appdwarf/appdwarf

47 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
set -e # exit on failure
IFS=$(printf '\n\t') # smarter ifs
HEAD="$(dirname "$(readlink -f "${0}")")/header"
2021-12-31 19:24:04 +00:00
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 [ ! -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 "$1"
rm -rf squashfs-root
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
mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$HEAD" -i "$@"
chmod +x "$(realpath "$1").sh"