2022-03-25 22:52:40 +00:00
|
|
|
#!/bin/sh
|
2022-04-13 21:10:51 +00:00
|
|
|
# shellcheck disable=SC2016,SC2129
|
|
|
|
|
2022-03-25 22:52:40 +00:00
|
|
|
tmp=$(mktemp -u)
|
|
|
|
if [ "$1" = "-d" ]; then
|
2022-04-13 21:10:51 +00:00
|
|
|
shift #decompress
|
2022-03-25 22:52:40 +00:00
|
|
|
tail -n +11 "$1" | zstd -do "$tmp" &&
|
|
|
|
mv "$tmp" "$1"
|
|
|
|
chmod +x "$1"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "-p" ]; then
|
|
|
|
shift
|
|
|
|
prefix="$1 "
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2022-04-13 21:10:51 +00:00
|
|
|
#file header
|
2022-03-25 22:52:40 +00:00
|
|
|
echo '#!/bin/sh' >> "$tmp"
|
|
|
|
echo 'out=$(mktemp -t .zzXXXX.'"${1##*.}"\) >> "$tmp"
|
|
|
|
cat >> "$tmp" << 'EOF'
|
|
|
|
dir=$(dirname "$0")
|
|
|
|
tail -n +11 "$0" | zstd -cd > "$out"
|
|
|
|
chmod +x "$out"
|
|
|
|
ln -s "$out" "$dir"
|
|
|
|
trap "res=$?" 0 1 2 3 5 10 13 15
|
|
|
|
EOF
|
|
|
|
echo "$prefix"'$dir/$(basename $out) "$@"' >> "$tmp"
|
|
|
|
cat >> "$tmp" << 'EOF'
|
|
|
|
rm "$out" "$dir"/$(basename $out)
|
|
|
|
exit $res
|
|
|
|
EOF
|
|
|
|
|
2022-04-13 21:10:51 +00:00
|
|
|
#compress
|
2022-03-25 22:52:40 +00:00
|
|
|
zstdmt --ultra -c22 --long "$1" >> "$tmp" || exit 1
|
|
|
|
mv "$tmp" "$1"
|
|
|
|
chmod +x "$1"
|