2 local FILE_TO_PATCH
="$1"
3 local SOURCETIME_PATH
="$2"
4 local FILE_TO_WORK_ON
="$(mktemp "$
(basename "$FILE_TO_PATCH").XXXXXX.tmp
")"
5 cat <<EOF >> "$FILE_TO_WORK_ON"
6 # Lines to add to PATH the source-time utilities for Nixpkgs packaging
7 if [[ -n "\${NIXPKGS_SOURCETIME_PATH-}" ]]; then
8 NIXPKGS_SOURCETIME_PATH_OLD="\$NIXPKGS_SOURCETIME_PATH;\${NIXPKGS_SOURCETIME_PATH_OLD-}"
10 NIXPKGS_SOURCETIME_PATH="$SOURCETIME_PATH"
11 if [[ -n "\$PATH" ]]; then
12 PATH="\$NIXPKGS_SOURCETIME_PATH:\$PATH"
14 PATH="\$NIXPKGS_SOURCETIME_PATH"
17 # End of lines to add to PATH source-time utilities for Nixpkgs packaging
19 cat "$FILE_TO_PATCH" >> "$FILE_TO_WORK_ON"
20 cat <<EOF >> "$FILE_TO_WORK_ON"
21 # Lines to clean up inside PATH the source-time utilities for Nixpkgs packaging
22 if [[ -n "\${PATH-}" ]]; then
23 # Remove the inserted section
24 PATH="\${PATH/\$NIXPKGS_SOURCETIME_PATH}"
25 # Remove the duplicated colons
27 # Remove the prefixing colon
28 if [[ -n "\$PATH" && "\${PATH:0:1}" == ":" ]]; then
31 # Remove the trailing colon
32 if [[ -n "\$PATH" && "\${PATH:\${#PATH}-1}" == ":" ]]; then
37 if [[ -n "\${NIXPKGS_SOURCETIME_PATH_OLD-}" ]]; then
38 IFS="" read -r -d ";" NIXPKGS_SOURCETIME_PATH <<< "\$NIXPKGS_SOURCETIME_PATH_OLD"
39 NIXPKGS_SOURCETIME_PATH_OLD="\${NIXPKGS_SOURCETIME_PATH_OLD:\${#NIXPKGS_SOURCETIME_PATH}+1}"
41 unset NIXPKGS_SOURCETIME_PATH
43 if [[ -z "\${NIXPKGS_SOURCETIME_PATH_OLD-}" ]]; then
44 unset NIXPKGS_SOURCETIME_PATH_OLD
46 # End of lines to clean up inside PATH the source-time utilities for Nixpkgs packaging
48 cat "$FILE_TO_WORK_ON" > "$FILE_TO_PATCH"