Created
March 6, 2020 23:22
-
-
Save bignaux/e08b27ee300b12ccfd7fb0efb2c7a6c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!@shell@ | |
if [ ! -z "$DEBUG" ] ; then | |
env | |
set -x | |
fi | |
export PATH=@path@ | |
# src : AppImage | |
# dest : let's unpack() create the directory | |
unpack() { | |
src=$1 | |
out=$2 | |
echo $src $out | |
# https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63 | |
eval "$(r2 "$src" -nn -Nqc "p8j 3 @ 8" | | |
jq -r '{appimageSignature: (.[:-1]|implode), appimageType: .[-1]}| | |
@sh "appimageSignature=\(.appimageSignature) appimageType=\(.appimageType)"')" | |
# check AppImage signature | |
if [[ "$appimageSignature" != "AI" ]]; then | |
echo "Not an appimage." | |
exit -1 | |
fi | |
case "$appimageType" in | |
1) | |
mkdir "$out" | |
bsdtar -x -C "$out" -f "$src" | |
;; | |
2) # 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 | |
offset=$(r2 "$src" -nn -Nqc "pfj.elf_header @ 0" |\ | |
jq 'map({(.name): .value}) | add | .shoff + (.shnum * .shentsize)') | |
unsquashfs -q -d "$out" -o "$offset" "$src" | |
chmod go-w "$out" | |
;; | |
# 3) get ready, https://github.com/TheAssassin/type3-runtime | |
*) echo Unsupported AppImage Type: "$appimageType" | |
exit | |
;; | |
esac | |
echo AppImage Type: "$appimageType" | |
} | |
apprun() { | |
eval "$(rahash2 "$APPIMAGE" -j | jq -r '.[] | @sh "SHA256=\(.hash)"')" | |
echo sha256 = \"$SHA256\"\; | |
SQUASHFS_ROOT="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256" | |
mkdir -p "$SQUASHFS_ROOT" | |
# could we remove squashfs-root? | |
export APPDIR="$SQUASHFS_ROOT/squashfs-root" | |
echo $(basename "$APPIMAGE") installed in "$APPDIR" | |
if [ ! -x "$APPDIR" ]; then | |
cd "$SQUASHFS_ROOT" | |
unpack "$APPIMAGE" "$APPDIR" | |
fi | |
wrap | |
} | |
wrap() { | |
# quite same in appimageTools | |
export APPIMAGE_SILENT_INSTALL=1 | |
cd "$APPDIR" | |
export PATH="$PATH:$PWD/usr/bin" | |
if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then | |
exec "$APPIMAGE_DEBUG_EXEC" | |
fi | |
# AppRun escape strategy | |
binary="./AppRun" | |
#if [ rg Exec=""] | |
if [ -n "$(file "$binary" | rg "Bourne-Again")" ]; then | |
eval $(rg BIN= "$binary" --no-line-number) | |
if [ -f $BIN ]; then | |
binary=$BIN | |
fi | |
fi | |
# look for linked link if elf | |
if [ -n "$(file "$binary" | rg "ELF")" ]; then | |
#strace $binary | |
rarun2 preload=/nix/store/7a68nclbq638gp7jdi50p52wfvgifmpq-system-path/lib/libfuse.so.2 program=$binary | |
fi | |
} | |
usage() { | |
echo "Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]"; | |
echo | |
echo 'Options are passed on to the appimage.' | |
echo "If you want to execute a custom command in the appimage's environment, set the APPIMAGE_DEBUG_EXEC environment variable." | |
exit 1 | |
} | |
while getopts ":a:d:xrw" option; do | |
case "${option}" in | |
a) #AppImage file | |
# why realpath? | |
APPIMAGE="$(realpath "${OPTARG}")" | |
;; | |
d) #appimage Directory | |
APPDIR=${OPTARG} | |
;; | |
x) # eXtract | |
unpack_opt=true | |
;; | |
r) # appimage-Run | |
apprun_opt=true | |
;; | |
w) # WrapAppImage | |
wrap_opt=true | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then | |
unpack "$APPIMAGE" "$APPDIR" | |
exit | |
fi | |
if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then | |
apprun | |
fi | |
if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then | |
wrap | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment