mirror of
https://github.com/Phantop/appdwarf.git
synced 2025-01-09 05:37:04 +00:00
64 lines
2.1 KiB
Bash
Executable file
64 lines
2.1 KiB
Bash
Executable file
#!/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 image mount to a given folder (no AppRun)"
|
|
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"
|
|
|
|
while true; do # process args
|
|
case "$1" in
|
|
--appimage | -a)
|
|
app="$2"
|
|
shift ;;
|
|
--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 2; echo appdwarf v2.9
|
|
tput setaf 4; echo Built by July 🏳️🌈
|
|
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 >&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"
|