2020-03-05 22:57:36 +00:00
|
|
|
#!@shell@
|
2020-11-24 12:55:04 +00:00
|
|
|
# shellcheck shell=bash
|
|
|
|
|
2020-03-08 12:38:32 +00:00
|
|
|
if [ -n "$DEBUG" ] ; then
|
2020-03-05 22:57:36 +00:00
|
|
|
set -x
|
|
|
|
fi
|
|
|
|
|
2020-03-08 12:38:32 +00:00
|
|
|
PATH="@path@:$PATH"
|
2020-03-08 19:34:23 +00:00
|
|
|
apprun_opt=true
|
|
|
|
|
2020-03-05 22:57:36 +00:00
|
|
|
# src : AppImage
|
|
|
|
# dest : let's unpack() create the directory
|
|
|
|
unpack() {
|
2020-05-27 02:27:48 +01:00
|
|
|
local src="$1"
|
|
|
|
local out="$2"
|
2020-03-05 22:57:36 +00:00
|
|
|
|
|
|
|
# https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
|
2020-11-24 12:55:04 +00:00
|
|
|
local appimageSignature;
|
|
|
|
appimageSignature="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $10$11;}')"
|
|
|
|
local appimageType;
|
|
|
|
appimageType="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $12;}')"
|
2020-03-05 22:57:36 +00:00
|
|
|
|
|
|
|
# check AppImage signature
|
2020-05-27 02:27:48 +01:00
|
|
|
if [ "$appimageSignature" != "4149" ]; then
|
|
|
|
echo "Not an AppImage file"
|
2020-03-08 12:38:32 +00:00
|
|
|
exit
|
2020-03-05 22:57:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
case "$appimageType" in
|
2020-05-27 02:27:48 +01:00
|
|
|
"01")
|
|
|
|
echo "Uncompress $(basename "$src") of type $appimageType"
|
|
|
|
mkdir "$out"
|
|
|
|
pv "$src" | bsdtar -x -C "$out" -f -
|
|
|
|
;;
|
|
|
|
|
|
|
|
"02")
|
|
|
|
# This method avoid issues with non executable appimages,
|
|
|
|
# non-native packer, packer patching and squashfs-root destination prefix.
|
|
|
|
|
|
|
|
# multiarch offset one-liner using same method as AppImage
|
|
|
|
# see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
|
2020-11-24 12:55:04 +00:00
|
|
|
offset=$(LC_ALL=C readelf -h "$src" | awk 'NR==13{e_shoff=$5} NR==18{e_shentsize=$5} NR==19{e_shnum=$5} END{print e_shoff+e_shentsize*e_shnum}')
|
2020-05-27 02:27:48 +01:00
|
|
|
echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset"
|
|
|
|
unsquashfs -q -d "$out" -o "$offset" "$src"
|
|
|
|
chmod go-w "$out"
|
|
|
|
;;
|
|
|
|
|
|
|
|
# "03")
|
|
|
|
# get ready, https://github.com/TheAssassin/type3-runtime
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo Unsupported AppImage Type: "$appimageType"
|
|
|
|
exit
|
|
|
|
;;
|
2020-03-05 22:57:36 +00:00
|
|
|
esac
|
|
|
|
echo "$(basename "$src") is now installed in $out"
|
|
|
|
}
|
|
|
|
|
|
|
|
apprun() {
|
|
|
|
|
2020-05-27 02:27:48 +01:00
|
|
|
SHA256=$(sha256sum "$APPIMAGE" | awk '{print $1}')
|
2020-03-05 22:57:36 +00:00
|
|
|
export APPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256"
|
|
|
|
|
|
|
|
#compatibility
|
|
|
|
if [ -x "$APPDIR/squashfs-root" ]; then APPDIR="$APPDIR/squashfs-root"; fi
|
|
|
|
|
|
|
|
if [ ! -x "$APPDIR" ]; then
|
2020-03-08 12:38:32 +00:00
|
|
|
mkdir -p "$(dirname "$APPDIR")"
|
2020-03-05 22:57:36 +00:00
|
|
|
unpack "$APPIMAGE" "$APPDIR"
|
2020-03-08 12:38:32 +00:00
|
|
|
else echo "$(basename "$APPIMAGE")" installed in "$APPDIR"
|
2020-03-05 22:57:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
export PATH="$PATH:$PWD/usr/bin"
|
|
|
|
}
|
|
|
|
|
|
|
|
wrap() {
|
|
|
|
|
|
|
|
# quite same in appimageTools
|
|
|
|
export APPIMAGE_SILENT_INSTALL=1
|
|
|
|
|
|
|
|
if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then
|
2021-01-04 12:00:00 +00:00
|
|
|
cd "$APPDIR" || true
|
2020-03-05 22:57:36 +00:00
|
|
|
exec "$APPIMAGE_DEBUG_EXEC"
|
|
|
|
fi
|
|
|
|
|
2021-01-04 12:00:00 +00:00
|
|
|
exec "$APPDIR/AppRun" "$@"
|
2020-03-05 22:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
2020-03-08 19:34:23 +00:00
|
|
|
cat <<EOF
|
|
|
|
Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]
|
|
|
|
|
|
|
|
-h show this message
|
|
|
|
-d debug mode
|
|
|
|
-x <directory> : extract appimage in the directory then exit.
|
|
|
|
-w <directory> : run uncompressed appimage directory (used in appimageTools)
|
|
|
|
|
|
|
|
[AppImage options]: Options are passed on to the appimage.
|
|
|
|
If you want to execute a custom command in the appimage's environment, set the APPIMAGE_DEBUG_EXEC environment variable.
|
|
|
|
|
|
|
|
EOF
|
2020-03-05 22:57:36 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2020-03-08 19:34:23 +00:00
|
|
|
while getopts "x:w:dh" option; do
|
2020-05-27 02:27:48 +01:00
|
|
|
case "${option}" in
|
|
|
|
d) set -x
|
|
|
|
;;
|
|
|
|
x) # eXtract
|
|
|
|
unpack_opt=true
|
|
|
|
APPDIR=${OPTARG}
|
|
|
|
;;
|
|
|
|
w) # WrapAppImage
|
|
|
|
export APPDIR=${OPTARG}
|
|
|
|
wrap_opt=true
|
|
|
|
;;
|
|
|
|
h) usage
|
|
|
|
;;
|
|
|
|
*) usage
|
|
|
|
;;
|
|
|
|
esac
|
2020-03-05 22:57:36 +00:00
|
|
|
done
|
2020-05-27 02:27:48 +01:00
|
|
|
shift "$((OPTIND-1))"
|
2020-03-05 22:57:36 +00:00
|
|
|
|
2020-05-27 02:27:48 +01:00
|
|
|
if [ -n "$wrap_opt" ] && [ -d "$APPDIR" ]; then
|
2020-03-08 19:34:23 +00:00
|
|
|
wrap "$@"
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
APPIMAGE="$(realpath "$1")" || usage
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2020-05-27 02:27:48 +01:00
|
|
|
if [ -n "$unpack_opt" ] && [ -f "$APPIMAGE" ]; then
|
2020-03-05 22:57:36 +00:00
|
|
|
unpack "$APPIMAGE" "$APPDIR"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2020-05-27 02:27:48 +01:00
|
|
|
if [ -n "$apprun_opt" ] && [ -f "$APPIMAGE" ]; then
|
2020-03-08 12:53:48 +00:00
|
|
|
apprun
|
|
|
|
wrap "$@"
|
2020-03-08 12:38:32 +00:00
|
|
|
exit
|
2020-03-05 22:57:36 +00:00
|
|
|
fi
|