anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / build-support / nuke-references / nuke-refs.sh
blob21eb855cbad9acb3865e9a00661cd3199bd50bdf
1 #! @shell@
3 fixupHooks=()
5 if [ -e @out@/nix-support/setup-hooks.sh ]; then
6 source @out@/nix-support/setup-hooks.sh
7 fi
9 excludes=""
10 while getopts e: o; do
11 case "$o" in
12 e) storeId=$(echo "$OPTARG" | @perl@/bin/perl -ne "print \"\$1\" if m|^\Q@storeDir@\E/([a-z0-9]{32})-.*|")
13 if [ -z "$storeId" ]; then
14 echo "-e argument must be a Nix store path"
15 exit 1
17 excludes="$excludes(?!$storeId)"
19 esac
20 done
21 shift $(($OPTIND-1))
23 for i in "$@"; do
24 if test ! -L "$i" -a -f "$i"; then
25 cat "$i" | @perl@/bin/perl -pe "s|\Q@storeDir@\E/$excludes[a-z0-9]{32}-|@storeDir@/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "$i.tmp"
26 if test -x "$i"; then chmod +x "$i.tmp"; fi
27 mv "$i.tmp" "$i"
29 for hook in "${fixupHooks[@]}"; do
30 eval "$hook" "$i"
31 done
33 done