zzexe: rewrite and use moreutils

This commit is contained in:
Phantop 2022-04-16 19:21:07 -04:00
parent 99d7dcf3aa
commit 1caa827c68
4 changed files with 10 additions and 32 deletions

2
AppRun
View File

@ -2,4 +2,4 @@
HERE=$(dirname "$(readlink -f "${0}")")
export PATH="${HERE}":"${HERE}"/bin:"$PATH"
export LD_LIBRARY_PATH="${HERE}"/lib64:"${HERE}"/lib:"$LD_LIBRARY_PATH"
"${HERE}"/"$APPDWARF_CMD" "$@"
exec "${HERE}"/"$APPDWARF_CMD" "$@"

View File

@ -42,6 +42,8 @@ It also automatically appends the extension of the source file to the temporary
created when ran since some programs care about that, such as an emulator only
running games of an expected file extension.
`zzexe` requires `zstd` for both creating and running files and `moreutils` for creating them.
## Known Issues
- Some images may not unmount properly under the default, combined mounting scheme due

View File

@ -6,7 +6,7 @@ LINK=$(curl -sL https://go.dev/dl | grep -om1 dl/go.\*linux-amd64.tar.gz)
curl -L https://go.dev/"$LINK" | tar xz -C$DIR
cp "$(dirname "$(readlink -f "${0}")")"/../AppRun $DIR/go
sed 5s#/#/bin/# $DIR/go/AppRun
sed -i 5s#/#/bin/# $DIR/go/AppRun
appdwarf $DIR/go
mv $DIR/go.sh go

36
zzexe
View File

@ -1,40 +1,16 @@
#!/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"
[ "$1" = "-d" ] && tail -n+10 "$2" | zstd -cd | ifne sponge "$2" && exit
[ "$1" = "-p" ] && p="$2" && shift 2 # save prefix if present
{ cat << 'EOF';zstdmt -c19 "$@";} |sed "2s/$/${1##*.})/;7s/^/$p /"| ifne sponge "$1"
#!/bin/sh
dir=$(dirname "$0") out=$(mktemp -t .zzXXXX.
tail -n+10 "$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"