appdwarf/appdwarf

53 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/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"
2021-12-31 19:24:04 +00:00
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
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
chmod +x "$app"
rm -rf squashfs-root
"$(realpath "$app")" --appimage-extract
set -- "$(basename "$app" .AppImage)" "$@"
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"