Skip to content

Commit

Permalink
apps: refactor appmk infrastructure into sourcing appdwarf
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantop committed Jul 5, 2024
1 parent 2addf37 commit 0e79f9b
Show file tree
Hide file tree
Showing 22 changed files with 160 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
matrix:
app:
- { name: wine, pkgs: dxvk-async-git mono vkd3d-proton-mingw-git wine-gecko wine-mono wine-staging-wow64 winetricks }
- { name: emus, pkgs: ares-emu-avx-git cemu citra-canary-git ryujinx yuzu-early-access }
- { name: emus, pkgs: ares-emu-avx-git cemu citra-canary-git ryujinx suyu-dev-qt6-git }
runs-on: ubuntu-latest
container: archlinux:latest
steps:
Expand Down
108 changes: 75 additions & 33 deletions appdwarf
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,46 @@
set -e # exit on failure
IFS=$(printf '\n\t') # smarter ifs

appmk() {
appdwarf "$DIR"
mv "$DIR".sh bin/"$APP"
rm -rf "$DIR"
}

apprun() {
export PATH="$APPDIR"/bin:"$PATH"
export LD_LIBRARY_PATH="$APPDIR"/lib64:"$APPDIR"/lib:"$LD_LIBRARY_PATH"
exec "$APPDIR/$(basename "$ARGV0")" "$@"
}

arun() {
outfunc apprun > "$1"
chmod +x "$1"
}

brun() {
outfunc apprun | sed '5s#/#/bin/#' > "$1"
chmod +x "$1"
}

appa() { arun "$DIR"/AppRun; }
appb() { brun "$DIR"/AppRun; }

unarc() { curl -L "$LINK" | bsdtar xf - -C"$DIR"; }
unbz() { curl -L "$LINK" | tar xj -C"$DIR"; }
ungz() { curl -L "$LINK" | tar xz -C"$DIR"; }
unxz() { curl -L "$LINK" | tar xJ -C"$DIR"; }
un7z() {
aria2c "$LINK" -d "$DIR" -o "$1"
7z x -y -o"$DIR" "$DIR"/"$1"
}

bundlehead() {
MOUNTBIN=$(mktemp) # use provided offsets to supply dwarfs binary
tail -n+"$OFF" "$0" | head -n"$LEN" | head -c-1 | zstd -cqd > "$MOUNTBIN"
mountbin=$(mktemp) # use provided offsets to supply dwarfs binary
#shellcheck disable=SC2154
tail -n+"$off" "$0" | head -n"$len" | head -c-1 | zstd -cqd > "$mountbin"
#shellcheck disable=SC2317
dwarfs() { chmod +x "$MOUNTBIN"; "$MOUNTBIN" "$@"; rm "$MOUNTBIN"; }
dwarfs() { chmod +x "$mountbin"; "$mountbin" "$@"; rm "$mountbin"; }
}

header() {
Expand Down Expand Up @@ -42,7 +71,7 @@ zzexe() {
[ "$1" = "-p" ] && p="$2" && shift # save prefix if present
shift; out=$(mktemp) # make tmp file to avoid io operations
{ outfunc
echo "OFF=$(($( (outfunc; outfunc zzexe_header) | wc -l)+2))"
echo "off=$(($( (outfunc; outfunc zzexe_header) | wc -l)+2))"
outfunc zzexe_header | sed -e "3s/)$/${1##*[./]})/" -e "8s/^/$p /"
zstdmt -cq19 "$@"
} > "$out"
Expand All @@ -53,43 +82,55 @@ zzexe() {

zzexe_header() {
dir="$(dirname "$0")" out=$(mktemp -t .zzXXXX.)
tail -n+"$OFF" "$0" | zstd -cd > "$out"
tail -n+"$off" "$0" | zstd -cd > "$out"
chmod +x "$out"
[ ! -f "$dir/$(basename "$out")" ] && ln -s "$out" "$dir"
trap 'rm -f "$out" "$dir/$(basename "$out")"' 0 1 2 3 6 14 15 EXIT
"$dir/$(basename "$out")" "$@"
exit $?
}

if [ "$SOURCE" ]; then
unset SOURCE
trap 'rm -rf "$DIR"' 0 1 2 3 6 14 15 EXIT
APP=$(basename "$0" | sed 's/^mk//')
DIR=/tmp/appdwarf/$APP
mkdir -p "$DIR"
return
fi

case "$1" in
-a )
outfunc apprun > "$2"
chmod +x "$2"
arun "$2"
exit ;;
-b )
outfunc apprun | sed '5s#/#/bin/#' > "$2"
chmod +x "$2"
brun "$2"
exit ;;
--bundle ) # allow bundling dwarfs binary
BUNDLE=$(realpath "$2")
bundle=$(realpath "$2")
shift 2;;
-d | --decompress )
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
tmp=$(mktemp) # make tmp file to avoid io operations
unappimage "$2" && exit # also extract appimages cuz we can
tail -n+"$(sed -n '3s/^OFF=//p' "$2")" "$2" | zstd -cd > "$tmp"
tail -n+"$(sed -n '3s/^off=//p' "$2")" "$2" | zstd -cd > "$tmp"
mv "$tmp" "$2"
chmod +x "$2"
exit ;;
-f | --fetch )
FETCH=1
fetch=1
shift ;;
-g | --get )
gh run -R phantop/appdwarf download -n "$2"
file="$(echo "$2" | sed 's/^arch-//')"
chmod +x "$file"
exit ;;
-p | -z | --prefix | --zzexe )
zzexe "$@" ;;
--version | -v )
printf '\e[32m'
echo 'appdwarf 2023.11.16'
echo 'appdwarf 2024.07.04'
printf '\e[36m'
echo Built by July 🏳️‍🌈
printf '\e[0m'
Expand All @@ -102,6 +143,7 @@ case "$1" in
echo
echo " --bundle [path/to/dwarfs] bundle dwarfs with the appdwarf image"
echo " -f, --fetch only fetch a remote AppImage"
echo " -g, --get download a prebuild appdwarf from actions"
echo
echo " -p, --prefix [PREFIX] zzexe a file with prefix"
echo " -z, --zzexe zzexe a file"
Expand All @@ -127,16 +169,16 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
echo "Assuming this is a GitHub repo..."
app="$(echo "${1%/}"/releases | sed 's|github.com|api.github.com/repos|')"
api="$(curl "$app" | jq -r .[].assets[].browser_download_url | grep 'AppImage$')"
link="$(echo "$api" | grep "$(uname -m)" || echo "$api" | grep -vEe '-(aarch|arm)(64|hf)\.AppImage')"
url="$(echo "$api" | grep "$(uname -m)" || echo "$api" | grep -vEe '-(aarch|arm)(64|hf)\.AppImage')"
shift
set -- "$(echo "$link" | head -n1)" "$@"
set -- "$(echo "$url" | head -n1)" "$@"
fi

app=$(basename "$1") # actually try to get the appimage
if aria2c -x16 -s16 "$1" -o "$app" || wget "$1" -O "$app"; then
shift
set -- "$app" "$@"
test "$FETCH" && chmod +x "$1" && exit
test "$fetch" && chmod +x "$1" && exit
else
printf '\e[31m' >&2
echo "No valid remote or local input found. Exiting..." >&2
Expand All @@ -160,22 +202,22 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
printf '\e[0m'
zzexe -z "$@"
fi
fi
fi

head="$(mktemp)"
if [ "$BUNDLE" ]; then { # behavior for bundling a dwarfs executable
ZDATA="$(mktemp)"
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"
head="$(mktemp)"
if [ "$bundle" ]; then { # behavior for bundling a dwarfs executable
zdata="$(mktemp)"
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"

mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$head" -i "$@" --categorize=pcmaudio -C pcmaudio/waveform::flac:level=8
rm -rf "$head" "$1"
chmod +x "$(realpath "$1").sh"
mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$head" -i "$@" --categorize=pcmaudio -C pcmaudio/waveform::flac:level=8
rm -rf "$head" "$1"
chmod +x "$(realpath "$1").sh"
4 changes: 1 addition & 3 deletions apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ These scripts are all targeted for use on x86_64 Linux systems with GLIBC.
Script | Function | Source
--- | --- | ---
`mkdotnet` | Latest LTS .NET runtime <https://dotnet.microsoft.com>
`mkeopkg` | Converts the given Solus package(s) to an appdwarf | <https://getsol.us>
`mkgo` | Latest official Go release | <https://go.dev>
`mkjava` | Accepts an argument for Java version and obtains that build from Adoptium | <https://adoptium.net>
`mkmp3tag` | Latest 64-bit Mp3tag release | <https://mp3tag.de/en>
`mkmusikcube` | Latest musikcube release | <https://musikcube.com/>
`mkmusl` | Latest musl.cc toolchain | <https://musl.cc>
`mknode` | Latest official NodeJS release | <https://nodejs.org>
`mkpacman` | Converts the given Arch package(s) to an appdwarf | <https://archlinux.org>
`mkpypy` | Latest PyPy3 release | <https://www.pypy.org>
`mkrenpy` | Latest Ren'Py release | <https://www.renpy.org>
`mkrust` | Latest Rust nightly | <https://rust-lang.org>
`mksignal` | Latest Signal stable from the Solus repos (requires `eopkg` and may not work on other distros) | <https://signal.org>
`mktex` | Minimal/custom TeX Live image | <https://ctan.org>
`mkwine` | Latest `wine-staging-tkg` release | <https://github.com/Kron4ek/Wine-Builds>
`mkwine proton` | GloriousEggroll Proton Builds | <https://github.com/GloriousEggroll/proton-ge-custom>
`rustsolus` | Latest Rust stable from the Solus repos (requires `eopkg` and may not work on other distros) | <https://getsol.us>
42 changes: 0 additions & 42 deletions apps/appmk

This file was deleted.

6 changes: 3 additions & 3 deletions apps/mkcalibre
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"
base=https://download.calibre-ebook.com
LINK="$(curl "$base" | tail -n 1 | cut -d\" -f2)"
LINK="$(curl "$base/$LINK" | tail -n 1 | cut -d\" -f4 | tr -d /)"
LINK="$base/$LINK/calibre-$LINK-$(uname -m).txz"
unxz
appa
part9
appmk
21 changes: 16 additions & 5 deletions apps/mkdotnet
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"

TYPE=Runtime
VER=LTS
Expand All @@ -16,9 +16,20 @@ done


LINK=https://dotnetcli.azureedge.net/dotnet/$TYPE
VER=$(curl $LINK/"$VER"/latest.version)
TYPE=$(echo "$TYPE" | tr "[:upper:]" "[:lower:]")
VER=$(curl $LINK/"$VER"/latest.version)
LINK="$LINK/$VER/dotnet-$TYPE-$VER-linux-x64.tar.gz"
ungz
ln -s dotnet "$DIR"/AppRun
part9

apprun() {
export DOTNET_ROOT="$APPDIR"
case "$(basename "$ARGV0")" in
dotnetenv )
exec "$@" ;;
* )
exec "$APPDIR/$(basename "$ARGV0")" "$@" ;;
esac
}

appa
appmk
10 changes: 0 additions & 10 deletions apps/mkeopkg

This file was deleted.

6 changes: 3 additions & 3 deletions apps/mkgo
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"
LINK=$(curl https://go.dev/dl/ | grep -m1 linux | cut -d\" -f4)
curl -L https://go.dev/"$LINK" | tar xz -C"$DIR"/..
appb
sed -i '5i export GOPROXY=direct' "$DIR"/AppRun
part9
appmk
7 changes: 3 additions & 4 deletions apps/mkjava
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"

TYPE=jre
VER=21
Expand All @@ -15,8 +15,7 @@ while [ $# -gt 0 ]; do
done

LINK=https://api.adoptium.net/v3/binary/latest/$VER/ga/linux/x64/"$TYPE"/hotspot/normal/eclipse
echo $LINK
ungz
mv "$DIR"/jdk*/* "$DIR"
appb
part9
appmk
9 changes: 4 additions & 5 deletions apps/mkmp3tag
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"
LINK=$(curl -L mp3tag.de/dodownload64.html | awk -F'[="]' /URL/'{print $7}')
aria2c "$LINK" -d "$DIR" -o mp3tag
7z x -y -o"$DIR" "$DIR"/mp3tag
un7z mp3tag
mv "$DIR"/Mp3tag.exe "$DIR"/mp3tag
appa
sed -i '5s/ / wine /' "$DIR"/AppRun
part9
appmk
6 changes: 3 additions & 3 deletions apps/mkmusikcube
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"
LINK=$(curl https://api.github.com/repos/clangen/musikcube/releases | grep -om1 'http.*_64.*bz2')
unbz
mv "$DIR"/musikcube*/* "$DIR"
appa
part9
appmk
6 changes: 3 additions & 3 deletions apps/mkmusl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
. "$(dirname "$0")"/appmk
part0
# shellcheck source=../appdwarf
SOURCE=1 . "$(which appdwarf)"
LINK=http://musl.cc/x86_64-linux-musl-native.tgz
ungz
mv "$DIR"/x86_64-linux-musl-native/* "$DIR"
ln -s gcc "$DIR"/bin/cc
appa
sed -i '5d;4a exec "$@"' "$DIR"/AppRun
part9
appmk
Loading

0 comments on commit 0e79f9b

Please sign in to comment.