From 349e923e00cf46fa33f118bfd22024f392e95a79 Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Thu, 5 Mar 2020 18:53:11 +0100 Subject: [PATCH 1/6] appimage-run: replace writeScript to a standalone appimage-exec.sh --- .../appimage-run/appimage-exec.sh | 43 ++++++++++++ .../appimage-run/default.nix | 69 ++++++------------- 2 files changed, 65 insertions(+), 47 deletions(-) create mode 100755 pkgs/tools/package-management/appimage-run/appimage-exec.sh diff --git a/pkgs/tools/package-management/appimage-run/appimage-exec.sh b/pkgs/tools/package-management/appimage-run/appimage-exec.sh new file mode 100755 index 00000000000..cdce727af4f --- /dev/null +++ b/pkgs/tools/package-management/appimage-run/appimage-exec.sh @@ -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 "$@" diff --git a/pkgs/tools/package-management/appimage-run/default.nix b/pkgs/tools/package-management/appimage-run/default.nix index 426cc7943e5..3eeaa752f02 100644 --- a/pkgs/tools/package-management/appimage-run/default.nix +++ b/pkgs/tools/package-management/appimage-run/default.nix @@ -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"; }) From b36d3f2c4a94a5e5002fb0647db5465e7c38668b Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Thu, 5 Mar 2020 23:57:36 +0100 Subject: [PATCH 2/6] appimage: replace writeScript to a standalone appimage-exec.sh --- pkgs/build-support/appimage/appimage-exec.sh | 129 ++++++++++++++++++ pkgs/build-support/appimage/default.nix | 68 +++------ .../appimage-run/appimage-exec.sh | 43 ------ .../appimage-run/default.nix | 28 +--- 4 files changed, 155 insertions(+), 113 deletions(-) create mode 100755 pkgs/build-support/appimage/appimage-exec.sh delete mode 100755 pkgs/tools/package-management/appimage-run/appimage-exec.sh diff --git a/pkgs/build-support/appimage/appimage-exec.sh b/pkgs/build-support/appimage/appimage-exec.sh new file mode 100755 index 00000000000..fd38889b9aa --- /dev/null +++ b/pkgs/build-support/appimage/appimage-exec.sh @@ -0,0 +1,129 @@ +#!@shell@ +if [ ! -z "$DEBUG" ] ; then + set -x +fi + +export PATH=@path@ + +# src : AppImage +# dest : let's unpack() create the directory +unpack() { + src=$1 + out=$2 + + # 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) echo "Uncompress $(basename "$src") of Type: $appimageType." + mkdir "$out" + pv "$src" | bsdtar -x -C "$out" -f - + ;; + + 2) echo "Uncompress $(basename "$src") of Type: $appimageType." + # 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 "$(basename "$src") is now installed in $out" +} + +apprun() { + + eval "$(rahash2 "$APPIMAGE" -j | jq -r '.[] | @sh "SHA256=\(.hash)"')" + echo sha256 = \"$SHA256\"\; + export APPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256" + + #compatibility + if [ -x "$APPDIR/squashfs-root" ]; then APPDIR="$APPDIR/squashfs-root"; fi + + if [ ! -x "$APPDIR" ]; then + mkdir -p $(dirname "$APPDIR") + unpack "$APPIMAGE" "$APPDIR" + fi + + echo $(basename "$APPIMAGE") installed in "$APPDIR" + + export PATH="$PATH:$PWD/usr/bin" + wrap +} + +wrap() { + + cd "$APPDIR" + # quite same in appimageTools + export APPIMAGE_SILENT_INSTALL=1 + + if [ -n "$APPIMAGE_DEBUG_EXEC" ]; then + exec "$APPIMAGE_DEBUG_EXEC" + fi + + exec ./AppRun "$@" +} + +usage() { + echo "Usage: appimage-run [appimage-run options] [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 + export 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 diff --git a/pkgs/build-support/appimage/default.nix b/pkgs/build-support/appimage/default.nix index c56aae4c599..4df0f15d84d 100644 --- a/pkgs/build-support/appimage/default.nix +++ b/pkgs/build-support/appimage/default.nix @@ -1,61 +1,35 @@ -{ stdenv, libarchive, radare2, jq, buildFHSUserEnv, squashfsTools, writeScript }: +{ stdenv, buildFHSUserEnv, writeScript, pkgs +, bash, radare2, jq, squashfsTools, ripgrep +, coreutils, libarchive, file, runtimeShell, pv +, lib, runCommand }: rec { - - extract = { name, src }: stdenv.mkDerivation { - name = "${name}-extracted"; - inherit src; - nativeBuildInputs = [ radare2 libarchive jq squashfsTools ]; - buildCommand = '' - # 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 - fi - - case "$appimageType" in - 1) - mkdir $out - bsdtar -x -C $out -f $src - ;; - - 2) - # 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";; - esac - ''; + appimage-exec = pkgs.substituteAll { + src = ./appimage-exec.sh; + isExecutable = true; + dir = "bin"; + path = with pkgs; lib.makeBinPath [ pv ripgrep file radare2 libarchive jq squashfsTools coreutils bash ]; }; + extract = { name, src }: runCommand "${name}-extracted" { + buildInputs = [ appimage-exec ]; + } '' + appimage-exec.sh -x -d $out -a ${src} + ''; + + # for compatibility, deprecated extractType1 = extract; extractType2 = extract; + #wrapType2 = wrapAppImage; + #wrapType1 = wrapAppImage; wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv (defaultFhsEnvArgs // { inherit name; - targetPkgs = pkgs: defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs; + targetPkgs = pkgs: [ appimage-exec ] + ++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs; - runScript = writeScript "run" '' - #!${stdenv.shell} - - export APPDIR=${src} - export APPIMAGE_SILENT_INSTALL=1 - cd $APPDIR - exec ./AppRun "$@" - ''; + runScript = "appimage-exec.sh -w -d ${src}"; } // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage)))); wrapType1 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { diff --git a/pkgs/tools/package-management/appimage-run/appimage-exec.sh b/pkgs/tools/package-management/appimage-run/appimage-exec.sh deleted file mode 100755 index cdce727af4f..00000000000 --- a/pkgs/tools/package-management/appimage-run/appimage-exec.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!@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 "$@" diff --git a/pkgs/tools/package-management/appimage-run/default.nix b/pkgs/tools/package-management/appimage-run/default.nix index 3eeaa752f02..37d1afe2843 100644 --- a/pkgs/tools/package-management/appimage-run/default.nix +++ b/pkgs/tools/package-management/appimage-run/default.nix @@ -1,31 +1,13 @@ -{ buildFHSUserEnv, coreutils, file, libarchive, runtimeShell -, extraPkgs ? pkgs: [], appimageTools, stdenv, bash }: +{ appimageTools, buildFHSUserEnv, extraPkgs ? pkgs: [] }: let - name = "appimage-run"; - version = "1.0"; fhsArgs = appimageTools.defaultFhsEnvArgs; - appimage-exec = stdenv.mkDerivation { - #inherit pname version; - name = "appimage-exec"; - - inherit coreutils file libarchive bash; - - buildCommand = '' - mkdir -p $out/bin/ - substituteAll ${./appimage-exec.sh} $out/bin/appimage-exec.sh - chmod +x $out/bin/appimage-exec.sh - ''; - }; - in buildFHSUserEnv (fhsArgs // { - inherit name; + name = "appimage-run"; - targetPkgs = pkgs: - [ appimage-exec - ] ++ fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs; - #extraInstallCommands = ''''; - runScript = "appimage-exec.sh"; + targetPkgs = pkgs: [ appimageTools.appimage-exec ] + ++ fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs; + runScript = "appimage-exec.sh -r -a"; }) From 2a6cd0e6c08f837b7599601700313c68eb86a6fa Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Sun, 8 Mar 2020 13:38:32 +0100 Subject: [PATCH 3/6] appimageTools: fix appimage-exec.sh according to shellcheck --- pkgs/build-support/appimage/appimage-exec.sh | 37 +++++++++++--------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/pkgs/build-support/appimage/appimage-exec.sh b/pkgs/build-support/appimage/appimage-exec.sh index fd38889b9aa..b209ce983e5 100755 --- a/pkgs/build-support/appimage/appimage-exec.sh +++ b/pkgs/build-support/appimage/appimage-exec.sh @@ -1,15 +1,19 @@ #!@shell@ -if [ ! -z "$DEBUG" ] ; then +if [ -n "$DEBUG" ] ; then set -x fi -export PATH=@path@ +#export PATH=@path@ +PATH="@path@:$PATH" +#DEBUG=0 # src : AppImage # dest : let's unpack() create the directory unpack() { - src=$1 - out=$2 + local src=$1 + local out=$2 + local appimageSignature="" + local appimageType=0 # https://github.com/AppImage/libappimage/blob/ca8d4b53bed5cbc0f3d0398e30806e0d3adeaaab/src/libappimage/utils/MagicBytesChecker.cpp#L45-L63 eval "$(r2 "$src" -nn -Nqc "p8j 3 @ 8" | @@ -19,16 +23,15 @@ unpack() { # check AppImage signature if [[ "$appimageSignature" != "AI" ]]; then echo "Not an appimage." - exit -1 + exit fi case "$appimageType" in - 1) echo "Uncompress $(basename "$src") of Type: $appimageType." + 1 ) echo "Uncompress $(basename "$src") of type $appimageType." mkdir "$out" pv "$src" | bsdtar -x -C "$out" -f - ;; - - 2) echo "Uncompress $(basename "$src") of Type: $appimageType." + 2) # This method avoid issues with non executable appimages, # non-native packer, packer patching and squashfs-root destination prefix. @@ -37,6 +40,7 @@ unpack() { offset=$(r2 "$src" -nn -Nqc "pfj.elf_header @ 0" |\ jq 'map({(.name): .value}) | add | .shoff + (.shnum * .shentsize)') + echo "Uncompress $(basename "$src") of type $appimageType @ offset $offset." unsquashfs -q -d "$out" -o "$offset" "$src" chmod go-w "$out" ;; @@ -52,26 +56,25 @@ unpack() { apprun() { eval "$(rahash2 "$APPIMAGE" -j | jq -r '.[] | @sh "SHA256=\(.hash)"')" - echo sha256 = \"$SHA256\"\; + echo sha256 = \""$SHA256"\"\; export APPDIR="${XDG_CACHE_HOME:-$HOME/.cache}/appimage-run/$SHA256" #compatibility if [ -x "$APPDIR/squashfs-root" ]; then APPDIR="$APPDIR/squashfs-root"; fi if [ ! -x "$APPDIR" ]; then - mkdir -p $(dirname "$APPDIR") + mkdir -p "$(dirname "$APPDIR")" unpack "$APPIMAGE" "$APPDIR" + else echo "$(basename "$APPIMAGE")" installed in "$APPDIR" fi - echo $(basename "$APPIMAGE") installed in "$APPDIR" - export PATH="$PATH:$PWD/usr/bin" - wrap + wrap "$@" } wrap() { - cd "$APPDIR" + cd "$APPDIR" || exit # quite same in appimageTools export APPIMAGE_SILENT_INSTALL=1 @@ -121,9 +124,11 @@ if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then fi if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then - apprun + apprun "$@" + exit fi if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then - wrap + wrap "$@" + exit fi From 95dc1ef1f0d5da42f3b92d9af00cbb0179cb5ecf Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Sun, 8 Mar 2020 13:53:48 +0100 Subject: [PATCH 4/6] appimageTools: fix appimage-exec.sh passing arguments --- pkgs/build-support/appimage/appimage-exec.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/appimage/appimage-exec.sh b/pkgs/build-support/appimage/appimage-exec.sh index b209ce983e5..ee952db0fd7 100755 --- a/pkgs/build-support/appimage/appimage-exec.sh +++ b/pkgs/build-support/appimage/appimage-exec.sh @@ -3,7 +3,6 @@ if [ -n "$DEBUG" ] ; then set -x fi -#export PATH=@path@ PATH="@path@:$PATH" #DEBUG=0 @@ -69,7 +68,6 @@ apprun() { fi export PATH="$PATH:$PWD/usr/bin" - wrap "$@" } wrap() { @@ -98,6 +96,7 @@ while getopts ":a:d:xrw" option; do a) #AppImage file # why realpath? APPIMAGE="$(realpath "${OPTARG}")" + break ;; d) #appimage Directory export APPDIR=${OPTARG} @@ -124,7 +123,8 @@ if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then fi if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then - apprun "$@" + apprun + wrap "$@" exit fi From 49e7871196ea43f6b8b6c81801f632f57ab892de Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Sun, 8 Mar 2020 17:55:43 +0100 Subject: [PATCH 5/6] appimageTools: wrapType1 = wrapType2; --- pkgs/build-support/appimage/default.nix | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pkgs/build-support/appimage/default.nix b/pkgs/build-support/appimage/default.nix index 4df0f15d84d..eb9a2a5ee08 100644 --- a/pkgs/build-support/appimage/default.nix +++ b/pkgs/build-support/appimage/default.nix @@ -20,8 +20,7 @@ rec { # for compatibility, deprecated extractType1 = extract; extractType2 = extract; - #wrapType2 = wrapAppImage; - #wrapType1 = wrapAppImage; + wrapType1 = wrapType2; wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv (defaultFhsEnvArgs // { inherit name; @@ -32,14 +31,9 @@ rec { runScript = "appimage-exec.sh -w -d ${src}"; } // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage)))); - wrapType1 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { - inherit name extraPkgs; - src = extractType1 { inherit name src; }; - }); - wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { inherit name extraPkgs; - src = extractType2 { inherit name src; }; + src = extract { inherit name src; }; }); defaultFhsEnvArgs = { From a3df64c8a7bd5e3e26c1cf469680d563c42103be Mon Sep 17 00:00:00 2001 From: Bignaux Ronan Date: Sun, 8 Mar 2020 20:34:23 +0100 Subject: [PATCH 6/6] appimage-exec.sh: simplify and improve getopts options --- pkgs/build-support/appimage/appimage-exec.sh | 48 +++++++++++-------- pkgs/build-support/appimage/default.nix | 4 +- .../appimage-run/default.nix | 4 +- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pkgs/build-support/appimage/appimage-exec.sh b/pkgs/build-support/appimage/appimage-exec.sh index ee952db0fd7..1273effe5fe 100755 --- a/pkgs/build-support/appimage/appimage-exec.sh +++ b/pkgs/build-support/appimage/appimage-exec.sh @@ -4,6 +4,8 @@ if [ -n "$DEBUG" ] ; then fi PATH="@path@:$PATH" +apprun_opt=true + #DEBUG=0 # src : AppImage @@ -84,32 +86,35 @@ wrap() { } usage() { - echo "Usage: appimage-run [appimage-run options] [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." + cat < [AppImage options] + +-h show this message +-d debug mode +-x : extract appimage in the directory then exit. +-w : run uncompressed appimage directory (used in appimageTools) + +[AppImage options]: Options are passed on to the appimage. +If you want to execute a custom command in the appimage's environment, set the APPIMAGE_DEBUG_EXEC environment variable. + +EOF exit 1 } -while getopts ":a:d:xrw" option; do +while getopts "x:w:dh" option; do case "${option}" in - a) #AppImage file - # why realpath? - APPIMAGE="$(realpath "${OPTARG}")" - break - ;; - d) #appimage Directory - export APPDIR=${OPTARG} + d) set -x ;; x) # eXtract unpack_opt=true - ;; - r) # appimage-Run - apprun_opt=true + APPDIR=${OPTARG} ;; w) # WrapAppImage + export APPDIR=${OPTARG} wrap_opt=true ;; + h) usage + ;; *) usage ;; @@ -117,6 +122,14 @@ while getopts ":a:d:xrw" option; do done shift $((OPTIND-1)) +if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then + wrap "$@" + exit +else + APPIMAGE="$(realpath "$1")" || usage + shift +fi + if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then unpack "$APPIMAGE" "$APPDIR" exit @@ -127,8 +140,3 @@ if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then wrap "$@" exit fi - -if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then - wrap "$@" - exit -fi diff --git a/pkgs/build-support/appimage/default.nix b/pkgs/build-support/appimage/default.nix index eb9a2a5ee08..993032c5601 100644 --- a/pkgs/build-support/appimage/default.nix +++ b/pkgs/build-support/appimage/default.nix @@ -14,7 +14,7 @@ rec { extract = { name, src }: runCommand "${name}-extracted" { buildInputs = [ appimage-exec ]; } '' - appimage-exec.sh -x -d $out -a ${src} + appimage-exec.sh -x $out ${src} ''; # for compatibility, deprecated @@ -28,7 +28,7 @@ rec { targetPkgs = pkgs: [ appimage-exec ] ++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs; - runScript = "appimage-exec.sh -w -d ${src}"; + runScript = "appimage-exec.sh -w ${src}"; } // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage)))); wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { diff --git a/pkgs/tools/package-management/appimage-run/default.nix b/pkgs/tools/package-management/appimage-run/default.nix index 37d1afe2843..3bc59f2ad14 100644 --- a/pkgs/tools/package-management/appimage-run/default.nix +++ b/pkgs/tools/package-management/appimage-run/default.nix @@ -1,13 +1,11 @@ { appimageTools, buildFHSUserEnv, extraPkgs ? pkgs: [] }: let - fhsArgs = appimageTools.defaultFhsEnvArgs; - in buildFHSUserEnv (fhsArgs // { name = "appimage-run"; targetPkgs = pkgs: [ appimageTools.appimage-exec ] ++ fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs; - runScript = "appimage-exec.sh -r -a"; + runScript = "appimage-exec.sh"; })