at master 50 lines 1.8 kB view raw
1patchRcPathBash(){ 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 7if [[ -n "\${NIXPKGS_SOURCETIME_PATH-}" ]]; then 8 NIXPKGS_SOURCETIME_PATH_OLD="\$NIXPKGS_SOURCETIME_PATH;\${NIXPKGS_SOURCETIME_PATH_OLD-}" 9fi 10NIXPKGS_SOURCETIME_PATH="$SOURCETIME_PATH" 11if [[ -n "\$PATH" ]]; then 12 PATH="\$NIXPKGS_SOURCETIME_PATH:\$PATH" 13else 14 PATH="\$NIXPKGS_SOURCETIME_PATH" 15fi 16export PATH 17# End of lines to add to PATH source-time utilities for Nixpkgs packaging 18EOF 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 22if [[ -n "\${PATH-}" ]]; then 23 # Remove the inserted section 24 PATH="\${PATH/\$NIXPKGS_SOURCETIME_PATH}" 25 # Remove the duplicated colons 26 PATH="\${PATH//::/:}" 27 # Remove the prefixing colon 28 if [[ -n "\$PATH" && "\${PATH:0:1}" == ":" ]]; then 29 PATH="\${PATH:1}" 30 fi 31 # Remove the trailing colon 32 if [[ -n "\$PATH" && "\${PATH:\${#PATH}-1}" == ":" ]]; then 33 PATH="\${PATH::}" 34 fi 35 export PATH 36fi 37if [[ -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}" 40else 41 unset NIXPKGS_SOURCETIME_PATH 42fi 43if [[ -z "\${NIXPKGS_SOURCETIME_PATH_OLD-}" ]]; then 44 unset NIXPKGS_SOURCETIME_PATH_OLD 45fi 46# End of lines to clean up inside PATH the source-time utilities for Nixpkgs packaging 47EOF 48 cat "$FILE_TO_WORK_ON" > "$FILE_TO_PATCH" 49 rm "$FILE_TO_WORK_ON" 50}