appdwarf/appdwarf

104 lines
2.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -eo pipefail
IFS=$'\n\t'
2021-12-31 19:24:04 +00:00
VER=2
2022-01-14 18:41:46 +00:00
HERE=$(dirname "$(readlink -f "${0}")")
source "$HERE/headers"
usage(){
2022-03-25 22:40:58 +00:00
echo "Usage: $(basename "$0") [option] [FILE/FOLDER/URL] [dwarfs option]"
echo " Compress a given AppDir (default)"
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 " -h, --help Print this help text"
echo " -v, --version Print the appdwarf version"
}
dwarf() {
2022-01-14 18:41:46 +00:00
mkdwarfs -i "$1" -o "$(realpath "$1").sh" -B"$back" "${@:2}" --header "$HEAD"
chmod +x "$(realpath "$1").sh"
}
appimage() {
if [[ -f "$1" ]]
then
chmod +x "$1"
rm -rf squashfs-root
case $1 in
/*) "$1" --appimage-extract || exit 1 ;;
*) ./"$1" --appimage-extract || exit 1 ;;
esac
2021-07-10 03:40:58 +00:00
dwarf squashfs-root "${@:2}"
rm -rf squashfs-root "$1"
mv squashfs-root.sh "$(basename "$1" .AppImage)".sh
else
echo "$1" is not a valid file
exit 1
fi
}
2021-12-31 19:24:04 +00:00
################################################################
header
2021-12-31 19:24:04 +00:00
back=5
while true
do
case "$1" in
--help | -h)
usage
exit 0
;;
2021-12-31 19:24:04 +00:00
--version | -v)
tput setaf 2
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)
2021-12-31 19:24:04 +00:00
back=$2
shift 2
;;
--separate | -s)
header_separate
shift
;;
--appimage | -a)
appimage "${@:2}"
exit 0
;;
--url | -u)
file=$(basename "$2")
if which aria2c; then
aria2c -x16 -s16 "$2" -o "$file" || exit 1
else
wget "$2" -O "$file" || exit 1
fi
2021-07-10 03:40:58 +00:00
appimage "$file" "${@:3}"
exit 0
;;
--)
shift; break;;
*)
break;;
esac
done
if test $# -eq 0; then
usage
exit 0
else
2021-07-10 03:40:58 +00:00
dwarf "$@"
exit 0
fi