summary refs log tree commit diff
path: root/pkgs
diff options
context:
space:
mode:
authorBignaux Ronan <ronan@aimao.org>2020-03-08 20:34:23 +0100
committerBignaux Ronan <ronan@aimao.org>2020-03-08 20:34:23 +0100
commita3df64c8a7bd5e3e26c1cf469680d563c42103be (patch)
treeb1668e52044c0ca84b5949004dadb92eda464c52 /pkgs
parent49e7871196ea43f6b8b6c81801f632f57ab892de (diff)
downloadnixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.tar
nixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.tar.gz
nixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.tar.bz2
nixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.tar.lz
nixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.tar.xz
nixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.tar.zst
nixpkgs-a3df64c8a7bd5e3e26c1cf469680d563c42103be.zip
appimage-exec.sh: simplify and improve getopts options
Diffstat (limited to 'pkgs')
-rwxr-xr-xpkgs/build-support/appimage/appimage-exec.sh48
-rw-r--r--pkgs/build-support/appimage/default.nix4
-rw-r--r--pkgs/tools/package-management/appimage-run/default.nix4
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> [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 <<EOF
+Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]
+
+-h      show this message
+-d      debug mode
+-x      <directory> : extract appimage in the directory then exit.
+-w      <directory> : 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";
 })