2021-06-08 19:53:29 +00:00
|
|
|
#!/bin/bash
|
2021-05-29 20:13:12 +00:00
|
|
|
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"
|
2021-05-29 20:13:12 +00:00
|
|
|
|
|
|
|
usage(){
|
2021-06-08 19:53:29 +00:00
|
|
|
echo "Usage: $(basename "$0") [option] [FILE/FOLDER/URL]"
|
2021-05-29 20:13:12 +00:00
|
|
|
echo " Compress a given AppDir (default)"
|
|
|
|
echo " -a, --appimage Convert a given AppImage to appdwarf"
|
2022-01-28 15:37:43 +00:00
|
|
|
echo " -B, --lookback Change dwarfs block lookback amount"
|
2022-01-01 05:50:04 +00:00
|
|
|
echo " -f, --folder Make image mount to a specified folder instead of running AppRun"
|
|
|
|
echo " -s, --separate Use old, separated header format"
|
2021-05-29 20:13:12 +00:00
|
|
|
echo " -u, --url Fetch AppImage from URL and convert to appdwarf"
|
2022-01-01 05:50:04 +00:00
|
|
|
|
2022-01-25 15:53:41 +00:00
|
|
|
echo " -h, --help Print this help text"
|
2022-01-01 05:50:04 +00:00
|
|
|
echo " -v, --version Print the appdwarf version"
|
2021-05-29 20:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dwarf() {
|
2022-01-14 18:41:46 +00:00
|
|
|
mkdwarfs -i "$1" -o "$(realpath "$1").sh" -B"$back" "${@:2}" --header "$HEAD"
|
2022-01-01 05:50:04 +00:00
|
|
|
chmod +x "$(realpath "$1").sh"
|
2021-05-29 20:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
appimage() {
|
|
|
|
if [[ -f "$1" ]]
|
|
|
|
then
|
|
|
|
chmod +x "$1"
|
2021-06-23 01:06:07 +00:00
|
|
|
rm -rf squashfs-root
|
2021-05-29 20:13:12 +00:00
|
|
|
./"$1" --appimage-extract || exit 1
|
2021-07-10 03:40:58 +00:00
|
|
|
dwarf squashfs-root "${@:2}"
|
2021-05-29 20:13:12 +00:00
|
|
|
rm -rf squashfs-root
|
2021-06-08 19:53:29 +00:00
|
|
|
mv squashfs-root.sh "$(basename "$1" .AppImage)".sh
|
2021-05-29 20:13:12 +00:00
|
|
|
else
|
|
|
|
echo "$1" is not a valid file
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-12-31 19:24:04 +00:00
|
|
|
|
|
|
|
################################################################
|
|
|
|
|
2021-12-31 18:27:01 +00:00
|
|
|
header
|
2021-12-31 19:24:04 +00:00
|
|
|
back=5
|
|
|
|
|
2021-05-29 20:13:12 +00:00
|
|
|
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.
|
2021-05-29 20:13:12 +00:00
|
|
|
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
|
|
|
|
;;
|
2022-01-28 15:37:43 +00:00
|
|
|
--lookback | -B)
|
2021-12-31 19:24:04 +00:00
|
|
|
back=$2
|
|
|
|
shift 2
|
|
|
|
;;
|
2021-12-31 18:27:01 +00:00
|
|
|
--separate | -s)
|
|
|
|
header_separate
|
|
|
|
shift
|
|
|
|
;;
|
2021-12-31 19:37:50 +00:00
|
|
|
|
|
|
|
--appimage | -a)
|
|
|
|
appimage "${@:2}"
|
|
|
|
exit 0
|
|
|
|
;;
|
2021-05-29 20:13:12 +00:00
|
|
|
--url | -u)
|
|
|
|
file=$(basename "$2")
|
2022-01-25 15:53:41 +00:00
|
|
|
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}"
|
2021-05-29 20:13:12 +00:00
|
|
|
rm "$file"
|
|
|
|
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 "$@"
|
2021-05-29 20:13:12 +00:00
|
|
|
exit 0
|
|
|
|
fi
|