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}")") HERE=$(dirname "$(readlink -f "${0}")")
export PATH="${HERE}":"${HERE}"/bin:"$PATH" export PATH="${HERE}":"${HERE}"/bin:"$PATH"
export LD_LIBRARY_PATH="${HERE}"/lib64:"${HERE}"/lib:"$LD_LIBRARY_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 created when ran since some programs care about that, such as an emulator only
running games of an expected file extension. running games of an expected file extension.
`zzexe` requires `zstd` for both creating and running files and `moreutils` for creating them.
## Known Issues ## Known Issues
- Some images may not unmount properly under the default, combined mounting scheme due - 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 curl -L https://go.dev/"$LINK" | tar xz -C$DIR
cp "$(dirname "$(readlink -f "${0}")")"/../AppRun $DIR/go cp "$(dirname "$(readlink -f "${0}")")"/../AppRun $DIR/go
sed 5s#/#/bin/# $DIR/go/AppRun sed -i 5s#/#/bin/# $DIR/go/AppRun
appdwarf $DIR/go appdwarf $DIR/go
mv $DIR/go.sh go mv $DIR/go.sh go

36
zzexe
View file

@ -1,40 +1,16 @@
#!/bin/sh #!/bin/sh
# shellcheck disable=SC2016,SC2129
set -e # exit on failure set -e # exit on failure
IFS=$(printf '\n\t') # smarter ifs IFS=$(printf '\n\t') # smarter ifs
tmp=$(mktemp) [ "$1" = "-d" ] && tail -n+10 "$2" | zstd -cd | ifne sponge "$2" && exit
[ "$1" = "-p" ] && p="$2" && shift 2 # save prefix if present
if [ "$1" = "-d" ]; then # decompress { cat << 'EOF';zstdmt -c19 "$@";} |sed "2s/$/${1##*.})/;7s/^/$p /"| ifne sponge "$1"
tail -n+11 "$2" | zstd -dof "$tmp" && #!/bin/sh
mv "$tmp" "$2" dir=$(dirname "$0") out=$(mktemp -t .zzXXXX.
chmod +x "$2" tail -n+10 "$0" | zstd -cd > "$out"
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" chmod +x "$out"
ln -s "$out" "$dir" ln -s "$out" "$dir"
trap "res=$?" 0 1 2 3 5 10 13 15 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")" "$@" "$dir/$(basename "$out")" "$@"
rm "$out" "$dir/$(basename "$out")" rm "$out" "$dir/$(basename "$out")"
exit $res exit $res
EOF EOF
# compress
zstdmt --ultra -c22 --long "$@" >> "$tmp"
mv "$tmp" "$1"
chmod +x "$1"