appimage-exec.sh: simplify and improve getopts options

This commit is contained in:
Bignaux Ronan 2020-03-08 20:34:23 +01:00
parent 49e7871196
commit a3df64c8a7
3 changed files with 31 additions and 25 deletions

View File

@ -4,6 +4,8 @@ if [ -n "$DEBUG" ] ; then
fi fi
PATH="@path@:$PATH" PATH="@path@:$PATH"
apprun_opt=true
#DEBUG=0 #DEBUG=0
# src : AppImage # src : AppImage
@ -84,32 +86,35 @@ wrap() {
} }
usage() { usage() {
echo "Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]"; cat <<EOF
echo Usage: appimage-run [appimage-run options] <AppImage> [AppImage options]
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." -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 exit 1
} }
while getopts ":a:d:xrw" option; do while getopts "x:w:dh" option; do
case "${option}" in case "${option}" in
a) #AppImage file d) set -x
# why realpath?
APPIMAGE="$(realpath "${OPTARG}")"
break
;;
d) #appimage Directory
export APPDIR=${OPTARG}
;; ;;
x) # eXtract x) # eXtract
unpack_opt=true unpack_opt=true
;; APPDIR=${OPTARG}
r) # appimage-Run
apprun_opt=true
;; ;;
w) # WrapAppImage w) # WrapAppImage
export APPDIR=${OPTARG}
wrap_opt=true wrap_opt=true
;; ;;
h) usage
;;
*) *)
usage usage
;; ;;
@ -117,6 +122,14 @@ while getopts ":a:d:xrw" option; do
done done
shift $((OPTIND-1)) 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 if [[ $unpack_opt = true ]] && [[ -f "$APPIMAGE" ]]; then
unpack "$APPIMAGE" "$APPDIR" unpack "$APPIMAGE" "$APPDIR"
exit exit
@ -127,8 +140,3 @@ if [[ $apprun_opt = true ]] && [[ -f "$APPIMAGE" ]]; then
wrap "$@" wrap "$@"
exit exit
fi fi
if [[ $wrap_opt = true ]] && [[ -d "$APPDIR" ]]; then
wrap "$@"
exit
fi

View File

@ -14,7 +14,7 @@ rec {
extract = { name, src }: runCommand "${name}-extracted" { extract = { name, src }: runCommand "${name}-extracted" {
buildInputs = [ appimage-exec ]; buildInputs = [ appimage-exec ];
} '' } ''
appimage-exec.sh -x -d $out -a ${src} appimage-exec.sh -x $out ${src}
''; '';
# for compatibility, deprecated # for compatibility, deprecated
@ -28,7 +28,7 @@ rec {
targetPkgs = pkgs: [ appimage-exec ] targetPkgs = pkgs: [ appimage-exec ]
++ defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs; ++ 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)))); } // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage))));
wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // {

View File

@ -1,13 +1,11 @@
{ appimageTools, buildFHSUserEnv, extraPkgs ? pkgs: [] }: { appimageTools, buildFHSUserEnv, extraPkgs ? pkgs: [] }:
let let
fhsArgs = appimageTools.defaultFhsEnvArgs; fhsArgs = appimageTools.defaultFhsEnvArgs;
in buildFHSUserEnv (fhsArgs // { in buildFHSUserEnv (fhsArgs // {
name = "appimage-run"; name = "appimage-run";
targetPkgs = pkgs: [ appimageTools.appimage-exec ] targetPkgs = pkgs: [ appimageTools.appimage-exec ]
++ fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs; ++ fhsArgs.targetPkgs pkgs ++ extraPkgs pkgs;
runScript = "appimage-exec.sh -r -a"; runScript = "appimage-exec.sh";
}) })