From 1e1e9c4fdd595d52631fd7548e12fc30020d6509 Mon Sep 17 00:00:00 2001 From: Phantop Date: Sat, 29 May 2021 16:13:12 -0400 Subject: [PATCH] Rename to appdwarf and add main appdwarf script Also adds in support for converting AppImages --- README.md | 3 +- appdwarf | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++ mkgo | 1 + mkjava | 1 + wine/mkwine | 2 +- 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100755 appdwarf diff --git a/README.md b/README.md index a6783b2..0620eb0 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,14 @@ Wine builds packed into a portable executables These scripts automatically fetch the latest version of their respective program and compress them into a portable image using [dwarfs](https://github.com/mhx/dwarfs) in a similar format to an [AppImage.](https://appimage.org/) +The titular `appdwarf` utility supports both converting an AppDir or an existing AppImage file, either as a local file or from a URL. + ## Requirements In order to create the images, you will need: - [dwarfs](https://github.com/mhx/dwarfs), specifically the `dwarfs` and `mkdwarfs` utilities (`dwarfs2` works, but you must either edit the script or link `dwarfs` to it) -- My `appdwarf` script from [here](https://github.com/Phantop/dotfiles/blob/main/.local/bin/appdwarf) If you only wish to run an existing image, only `dwarfs` (or `dwarfs2`) is needed. diff --git a/appdwarf b/appdwarf new file mode 100755 index 0000000..8c822b8 --- /dev/null +++ b/appdwarf @@ -0,0 +1,80 @@ +#!/bin/sh +set -eo pipefail +IFS=$'\n\t' +version=1 + +usage(){ + echo "Usage: $0 [option] [FILE/FOLDER/URL]" + echo " Compress a given AppDir (default)" + echo " -a, --appimage Convert a given AppImage to appdwarf" + echo " -u, --url Fetch AppImage from URL and convert to appdwarf" +} + +dwarf() { + mkdwarfs -i "$1" -o "$(basename "$1").sh" --header <(cat << 'EOF' +#!/bin/sh +DIR=/tmp/.dwarf_$(basename "$0")$RANDOM +mkdir "$DIR" 2> /dev/null +dwarfs -o offset=auto "$0" "$DIR" 2> /dev/null +"$DIR/AppRun" $@ +fusermount -uz "$DIR" 2> /dev/null +rmdir "$DIR" 2> /dev/null +exit +EOF +) + +chmod +x "$(basename "$@").sh" +} + +appimage() { + if [[ -f "$1" ]] + then + chmod +x "$1" + ./"$1" --appimage-extract || exit 1 + dwarf squashfs-root + rm -rf squashfs-root + mv squashfs-root.sh $(basename "$1" .AppImage).sh + else + echo "$1" is not a valid file + exit 1 + fi +} + +rm -rf squashfs-root + +while true +do + case "$1" in + --help | -h) + usage + exit 0 + ;; + --version) + echo "$version" + exit 0 + ;; + --appimage | -a) + appimage "$2" + exit 0 + ;; + --url | -u) + file=$(basename "$2") + wget "$2" -O "$file" || exit 1 + appimage "$file" + rm "$file" + exit 0 + ;; + --) + shift; break;; + *) + break;; + esac +done + +if test $# -eq 0; then + usage + exit 0 +else + dwarf "$1" + exit 0 +fi diff --git a/mkgo b/mkgo index 3ace10b..9c98218 100755 --- a/mkgo +++ b/mkgo @@ -1,4 +1,5 @@ #!/bin/bash +PATH=$(dirname $(readlink -f "${0}")):$PATH DIR=/tmp/dwarf-portable-executable mkdir -p $DIR curl -L https://golang.org/$(curl -sL https://golang.org/dl | grep -wo dl/go.\*linux-amd64.tar.gz | head -n1) | tar xz -C$DIR diff --git a/mkjava b/mkjava index 752ead7..a78320e 100755 --- a/mkjava +++ b/mkjava @@ -1,4 +1,5 @@ #!/bin/bash +PATH=$(dirname $(readlink -f "${0}")):$PATH DIR=/tmp/dwarf-portable-executable/java mkdir -p $DIR curl -L https://api.adoptopenjdk.net/v3/binary/latest/11/ga/linux/x64/jre/openj9/normal/adoptopenjdk | tar xz -C$DIR diff --git a/wine/mkwine b/wine/mkwine index e5ea4ed..b71d12b 100755 --- a/wine/mkwine +++ b/wine/mkwine @@ -1,5 +1,5 @@ #!/usr/bin/env bash - +PATH=$(dirname $(readlink -f "${0}"))/../:$PATH start="$PWD" winedir=/tmp/dwarf-portable-executable/wine script_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"