2 # shellcheck shell=bash
4 if [ -n "$DEBUG" ] ; then
11 # can be read by appimages: https://docs.appimage.org/packaging-guide/environment-variables.html
16 # dest : let's unpack() create the directory
21 # https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63
22 local appimageSignature
;
23 appimageSignature
="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $10$11;}')"
25 appimageType
="$(LC_ALL=C readelf -h "$src" | awk 'NR==2{print $12;}')"
27 # check AppImage signature
28 if [ "$appimageSignature" != "4149" ]; then
29 echo "Not an AppImage file"
33 case "$appimageType" in
35 echo "Uncompress $(basename "$src") of type $appimageType"
37 pv
"$src" | bsdtar
-x -C "$out" -f -
41 # This method avoid issues with non executable appimages,
42 # non-native packer, packer patching and squashfs-root destination prefix.
44 # multiarch offset one-liner using same method as AppImage
45 # see https://gist.github.com/probonopd/a490ba3401b5ef7b881d5e603fa20c93
46 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}')
47 echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset"
48 unsquashfs
-q -d "$out" -o "$offset" "$src"
53 # get ready, https://github.com/TheAssassin/type3-runtime
56 echo Unsupported AppImage Type
: "$appimageType"
60 echo "$(basename "$src") is now installed in $out"
65 SHA256
=$
(sha256sum
"$APPIMAGE" |
awk '{print $1}')
66 export APPDIR
="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256"
69 if [ -x "$APPDIR/squashfs-root" ]; then APPDIR
="$APPDIR/squashfs-root"; fi
71 if [ ! -x "$APPDIR" ]; then
72 mkdir
-p "$(dirname "$APPDIR")"
73 unpack
"$APPIMAGE" "$APPDIR"
74 else echo "$(basename "$APPIMAGE")" installed
in "$APPDIR"
77 export PATH
="$PATH:$PWD/usr/bin"
82 # quite same in appimageTools
83 export APPIMAGE_SILENT_INSTALL
=1
85 if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then
87 exec "$APPIMAGE_DEBUG_EXEC"
90 exec "$APPDIR/AppRun" "$@"
95 Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]
99 -x <directory> : extract appimage in the directory then exit.
100 -w <directory> : run uncompressed appimage directory (used in appimageTools)
102 [AppImage options]: Options are passed on to the appimage.
103 If you want to execute a custom command in the appimage's environment, set the APPIMAGE_DEBUG_EXEC environment variable.
109 while getopts "x:w:dh" option
; do
118 export APPDIR
=${OPTARG}
127 shift "$((OPTIND-1))"
129 if [ -n "$wrap_opt" ] && [ -d "$APPDIR" ]; then
133 APPIMAGE
="$(realpath "$1")" || usage
137 if [ -n "$unpack_opt" ] && [ -f "$APPIMAGE" ]; then
138 unpack
"$APPIMAGE" "$APPDIR"
142 if [ -n "$apprun_opt" ] && [ -f "$APPIMAGE" ]; then