mirror of https://github.com/Phantop/appdwarf.git
switch from buggy offset heuristic to storing offsets
This commit is contained in:
parent
7e0360e809
commit
02b1604efb
83
appdwarf
83
appdwarf
|
@ -8,10 +8,9 @@ apprun() {
|
||||||
exec "$APPDIR/$(basename "$ARGV0")" "$@"
|
exec "$APPDIR/$(basename "$ARGV0")" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
bundlehead() { #use script end and dwarfs header to find location of dwarfs binary
|
bundlehead() {
|
||||||
MOUNTBIN=$(mktemp); START=$(sed -n '/^exit \$? #ade$/{N;=}' "$0")
|
MOUNTBIN=$(mktemp) # use provided offsets to supply dwarfs binary
|
||||||
END=$(sed -n '0,/^DWARFS/=' "$0" | tail -n2 | head -n1)
|
tail -n+"$OFF" "$0" | head -n"$LEN" | head -c-1 | zstd -cqd > "$MOUNTBIN"
|
||||||
head -n"$END" "$0" | tail -n+"$START" | head -c-1 | zstd -cqd > "$MOUNTBIN"
|
|
||||||
dwarfs() { chmod +x "$MOUNTBIN"; "$MOUNTBIN" "$@"; rm "$MOUNTBIN"; }
|
dwarfs() { chmod +x "$MOUNTBIN"; "$MOUNTBIN" "$@"; rm "$MOUNTBIN"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,82 +20,88 @@ header() {
|
||||||
dwarfs -o offset=auto -o tidy_strategy=swap -o workers="$(nproc)" "$0" "$APPDIR"
|
dwarfs -o offset=auto -o tidy_strategy=swap -o workers="$(nproc)" "$0" "$APPDIR"
|
||||||
trap 'fusermount -quz $APPDIR; rmdir $APPDIR' 0 1 2 3 6 14 15 EXIT
|
trap 'fusermount -quz $APPDIR; rmdir $APPDIR' 0 1 2 3 6 14 15 EXIT
|
||||||
"$APPDIR/AppRun" "$@"
|
"$APPDIR/AppRun" "$@"
|
||||||
exit $? #ade
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
printfunc() {
|
outfunc() {
|
||||||
echo '#!/bin/sh'
|
echo '#!/bin/sh'
|
||||||
echo 'set -e'
|
echo 'set -e' # running outfunc with no input just prints these two lines
|
||||||
sed -n "/^$1() {$/,/^}$/s/^ *//p" "$0" | tail -n+2 | head -n-1
|
sed -n "/^$1() {$/,/^}$/s/^ *//p" "$0" | tail -n+2 | head -n-1
|
||||||
}
|
}
|
||||||
|
|
||||||
unappimage() {
|
unappimage() {
|
||||||
|
test "$(hexdump -n11 -e'"%x"' "$1")" = 464c457f1010224941 || return 1
|
||||||
|
echo "AppImage found. Extracting..." # appimage magic matched
|
||||||
o=$(($(readelf -h "$1" | sed -e 's/[^0-9]//g;13p;18,19p;d' | sed -e 1a+ -e 2a*)))
|
o=$(($(readelf -h "$1" | sed -e 's/[^0-9]//g;13p;18,19p;d' | sed -e 1a+ -e 2a*)))
|
||||||
unsquashfs -o "$o" "$@" # calculate offset via ELF header
|
unsquashfs -o "$o" "$@" # calculate offset via ELF header
|
||||||
}
|
}
|
||||||
|
|
||||||
zzexe() {
|
zzexe() {
|
||||||
[ "$1" = "-p" ] && p="$2" && shift # save prefix if present
|
[ "$1" = "-p" ] && p="$2" && shift # save prefix if present
|
||||||
shift; tmp=$(mktemp) # make tmp file to avoid io operations
|
shift; out=$(mktemp) # make tmp file to avoid io operations
|
||||||
printfunc zzexe_header | sed -e "2s/);$/${1##*[./]})/" -e "7s/^/$p /" > "$tmp"
|
{ outfunc
|
||||||
zstdmt -cq19 "$@" >> "$tmp"
|
echo "OFF=$(($( (outfunc; outfunc zzexe_header) | wc -l)+2))"
|
||||||
mv "$tmp" "$1"
|
outfunc zzexe_header | sed -e "3s/)$/${1##*[./]})/" -e "8s/^/$p /"
|
||||||
|
zstdmt -cq19 "$@"
|
||||||
|
} > "$out"
|
||||||
|
mv "$out" "$1"
|
||||||
chmod +x "$1"
|
chmod +x "$1"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
zzexe_header() {
|
zzexe_header() {
|
||||||
dir="$(dirname "$0")" out=$(mktemp -t .zzXXXX.)
|
dir="$(dirname "$0")" out=$(mktemp -t .zzXXXX.)
|
||||||
tail -n+"$(sed -n '/^exit \$? #zst$/{N;=}' "$0")" "$0" | zstd -cd > "$out"
|
tail -n+"$OFF" "$0" | zstd -cd > "$out"
|
||||||
chmod +x "$out"
|
chmod +x "$out"
|
||||||
[ ! -f "$dir/$(basename "$out")" ] && ln -s "$out" "$dir"
|
[ ! -f "$dir/$(basename "$out")" ] && ln -s "$out" "$dir"
|
||||||
trap 'rm "$out" "$dir/$(basename "$out")"' 0 1 2 3 6 14 15 EXIT
|
trap 'rm -f "$out" "$dir/$(basename "$out")"' 0 1 2 3 6 14 15 EXIT
|
||||||
"$dir/$(basename "$out")" "$@"
|
"$dir/$(basename "$out")" "$@"
|
||||||
exit $? #zst
|
exit $?
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-a )
|
-a )
|
||||||
printfunc apprun > "$2"
|
outfunc apprun > "$2"
|
||||||
chmod +x "$2"
|
chmod +x "$2"
|
||||||
exit ;;
|
exit ;;
|
||||||
-b )
|
-b )
|
||||||
printfunc apprun | sed '4s#/#/bin/#' > "$2"
|
outfunc apprun | sed '5s#/#/bin/#' > "$2"
|
||||||
chmod +x "$2"
|
chmod +x "$2"
|
||||||
exit ;;
|
exit ;;
|
||||||
--bundle )
|
--bundle ) # allow bundling dwarfs binary
|
||||||
BUNDLE=$(realpath "$2")
|
BUNDLE=$(realpath "$2")
|
||||||
shift 2;;
|
shift 2;;
|
||||||
-d )
|
-d | --decompress )
|
||||||
d=dwarfs-root # just to keep line shorter, extract if file is dwarfs
|
d=dwarfs-root # just to keep line shorter, extract if file is dwarfs
|
||||||
dwarfsck -d0 -i"$2" && mkdir $d && dwarfsextract -o $d -i "$2" && exit
|
dwarfsck -d0 -i"$2" && mkdir $d && dwarfsextract -o $d -i "$2" && exit
|
||||||
tmp=$(mktemp) # make tmp file to avoid io operations
|
tmp=$(mktemp) # make tmp file to avoid io operations
|
||||||
tail -n+"$(sed -n '/^exit \$? #zst$/{N;=}' "$2")" "$2" | zstd -cd > "$tmp"
|
unappimage "$2" && exit # also extract appimages cuz we can
|
||||||
|
tail -n+"$(sed -n '3s/^OFF=//p' "$2")" "$2" | zstd -cd > "$tmp"
|
||||||
mv "$tmp" "$2"
|
mv "$tmp" "$2"
|
||||||
chmod +x "$2"
|
chmod +x "$2"
|
||||||
exit ;;
|
exit ;;
|
||||||
--fetch )
|
--fetch )
|
||||||
FETCH=1
|
FETCH=1
|
||||||
shift ;;
|
shift ;;
|
||||||
-p | -z)
|
-p | -z | --prefix | --zzexe )
|
||||||
zzexe "$@" ;;
|
zzexe "$@" ;;
|
||||||
--version | -v )
|
--version | -v )
|
||||||
tput setaf 2; echo appdwarf 2023.02.04
|
tput setaf 2; echo appdwarf 2023.02.04
|
||||||
tput setaf 6; echo Built by July 🏳️🌈; exit ;;
|
tput setaf 6; echo Built by July 🏳️🌈; exit ;;
|
||||||
-* | '' )
|
-* | '' )
|
||||||
echo "Usage: appdwarf [option] [APP/FILE/FOLDER/URL] [compression options]"
|
echo "Usage: appdwarf [option] [APP/FILE/FOLDER/URL] [compression options]"
|
||||||
echo " -a [file] Write example AppRun to file and exit"
|
echo " -a [FILE] write example AppRun file"
|
||||||
echo " -b [file] Write example AppRun with bin subdir to file and exit"
|
echo " -b [FILE] write bin subdir AppRun file"
|
||||||
echo " -d [file] Decompress an appdwarf image or zzexe'd file"
|
echo " -d [--decompress] [FILE] decompress a compressed program"
|
||||||
echo
|
echo
|
||||||
echo " --bundle [file] Bundle a dwarfs executable with the appdwarf image"
|
echo " --bundle [FILE] bundle dwarfs with the appdwarf image"
|
||||||
echo " --fetch Exit after fetching a remote AppImage, if applicable"
|
echo " --fetch only fetch a remote AppImage"
|
||||||
echo
|
echo
|
||||||
echo " -p [prefix] zzexe a file with prefix"
|
echo " -p [--prefix] [PREFIX] zzexe a file with prefix"
|
||||||
echo " -z zzexe a file"
|
echo " -z [--zzexe] zzexe a file"
|
||||||
echo
|
echo
|
||||||
echo " -h, --help Print this help text"
|
echo " -h, --help Print this help text"
|
||||||
echo " -v, --version Print the appdwarf version"; exit ;;
|
echo " -v, --version Print the appdwarf version"; exit ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
||||||
|
@ -135,14 +140,12 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
||||||
# this is a file, but it might be an existing dwarfs image
|
# this is a file, but it might be an existing dwarfs image
|
||||||
if dwarfsck -d0 -i"$1"; then
|
if dwarfsck -d0 -i"$1"; then
|
||||||
set -- "$@" --recompress=none
|
set -- "$@" --recompress=none
|
||||||
elif test "$(hexdump -n11 -e'"%x"' "$1")" = 464c457f1010224941; then
|
elif unappimage "$1"; then
|
||||||
echo "AppImage found. Converting..." # appimage magic matched
|
|
||||||
app="$(basename "$1" .AppImage)"
|
app="$(basename "$1" .AppImage)"
|
||||||
unappimage "$1"
|
|
||||||
rm -rf "$1" "$app"
|
rm -rf "$1" "$app"
|
||||||
|
mv squashfs-root "$app"
|
||||||
shift
|
shift
|
||||||
set -- "$app" "$@"
|
set -- "$app" "$@"
|
||||||
mv squashfs-root "$1"
|
|
||||||
else
|
else
|
||||||
tput setaf 4; echo "$1 is not an AppImage, it will be zzexe'd"
|
tput setaf 4; echo "$1 is not an AppImage, it will be zzexe'd"
|
||||||
zzexe -z "$@"
|
zzexe -z "$@"
|
||||||
|
@ -150,9 +153,17 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
||||||
fi
|
fi
|
||||||
|
|
||||||
head="$(mktemp)"
|
head="$(mktemp)"
|
||||||
test "$BUNDLE" && printfunc bundlehead >> "$head"
|
if [ "$BUNDLE" ]; then { # behavior for bundling a dwarfs executable
|
||||||
printfunc header >> "$head"
|
ZDATA="$(mktemp)"
|
||||||
test "$BUNDLE" && zstd -cq "$BUNDLE" >> "$head"
|
zstd -cq "$BUNDLE" > "$ZDATA"
|
||||||
|
outfunc
|
||||||
|
echo "OFF=$(($( (outfunc; outfunc bundlehead; outfunc header) | wc -l)+3))"
|
||||||
|
echo "LEN=$(($(wc -l < "$ZDATA")+1))"
|
||||||
|
outfunc bundlehead
|
||||||
|
} > "$head"
|
||||||
|
fi
|
||||||
|
outfunc header >> "$head"
|
||||||
|
test "$BUNDLE" && cat "$ZDATA" >> "$head"
|
||||||
echo >> "$head"
|
echo >> "$head"
|
||||||
|
|
||||||
mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$head" -i "$@"
|
mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$head" -i "$@"
|
||||||
|
|
|
@ -6,5 +6,5 @@ eopkg fc -o "$DIR" "$@"
|
||||||
parallel "unzip -op {} install.tar.xz | tar xJf - -C$DIR" ::: "$DIR"/*.eopkg
|
parallel "unzip -op {} install.tar.xz | tar xJf - -C$DIR" ::: "$DIR"/*.eopkg
|
||||||
rm "$DIR"/*.eopkg
|
rm "$DIR"/*.eopkg
|
||||||
appb
|
appb
|
||||||
sed -i 2,4s#/bin#/usr/bin# "$DIR"/AppRun
|
sed -i 3,5s#/bin#/usr/bin# "$DIR"/AppRun
|
||||||
part9
|
part9
|
||||||
|
|
|
@ -4,5 +4,5 @@ part0
|
||||||
LINK=$(curl https://go.dev/dl/ | grep -m1 linux | cut -d\" -f4)
|
LINK=$(curl https://go.dev/dl/ | grep -m1 linux | cut -d\" -f4)
|
||||||
curl -L https://go.dev/"$LINK" | tar xz -C"$DIR"/..
|
curl -L https://go.dev/"$LINK" | tar xz -C"$DIR"/..
|
||||||
appb
|
appb
|
||||||
sed -i '4i export GOPROXY=direct' "$DIR"/AppRun
|
sed -i '5i export GOPROXY=direct' "$DIR"/AppRun
|
||||||
part9
|
part9
|
||||||
|
|
|
@ -6,5 +6,5 @@ aria2c "$LINK" -d "$DIR" -o mp3tag
|
||||||
7z x -y -o"$DIR" "$DIR"/mp3tag
|
7z x -y -o"$DIR" "$DIR"/mp3tag
|
||||||
mv "$DIR"/Mp3tag.exe "$DIR"/mp3tag
|
mv "$DIR"/Mp3tag.exe "$DIR"/mp3tag
|
||||||
appa
|
appa
|
||||||
sed -i '4s/ / wine /' "$DIR"/AppRun
|
sed -i '5s/ / wine /' "$DIR"/AppRun
|
||||||
part9
|
part9
|
||||||
|
|
|
@ -6,5 +6,5 @@ ungz
|
||||||
mv "$DIR"/x86_64-linux-musl-native/* "$DIR"
|
mv "$DIR"/x86_64-linux-musl-native/* "$DIR"
|
||||||
ln -s gcc "$DIR"/bin/cc
|
ln -s gcc "$DIR"/bin/cc
|
||||||
appa
|
appa
|
||||||
sed -i '4d;3a exec "$@"' "$DIR"/AppRun
|
sed -i '5d;4a exec "$@"' "$DIR"/AppRun
|
||||||
part9
|
part9
|
||||||
|
|
|
@ -41,5 +41,5 @@ EOF
|
||||||
rm -r "$DIR"/texmf-dist/scripts/tlcockpit
|
rm -r "$DIR"/texmf-dist/scripts/tlcockpit
|
||||||
"$DIR"/bin/x86_64-linux/tlmgr install bookhands markdown paralist titlesec titling xstring
|
"$DIR"/bin/x86_64-linux/tlmgr install bookhands markdown paralist titlesec titling xstring
|
||||||
appb
|
appb
|
||||||
sed -i 2,4s#/bin#/bin/x86_64-linux# "$DIR"/AppRun
|
sed -i 3,5s#/bin#/bin/x86_64-linux# "$DIR"/AppRun
|
||||||
part9
|
part9
|
||||||
|
|
Loading…
Reference in New Issue