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
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

View file

@ -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 // {

View file

@ -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";
})