biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / build-support / setup-hooks / patch-rc-path-hooks / patch-rc-path-bash.sh
blobb98b983861b02b12c047dcf287df0603c5300c74
1 patchRcPathBash(){
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-}"
9 fi
10 NIXPKGS_SOURCETIME_PATH="$SOURCETIME_PATH"
11 if [[ -n "\$PATH" ]]; then
12 PATH="\$NIXPKGS_SOURCETIME_PATH:\$PATH"
13 else
14 PATH="\$NIXPKGS_SOURCETIME_PATH"
16 export PATH
17 # End of lines to add to PATH source-time utilities for Nixpkgs packaging
18 EOF
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
26 PATH="\${PATH//::/:}"
27 # Remove the prefixing colon
28 if [[ -n "\$PATH" && "\${PATH:0:1}" == ":" ]]; then
29 PATH="\${PATH:1}"
31 # Remove the trailing colon
32 if [[ -n "\$PATH" && "\${PATH:\${#PATH}-1}" == ":" ]]; then
33 PATH="\${PATH::}"
35 export PATH
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}"
40 else
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
47 EOF
48 cat "$FILE_TO_WORK_ON" > "$FILE_TO_PATCH"
49 rm "$FILE_TO_WORK_ON"