mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-19 12:11:28 +00:00
appimage-run: replace writeScript to a standalone appimage-exec.sh
This commit is contained in:
parent
bf83a7cc66
commit
349e923e00
43
pkgs/tools/package-management/appimage-run/appimage-exec.sh
Executable file
43
pkgs/tools/package-management/appimage-run/appimage-exec.sh
Executable file
|
@ -0,0 +1,43 @@
|
|||
#!@bash@/bin/bash
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $0 FILE [OPTION...]"
|
||||
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
|
||||
fi
|
||||
APPIMAGE="$(realpath "$1")"
|
||||
shift
|
||||
|
||||
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"
|
||||
|
||||
if @file@/bin/file --mime-type --brief --keep-going "$APPIMAGE" | grep -q iso; then
|
||||
# is type-1 appimage
|
||||
mkdir "$APPDIR"
|
||||
@libarchive@/bin/bsdtar -x -C "$APPDIR" -f "$APPIMAGE"
|
||||
else
|
||||
# is type-2 appimage
|
||||
"$APPIMAGE" --appimage-extract 2>/dev/null
|
||||
fi
|
||||
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
|
||||
|
||||
exec ./AppRun "$@"
|
|
@ -1,56 +1,31 @@
|
|||
{ writeScript, buildFHSUserEnv, coreutils, file, libarchive, runtimeShell
|
||||
, extraPkgs ? pkgs: [], appimageTools }:
|
||||
{ buildFHSUserEnv, coreutils, file, libarchive, runtimeShell
|
||||
, extraPkgs ? pkgs: [], appimageTools, stdenv, bash }:
|
||||
|
||||
let
|
||||
fhsArgs = appimageTools.defaultFhsEnvArgs;
|
||||
in buildFHSUserEnv (fhsArgs // {
|
||||
|
||||
name = "appimage-run";
|
||||
version = "1.0";
|
||||
fhsArgs = appimageTools.defaultFhsEnvArgs;
|
||||
|
||||
targetPkgs = pkgs: fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
||||
appimage-exec = stdenv.mkDerivation {
|
||||
#inherit pname version;
|
||||
name = "appimage-exec";
|
||||
|
||||
runScript = writeScript "appimage-exec" ''
|
||||
#!${runtimeShell}
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $0 FILE [OPTION...]"
|
||||
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
|
||||
fi
|
||||
APPIMAGE="$(realpath "$1")"
|
||||
shift
|
||||
inherit coreutils file libarchive bash;
|
||||
|
||||
if [ ! -x "$APPIMAGE" ]; then
|
||||
echo "fatal: $APPIMAGE is not executable"
|
||||
exit 1
|
||||
fi
|
||||
buildCommand = ''
|
||||
mkdir -p $out/bin/
|
||||
substituteAll ${./appimage-exec.sh} $out/bin/appimage-exec.sh
|
||||
chmod +x $out/bin/appimage-exec.sh
|
||||
'';
|
||||
};
|
||||
|
||||
SHA256="$(${coreutils}/bin/sha256sum "$APPIMAGE" | cut -d ' ' -f 1)"
|
||||
SQUASHFS_ROOT="''${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256/"
|
||||
mkdir -p "$SQUASHFS_ROOT"
|
||||
in buildFHSUserEnv (fhsArgs // {
|
||||
inherit name;
|
||||
|
||||
export APPDIR="$SQUASHFS_ROOT/squashfs-root"
|
||||
if [ ! -x "$APPDIR" ]; then
|
||||
cd "$SQUASHFS_ROOT"
|
||||
|
||||
if ${file}/bin/file --mime-type --brief --keep-going "$APPIMAGE" | grep -q iso; then
|
||||
# is type-1 appimage
|
||||
mkdir "$APPDIR"
|
||||
${libarchive}/bin/bsdtar -x -C "$APPDIR" -f "$APPIMAGE"
|
||||
else
|
||||
# is type-2 appimage
|
||||
"$APPIMAGE" --appimage-extract 2>/dev/null
|
||||
fi
|
||||
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
|
||||
|
||||
exec ./AppRun "$@"
|
||||
'';
|
||||
targetPkgs = pkgs:
|
||||
[ appimage-exec
|
||||
] ++ fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
|
||||
#extraInstallCommands = '''';
|
||||
runScript = "appimage-exec.sh";
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue