#!/bin/sh # shellcheck disable=SC2016,SC2129 set -e # exit on failure IFS=$(printf '\n\t') # smarter ifs tmp=$(mktemp) if [ "$1" = "-d" ]; then # decompress tail -n+11 "$2" | zstd -dof "$tmp" && mv "$tmp" "$2" chmod +x "$2" exit fi # file header echo '#!/bin/sh' > "$tmp" # save extension for extracted tmp file 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 # apply prefix if applicable [ "$1" = "-p" ] && printf %s "$2 " >> "$tmp" && shift 2 cat >> "$tmp" << 'EOF' "$dir/$(basename "$out")" "$@" rm "$out" "$dir/$(basename "$out")" exit $res EOF # compress zstdmt --ultra -c22 --long "$@" >> "$tmp" mv "$tmp" "$1" chmod +x "$1"