···1112# Run patch shebangs on a directory or file.
13# Can take multiple paths as arguments.
14-# patchShebangs [--build | --host] PATH...
1516# Flags:
17# --build : Lookup commands available at build-time
18# --host : Lookup commands available at runtime
01920# Example use cases,
21# $ patchShebangs --host /nix/store/...-hello-1.0/bin
···2324patchShebangs() {
25 local pathName
02627- if [[ "$1" == "--host" ]]; then
28- pathName=HOST_PATH
29- shift
30- elif [[ "$1" == "--build" ]]; then
31- pathName=PATH
32- shift
33- fi
000000000000000000003435 echo "patching script interpreter paths in $@"
36 local f
···93 newInterpreterLine="$newPath $args"
94 newInterpreterLine=${newInterpreterLine%${newInterpreterLine##*[![:space:]]}}
9596- if [[ -n "$oldPath" && "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]]; then
97 if [[ -n "$newPath" && "$newPath" != "$oldPath" ]]; then
98 echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
99 # escape the escape chars so that sed doesn't interpret them
···1112# Run patch shebangs on a directory or file.
13# Can take multiple paths as arguments.
14+# patchShebangs [--build | --host | --update] [--] PATH...
1516# Flags:
17# --build : Lookup commands available at build-time
18# --host : Lookup commands available at runtime
19+# --update : Update shebang paths that are in Nix store
2021# Example use cases,
22# $ patchShebangs --host /nix/store/...-hello-1.0/bin
···2425patchShebangs() {
26 local pathName
27+ local update
2829+ while [[ $# -gt 0 ]]; do
30+ case "$1" in
31+ --host)
32+ pathName=HOST_PATH
33+ shift
34+ ;;
35+ --build)
36+ pathName=PATH
37+ shift
38+ ;;
39+ --update)
40+ update=true
41+ shift
42+ ;;
43+ --)
44+ shift
45+ break
46+ ;;
47+ -*|--*)
48+ echo "Unknown option $1 supplied to patchShebangs" >&2
49+ return 1
50+ ;;
51+ *)
52+ break
53+ ;;
54+ esac
55+ done
5657 echo "patching script interpreter paths in $@"
58 local f
···115 newInterpreterLine="$newPath $args"
116 newInterpreterLine=${newInterpreterLine%${newInterpreterLine##*[![:space:]]}}
117118+ if [[ -n "$oldPath" && ( "$update" == true || "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ) ]]; then
119 if [[ -n "$newPath" && "$newPath" != "$oldPath" ]]; then
120 echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
121 # escape the escape chars so that sed doesn't interpret them