From 1caa827c682345c42ebe271d9328dadf33d5ec04 Mon Sep 17 00:00:00 2001 From: Phantop Date: Sat, 16 Apr 2022 19:21:07 -0400 Subject: [PATCH] zzexe: rewrite and use moreutils --- AppRun | 2 +- README.md | 2 ++ apps/mkgo | 2 +- zzexe | 36 ++++++------------------------------ 4 files changed, 10 insertions(+), 32 deletions(-) diff --git a/AppRun b/AppRun index dcbb912..dcc75c9 100755 --- a/AppRun +++ b/AppRun @@ -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" "$@" diff --git a/README.md b/README.md index 25823aa..deb7cf6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/apps/mkgo b/apps/mkgo index 61d9b43..8f52898 100755 --- a/apps/mkgo +++ b/apps/mkgo @@ -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 diff --git a/zzexe b/zzexe index 26b23b0..fe12cce 100755 --- a/zzexe +++ b/zzexe @@ -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"