appdwarf/appdwarf

62 lines
1.9 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 " -f, --folder Make mount toggle image for a given folder"
echo " -s, --separate Use old, separated header format"
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"
shift ;;
2021-12-31 19:24:04 +00:00
--folder | -f)
"$HEAD"_folder
HEAD=/tmp/dwarfhead
sed -i "2s|$|\"$2\"|" "$HEAD"
shift ;;
--separate | -s)
HEAD="$HEAD"_separate ;;
--url | -u)
app=$(basename "$2")
aria2c -x16 -s16 "$2" -o "$app" || wget "$2" -O "$app"
shift ;;
--version | -v)
tput setaf 4
echo appdwarf v2.9
echo Maintained by phantop.
exit ;;
--)
shift; break;;
*)
break;;
esac; shift
done
if [ -n "$app" ]; then # handle and extract appimage input, if present
[ ! -f "$app" ] && tput setaf 1 && echo "$app" is not a valid file && exit 1
chmod +x "$app"
rm -rf squashfs-root
"$(realpath "$app")" --appimage-extract || exit 1
rm "$app"
set -- "$(basename "$app" .AppImage)" "$@"
mv squashfs-root "$1"
fi
[ ! -d "$1" ] && tput setaf 1 && echo "$1" is not a valid folder && exit 1
mkdwarfs -o "$(realpath "$1").sh" -B5 --header "$HEAD" -i "$@"
chmod +x "$(realpath "$1").sh"