2019-06-16 20:59:06 +01:00
|
|
|
{ writeScript, buildFHSUserEnv, coreutils, file, libarchive, runtimeShell
|
2019-01-27 13:02:50 +00:00
|
|
|
, extraPkgs ? pkgs: [], appimageTools }:
|
2018-06-09 18:10:16 +01:00
|
|
|
|
2019-01-27 13:02:50 +00:00
|
|
|
let
|
|
|
|
fhsArgs = appimageTools.defaultFhsEnvArgs;
|
|
|
|
in buildFHSUserEnv (fhsArgs // {
|
2018-06-09 18:10:16 +01:00
|
|
|
name = "appimage-run";
|
|
|
|
|
2019-01-27 13:02:50 +00:00
|
|
|
targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
2018-06-09 18:10:16 +01:00
|
|
|
|
|
|
|
runScript = writeScript "appimage-exec" ''
|
2019-02-26 11:45:54 +00:00
|
|
|
#!${runtimeShell}
|
2019-03-09 20:43:09 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo "Usage: $0 FILE [OPTION...]"
|
|
|
|
echo
|
2019-03-09 21:11:47 +00:00
|
|
|
echo 'Options are passed on to the appimage.'
|
2019-03-09 20:43:09 +00: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 18:10:16 +01:00
|
|
|
APPIMAGE="$(realpath "$1")"
|
2019-03-09 21:11:47 +00:00
|
|
|
shift
|
2018-06-09 18:10:16 +01: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 17:42:13 +01:00
|
|
|
|
|
|
|
if ${file}/bin/file --mime-type --brief --keep-going "$APPIMAGE" | grep -q iso; then
|
|
|
|
# is type-1 appimage
|
2018-10-16 12:55:31 +01:00
|
|
|
mkdir "$APPDIR"
|
|
|
|
${libarchive}/bin/bsdtar -x -C "$APPDIR" -f "$APPIMAGE"
|
2018-09-19 17:42:13 +01:00
|
|
|
else
|
|
|
|
# is type-2 appimage
|
|
|
|
"$APPIMAGE" --appimage-extract 2>/dev/null
|
|
|
|
fi
|
2018-06-09 18:10:16 +01: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 21:11:47 +00:00
|
|
|
exec ./AppRun "$@"
|
2018-06-09 18:10:16 +01:00
|
|
|
'';
|
2019-01-27 13:02:50 +00:00
|
|
|
})
|