From 6774a2d639570e50521bb691aac65c9d1e599371 Mon Sep 17 00:00:00 2001 From: Phantop Date: Mon, 20 Jun 2022 15:13:05 -0400 Subject: [PATCH] appdwarf 3.5: auto detect and handle files and urls --- appdwarf | 70 +++++++++++++++++++++++--------------------------- apps/README.md | 4 +-- apps/appimage | 15 ++++++++++- apps/github | 11 -------- apps/mkjava | 5 ++-- apps/mkmusl | 9 ++----- apps/mkvagrant | 9 ------- apps/ungoogled | 3 --- header | 4 +-- 9 files changed, 53 insertions(+), 77 deletions(-) delete mode 100755 apps/github delete mode 100755 apps/mkvagrant delete mode 100755 apps/ungoogled diff --git a/appdwarf b/appdwarf index 8b8c124..1896cb4 100755 --- a/appdwarf +++ b/appdwarf @@ -1,52 +1,46 @@ #!/bin/sh -if [ $# -eq 0 ] || [ "$1" = -h ] || [ "$1" = --help ]; then # print help text - tput setaf 6 - echo "Usage: $(basename "$0") [options] [FILE/FOLDER/URL] [dwarfs options]" - echo "Compress a given AppDir (default)" - tput setaf 7 - echo " -a, --appimage Convert a given AppImage to appdwarf" - echo " -u, --url Fetch and convert AppImage from URL" - echo; tput setaf 5 - echo " -h, --help Print this help text" - echo " -v, --version Print the appdwarf version" - exit -fi - set -e # exit on failure IFS=$(printf '\n\t') # smarter ifs HEAD="$(dirname "$(readlink -f "${0}")")/header" -while true; do # process args - case "$1" in - --appimage | -a) - app="$2" ;; - --url | -u) - app=$(basename "$2") - aria2c -x16 -s16 "$2" -o "$app" || wget "$2" -O "$app" ;; - --version | -v) - tput setaf 2; echo appdwarf v3.0 - tput setaf 4; echo Built by July 🏳️‍🌈 - exit ;; - --) - shift; break;; - *) - break;; - esac; shift 2 -done +case "$1" in + -h | --help | '') + tput setaf 6 + echo "Usage: $(basename "$0") [FILE/FOLDER/URL] [dwarfs options]" + tput setaf 3 + echo " -h, --help Print this help text" + echo " -v, --version Print the appdwarf version"; exit ;; + --version | -v) + tput setaf 2; echo appdwarf v3.5 + tput setaf 6; echo Built by July 🏳️‍🌈; exit ;; + -* ) + tput setaf 1; echo Invalid argument; exit 1 +esac -if [ -n "$app" ]; then # handle and extract appimage input, if present - [ ! -f "$app" ] && tput setaf 1 && echo "$app" is not a valid file >&2 && exit 1 - file -i "$app" | grep -qv x-executable && tput setaf 1 && - echo "$app" is not an AppImage >&2 && exit 1 +if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage + if [ ! -f "$1" ]; then # file doesn't exist, see if this is a url + app=$(basename "$1") + if aria2c -x16 -s16 "$1" -o "$app" || wget "$1" -O "$app"; then + shift + set -- "$app" "$@" + else + tput setaf 1; echo "$1" is not a valid file, folder, or url >&2 + rm "$app" 2> /dev/null; exit 1 + fi + fi - chmod +x "$app" + chmod +x "$1" rm -rf squashfs-root - "$(realpath "$app")" --appimage-extract - set -- "$(basename "$app" .AppImage)" "$@" + if ! "$(realpath "$1")" --appimage-extract 2> /dev/null; then + tput setaf 4; echo "$1 is not an AppImage, it will be zzexe'd" + exec "$(dirname "$(readlink -f "${0}")")/zzexe" "$@" + fi + + app="$(basename "$1" .AppImage)" shift + set -- "$app" "$@" mv squashfs-root "$1" fi -[ ! -d "$1" ] && tput setaf 1 && echo "$1" is not a valid folder >&2 && exit 1 mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$HEAD" -i "$@" chmod +x "$(realpath "$1").sh" diff --git a/apps/README.md b/apps/README.md index a75cd31..48e76f1 100644 --- a/apps/README.md +++ b/apps/README.md @@ -10,8 +10,7 @@ These scripts are all targeted for using on x86_64 Linux systems with GLIBC. Script | Function | Source --- | --- | --- -`appimage ` | Can fetch and convert AppImages by name from AppImageHub if the source repo is hosted on GitHub and linked to | -`github ` | Can be given a GitHub URL or repo in the form `user/repo` and will find and convert the latest AppImage release | +`appimage ` | Can fetch and convert AppImages by name from AppImageHub or from a given GitHub repo| `mkchrome ` | Latest official Chromium build | `mkgo ` | Latest official Go release | `mkjava ` | Accepts an argument for Java version and obtains that build from Adoptium | @@ -23,4 +22,3 @@ Script | Function | Source `mkwine ` | Latest `wine-staging-tkg` release | `mkwine proton` | GloriousEggroll Proton Builds | `rustsolus` | Latest Rust stable from the Solus repos (requires `eopkg` and may not work on other distros) | -`ungoogled` | Latest submitted `ungoogled-chromium` binary release | diff --git a/apps/appimage b/apps/appimage index 9755c04..e83bdb6 100755 --- a/apps/appimage +++ b/apps/appimage @@ -1,2 +1,15 @@ #!/bin/sh -./github https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/"$1".md +if ! echo "$1" | grep / ; then + "$0" https://raw.githubusercontent.com/AppImage/appimage.github.io/master/apps/"$1".md + exit $? +fi +if ! echo "$1" | grep https ; then + set -- "https://github.com/$1" +fi +LINK2="$(echo "$1"/releases | sed 's|github.com|api.github.com/repos|')" +if ! echo "$1" | grep github.com; then + LINK2="$(curl "$1" | grep -o https.\*releases | sed 's|github.com|api.github.com/repos|')" +fi +LINK3="$(curl "$LINK2" | grep -v arm64 | grep -v armh | grep -om1 https.\*AppImage)" +shift +appdwarf "$LINK3" "$@" diff --git a/apps/github b/apps/github deleted file mode 100755 index a3db5a4..0000000 --- a/apps/github +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -if ! echo "$1" | grep https ; then - set -- "https://github.com/$1" -fi -LINK2="$(echo "$1"/releases | sed 's|github.com|api.github.com/repos|')" -if ! echo "$1" | grep github.com; then - LINK2="$(curl "$1" | grep -o https.\*releases | sed 's|github.com|api.github.com/repos|')" -fi -LINK3="$(curl "$LINK2" | grep -v arm64 | grep -v armh | grep -om1 https.\*AppImage)" -shift -appdwarf "$@" -u "$LINK3" diff --git a/apps/mkjava b/apps/mkjava index 4a8aafa..c98c593 100755 --- a/apps/mkjava +++ b/apps/mkjava @@ -5,10 +5,9 @@ mkdir -p $DIR VER=$1 shift -LINK=https://api.adoptium.net/v3/binary/latest/$VER/ga/linux/x64/jdk/hotspot/normal/eclipse +LINK=https://api.adoptium.net/v3/binary/latest/$VER/ga/linux/x64/jre/hotspot/normal/eclipse curl -L "$LINK" | tar xz -C$DIR -mv $DIR/jdk* $DIR/jdk -$DIR/jdk/bin/jlink --add-modules ALL-MODULE-PATH --output $DIR/jre --strip-debug --no-man-pages --no-header-files --compress=0 +mv $DIR/jdk* $DIR/jre cp "$(dirname "$(readlink -f "${0}")")"/../AppRun $DIR/jre sed -i 4s#/#/bin/# $DIR/jre/AppRun diff --git a/apps/mkmusl b/apps/mkmusl index db90038..3cad15d 100755 --- a/apps/mkmusl +++ b/apps/mkmusl @@ -6,13 +6,8 @@ curl http://musl.cc/x86_64-linux-musl-native.tgz | tar xz -C$DIR mv $DIR/x86_64-linux-musl-native $DIR/musl ln -s gcc $DIR/musl/bin/cc -cat > $DIR/musl/AppRun << 'EOF' -#!/bin/sh -HERE=$(dirname $(readlink -f "${0}")) -export PATH="${HERE}/bin":$PATH -"$@" -EOF -chmod +x $DIR/musl/AppRun +cp "$(dirname "$(readlink -f "${0}")")"/../AppRun $DIR/musl +sed -i '4s#"$APPDIR/$ARGV0" ##' $DIR/musl/AppRun appdwarf $DIR/musl mv $DIR/musl.sh musl diff --git a/apps/mkvagrant b/apps/mkvagrant deleted file mode 100755 index 2d8c032..0000000 --- a/apps/mkvagrant +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -PATH=$(dirname "$(readlink -f "${0}")")/..:$PATH -DIR=/tmp/appdwarf -mkdir -p $DIR -LINK=https://releases.hashicorp.com/vagrant -VER=$(curl -L $LINK | grep -m1 'href.*[0-9]' | cut -d/ -f3) -LINK2=https://releases.hashicorp.com/vagrant/$VER/vagrant_"$VER"_linux_amd64.zip -curl "$LINK2" | bsdtar xf - -C$DIR -appdwarf -a $DIR/vagrant diff --git a/apps/ungoogled b/apps/ungoogled deleted file mode 100755 index 0aa5dac..0000000 --- a/apps/ungoogled +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -ID="$(curl -L https://ungoogled-software.github.io/ungoogled-chromium-binaries | grep -m7 href | tail -n 1 | awk -F'[<>]' '{print $5}')" -appdwarf -u "https://github.com/clickot/ungoogled-chromium-binaries/releases/download/$ID/ungoogled-chromium_$ID.AppImage" diff --git a/header b/header index 9fa2e7a..f2d291f 100755 --- a/header +++ b/header @@ -2,10 +2,10 @@ ARGV0="$(basename "$0")"; APPDIR="/tmp/dwarf_$ARGV0$(echo "$0"|md5sum|head -c5)" export APPIMAGE="$0" OWD="$PWD" ARGV0 APPDIR [ ! -d "$APPDIR" ] && mkdir "$APPDIR" && - dwarfs -o offset=auto -o tidy_strategy=swap -o workers=4 "$0" "$APPDIR" 2>&1|: +dwarfs -o offset=auto -o tidy_strategy=swap -o workers=4 "$0" "$APPDIR" 2>/dev/null "$APPDIR/AppRun" "$@" res=$? fusermount -quz "$APPDIR" -rmdir "$APPDIR" /dev/null +rmdir "$APPDIR" > /dev/null exit $res