appdwarf/appdwarf

100 lines
2.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
set -e
IFS=$(printf '\n\t')
VER=2.5
BACK=5
2022-01-14 18:41:46 +00:00
HERE=$(dirname "$(readlink -f "${0}")")
. "$HERE/headers" && header || exit 1
if test $# -eq 0; then
tput setaf 3
2022-03-25 22:40:58 +00:00
echo "Usage: $(basename "$0") [option] [FILE/FOLDER/URL] [dwarfs option]"
echo " Compress a given AppDir (default)"
tput setaf 7
echo " -a, --appimage Convert a given AppImage to appdwarf"
echo " -B, --lookback Change dwarfs block lookback amount"
echo " -f, --folder Make image mount to a specified folder instead of running AppRun"
echo " -s, --separate Use old, separated header format"
echo " -u, --url Fetch AppImage from URL and convert to appdwarf"
echo
tput setaf 4
echo " -h, --help Print this help text"
echo " -v, --version Print the appdwarf version"
exit 0
fi
dwarf() {
mkdwarfs -i "$@" -o "$(realpath "$1").sh" -B"$BACK" --header "$HEAD"
chmod +x "$(realpath "$1").sh"
}
appimage() {
if [ ! -f "$1" ]; then
tput setaf 1
echo "$1" is not a valid file
exit 1
fi
chmod +x "$1"
rm -rf squashfs-root
case $1 in
/*) "$1" --appimage-extract || exit 1 ;;
*) ./"$1" --appimage-extract || exit 1 ;;
esac
file="$1"
shift
dwarf squashfs-root "$@"
rm -rf squashfs-root "$file"
mv squashfs-root.sh "$(basename "$file" .AppImage)".sh
exit 0
}
2021-12-31 19:24:04 +00:00
while true
do
case "$1" in
--help | -h)
exec appdwarf
;;
2021-12-31 19:24:04 +00:00
--version | -v)
tput setaf 5
2021-12-31 19:24:04 +00:00
echo appdwarf v"$VER"
echo Maintained by phantop.
exit 0
;;
2021-12-31 19:24:04 +00:00
--folder | -f)
2022-01-14 18:41:46 +00:00
header_folder "$(realpath "$2")"
2021-12-31 19:24:04 +00:00
shift 2
;;
--lookback | -B)
BACK=$2
2021-12-31 19:24:04 +00:00
shift 2
;;
--separate | -s)
header_separate
shift
;;
--appimage | -a)
shift
appimage "$@"
;;
--url | -u)
shift
file=$(basename "$1")
if which aria2c; then
aria2c -x16 -s16 "$1" -o "$file" || exit 1
else
wget "$1" -O "$file" || exit 1
fi
shift
appimage "$file" "$@"
;;
--)
shift; break;;
*)
break;;
esac
done
dwarf "$@"