From 582fff004782c24abfe39d0b300f94d31233466d Mon Sep 17 00:00:00 2001 From: Phantop Date: Fri, 25 Mar 2022 18:52:40 -0400 Subject: [PATCH] zzexe: moved here from my dotfiles --- README.md | 19 ++++++++++++++++++- zzexe | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 zzexe diff --git a/README.md b/README.md index 2ea0454..f1dd360 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,24 @@ For your own programs, simply create an AppImage-style AppDir and run `appdwarf You can also invoke `appdwarf -a {appimage}` to convert an apimage. I suggest checking the help (listed via `appdwarf --help`) for other options. -The apps folder contains other scripts for specific programs that will download all necessary files and create a resulting appdwarf in the same folder. +The apps folder contains other scripts for specific programs that will download all +necessary files and create a resulting appdwarf in the same folder. + +## `zzexe` + +`zzexe` is a small tool similar to `gzexe` that instead uses zstd to compress single applications. +I've included it because it has a similar goal to `appdwarf` on the whole, just on a smaller scale. + +I wrote it in part because I felt that `gzexe` was overly complicated, as I used to +just use a lightly modified version of it that replaces `gzip` with `zstd`, +and to add a couple additional features. + +It supports adding in a prefix command to the file using the `-p` options e.g. +`zzexe -p wine some.exe` will generate a compressed file that will then run the exe. + +It also automatically appends the extension of the source file to the temporary file +created when ran since some programs care about that, such as an emulator only +running games of an expected file extension. ## Known Issues diff --git a/zzexe b/zzexe new file mode 100755 index 0000000..45eb559 --- /dev/null +++ b/zzexe @@ -0,0 +1,34 @@ +#!/bin/sh +tmp=$(mktemp -u) +if [ "$1" = "-d" ]; then + shift + tail -n +11 "$1" | zstd -do "$tmp" && + mv "$tmp" "$1" + chmod +x "$1" + exit +fi + +if [ "$1" = "-p" ]; then + shift + prefix="$1 " + shift +fi + +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 + +zstdmt --ultra -c22 --long "$1" >> "$tmp" || exit 1 +mv "$tmp" "$1" +chmod +x "$1"