2019-06-16 21:59:06 +02:00
|
|
|
{ writeScript, buildFHSUserEnv, coreutils, file, libarchive, runtimeShell
|
2019-01-27 14:02:50 +01:00
|
|
|
, extraPkgs ? pkgs: [], appimageTools }:
|
2018-06-09 19:10:16 +02:00
|
|
|
|
2019-01-27 14:02:50 +01:00
|
|
|
let
|
|
|
|
fhsArgs = appimageTools.defaultFhsEnvArgs;
|
|
|
|
in buildFHSUserEnv (fhsArgs // {
|
2018-06-09 19:10:16 +02:00
|
|
|
name = "appimage-run";
|
|
|
|
|
2019-01-27 14:02:50 +01:00
|
|
|
targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
2018-06-09 19:10:16 +02:00
|
|
|
|
|
|
|
runScript = writeScript "appimage-exec" ''
|
2019-02-26 12:45:54 +01:00
|
|
|
#!${runtimeShell}
|
2019-03-09 21:43:09 +01:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo "Usage: $0 FILE [OPTION...]"
|
|
|
|
echo
|
2019-03-09 22:11:47 +01:00
|
|
|
echo 'Options are passed on to the appimage.'
|
2019-03-09 21:43:09 +01:00
|
|
|
echo "If you want to execute a custom command in the appimage's environment, set the APPIMAGE_DEBUG_EXEC environment variable."
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-06-09 19:10:16 +02:00
|
|
|
APPIMAGE="$(realpath "$1")"
|
2019-03-09 22:11:47 +01:00
|
|
|
shift
|
2018-06-09 19:10:16 +02:00
|
|
|
|
|
|
|
if [ ! -x "$APPIMAGE" ]; then
|
|
|
|
echo "fatal: $APPIMAGE is not executable"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
SHA256="$(${coreutils}/bin/sha256sum "$APPIMAGE" | cut -d ' ' -f 1)"
|
|
|
|
SQUASHFS_ROOT="''${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256/"
|
|
|
|
mkdir -p "$SQUASHFS_ROOT"
|
|
|
|
|
|
|
|
export APPDIR="$SQUASHFS_ROOT/squashfs-root"
|
|
|
|
if [ ! -x "$APPDIR" ]; then
|
|
|
|
cd "$SQUASHFS_ROOT"
|
2018-09-19 18:42:13 +02:00
|
|
|
|
|
|
|
if ${file}/bin/file --mime-type --brief --keep-going "$APPIMAGE" | grep -q iso; then
|
|
|
|
# is type-1 appimage
|
2018-10-16 13:55:31 +02:00
|
|
|
mkdir "$APPDIR"
|
|
|
|
${libarchive}/bin/bsdtar -x -C "$APPDIR" -f "$APPIMAGE"
|
2018-09-19 18:42:13 +02:00
|
|
|
else
|
|
|
|
# is type-2 appimage
|
|
|
|
"$APPIMAGE" --appimage-extract 2>/dev/null
|
|
|
|
fi
|
2018-06-09 19:10:16 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd "$APPDIR"
|
|
|
|
export PATH="$PATH:$PWD/usr/bin"
|
|
|
|
export APPIMAGE_SILENT_INSTALL=1
|
|
|
|
|
|
|
|
if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then
|
|
|
|
exec "$APPIMAGE_DEBUG_EXEC"
|
|
|
|
fi
|
|
|
|
|
2019-03-09 22:11:47 +01:00
|
|
|
exec ./AppRun "$@"
|
2018-06-09 19:10:16 +02:00
|
|
|
'';
|
2019-01-27 14:02:50 +01:00
|
|
|
})
|