about summary refs log tree commit diff
path: root/pkgs/build-support/nuke-references/builder.sh
blob: 02eac664d43714ef7041a6165433395cbe79236d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
source $stdenv/setup

mkdir -p $out/bin
cat > $out/bin/nuke-refs <<EOF
#! $SHELL -e

excludes=""
while getopts e: o; do
    case "\$o" in
        e) storeId=\$(echo "\$OPTARG" | sed -n "s|^$NIX_STORE/\\([a-z0-9]\{32\}\\)-.*|\1|p")
           if [ -z "\$storeId" ]; then
               echo "-e argument must be a Nix store path"
               exit 1
           fi
           excludes="\$excludes(?!\$storeId)"
        ;;
    esac
done
shift \$((\$OPTIND-1))

for i in "\$@"; do
    if test ! -L "\$i" -a -f "\$i"; then
        cat "\$i" | $perl/bin/perl -pe "s|$NIX_STORE/\$excludes[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" > "\$i.tmp"
        if test -x "\$i"; then chmod +x "\$i.tmp"; fi
        mv "\$i.tmp" "\$i"
    fi
done
EOF
chmod +x $out/bin/nuke-refs