diff --git a/i18n/start-help/en.txt b/i18n/start-help/en.txt index 0904d250..2e52391a 100644 --- a/i18n/start-help/en.txt +++ b/i18n/start-help/en.txt @@ -16,12 +16,12 @@ options: On non GNU systems, set the variable LC_MESSAGES to a valid locale. - --simple-savefiles + -S simple the savefile is obtained by adding a "-save" suffix, each savefile overwrites the previous one - --index-savefiles + -S index savefiles are numbered so that all savefiles are kept - --overwrite-savefiles + -S overwrite the savefile overwrite the initial GameShell file (you can use option -R to start a new game from the start) diff --git a/i18n/start-help/fr.txt b/i18n/start-help/fr.txt index 98cfa676..e7ab178e 100644 --- a/i18n/start-help/fr.txt +++ b/i18n/start-help/fr.txt @@ -17,13 +17,13 @@ options : Pour les systèmes non GNU, initialisez la variable LC_MESSAGES avec une locale valide. - --simple-savefiles + -S simple le fichier de sauvegarde est obtenu en ajoutant un suffix "-save", chaque fichier de sauvegarde remplace le précédent - --index-savefiles + -S index les fichiers de sauvegarde sont numérotés pour que toutes les sauvegardes soient conservées - --overwrite-savefiles + -S overwrite le fichier de sauvegarde remplace l'instance initial de GameShell (on peut utiliser l'option -R pour lancer une partie à partir du début) diff --git a/i18n/start-help/it.txt b/i18n/start-help/it.txt index bc5355b9..000ea47e 100644 --- a/i18n/start-help/it.txt +++ b/i18n/start-help/it.txt @@ -16,12 +16,12 @@ options: Su sistemi non GNU, imposta la variabile LC_MESSAGES per un "locale" valido. - --simple-savefiles + -S simple il file di salvataggio è generato con un suffiso "-save", ogni salvataggio sovrascrive il precedente - --index-savefiles + -S index i salvataggi sono numerati così sono tutti conservati - --overwrite-savefiles + -S overwrite il salvataggio sovrascrive il file iniziale di GameShell (puoi utilizzare l'opzione -R per avviare un nuovo gioco dall'inizio) diff --git a/lib/header.sh b/lib/header.sh index 9d77dfac..37fee62a 100644 --- a/lib/header.sh +++ b/lib/header.sh @@ -34,61 +34,65 @@ GSH_EXEC_DIR=$(cd "$GSH_EXEC_DIR"; pwd -P) # just in case GSH_EXEC_DIR=${GSH_EXEC_DIR:-.} -for arg in "$@" +while getopts "VUXKFh" opt do - if [ "$arg" = "-V" ] - then - echo "Gameshell $GSH_VERSION" - if [ -n "$GSH_LAST_CHECKED_MISSION" ] - then - echo "saved game: [mission $GSH_LAST_CHECKED_MISSION] OK" - fi - exit 0 - elif [ "$arg" = "-U" ] - then - TARGET="$GSH_EXEC_DIR/gameshell.sh" - TMPFILE="$GSH_EXEC_DIR/gameshell.sh$$" - if command -v wget >/dev/null - then - if wget -O "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh - then - mv "$TMPFILE" "$TARGET" - chmod +x "$TARGET" - echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh" - exit 0 - else - rm -f "$TMPFILE" - echo "Error: couldn't download or save the latest version of GameShell." >&2 - exit 1 - fi - elif command -v curl >/dev/null - then - if curl -fo "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh - then - mv "$TMPFILE" "$TARGET" - chmod +x "$TARGET" - echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh" + case "$opt" in + V) + echo "Gameshell $GSH_VERSION" + if [ -n "$GSH_LAST_CHECKED_MISSION" ] + then + echo "saved game: [mission $GSH_LAST_CHECKED_MISSION] OK" + fi exit 0 - else - rm -f "$TMPFILE" - echo "Error: couldn't download or save the latest version of GameShell." >&2 - exit 1 - fi - fi - elif [ "$arg" = "-X" ] - then - GSH_EXTRACT="true" - elif [ "$arg" = "-K" ] - then - KEEP_DIR="true" - elif [ "$arg" = "-F" ] - then - GSH_FORCE="true" - elif [ "$arg" = "-h" ] - then - # used to avoid checking for more recent files - GSH_HELP="true" - fi + ;; + U) + TARGET="$GSH_EXEC_DIR/gameshell.sh" + TMPFILE="$GSH_EXEC_DIR/gameshell.sh$$" + if command -v wget >/dev/null + then + if wget -O "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh + then + mv "$TMPFILE" "$TARGET" + chmod +x "$TARGET" + echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh" + exit 0 + else + rm -f "$TMPFILE" + echo "Error: couldn't download or save the latest version of GameShell." >&2 + exit 1 + fi + elif command -v curl >/dev/null + then + if curl -fo "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh + then + mv "$TMPFILE" "$TARGET" + chmod +x "$TARGET" + echo "Latest version of GameShell downloaded to $GSH_EXEC_DIR/gameshell.sh" + exit 0 + else + rm -f "$TMPFILE" + echo "Error: couldn't download or save the latest version of GameShell." >&2 + exit 1 + fi + fi + ;; + X) + GSH_EXTRACT="true" + ;; + K) + KEEP_DIR="true" + ;; + F) + GSH_FORCE="true" + ;; + h) + # used to avoid checking for more recent files + GSH_HELP="true" + ;; + *) + # ignore other options, they will be passed to start.sh + ;; + esac done diff --git a/start.sh b/start.sh index 23f6f11f..9c981905 100755 --- a/start.sh +++ b/start.sh @@ -37,28 +37,19 @@ GSH_MODE="ANONYMOUS" # if GSH_NO_GETTEXT is non-empty, gettext won't be used anywhere, the only language will thus be English # export GSH_NO_GETTEXT=1 # DO NOT CHANGE OR REMOVE THIS LINE, it is used by utils/archive.sh RESET="" -# hack to parse long options --index-savefiles --overwrite-savefiles --simple-savefiles -# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options -_long_option=0 -while getopts ":hnPdDACRXUVqGL:KBZc:F-:" opt +while getopts "hnPdDACRXUVqGL:KBZc:FS:" opt do - if [ "$opt" = "-" ] - then - opt="${OPTARG%%=*}" # extract long option name - OPTARG="${OPTARG#$opt}" # extract long option argument (may be empty) - OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` - _long_option=1 - fi - case $opt in - index-savefiles) - GSH_SAVEFILE_MODE=index - ;; - simple-savefiles) - GSH_SAVEFILE_MODE=simple - ;; - overwrite-savefiles) - GSH_SAVEFILE_MODE=overwrite + S) + case "$OPTARG" in + "index" | "simple" | "overwrite") + GSH_SAVEFILE_MODE=$OPTARG + ;; + *) + echo "$(gettext "Error: save mode can only be 'index', 'simple' or 'overwrite'")" >&2 + exit 1 + ;; + esac ;; h) display_help diff --git a/utils/archive.sh b/utils/archive.sh index 61597f97..9781601f 100755 --- a/utils/archive.sh +++ b/utils/archive.sh @@ -11,7 +11,7 @@ create a GameShell standalone archive options: -h this message - --password=... choose password for admin commands + -p ... choose password for admin commands -P use the "passport mode" by default when running GameShell -A use the "anonymous mode" by default when running GameShell -L LANGS only keep the given languages (ex: -L 'en*,fr') @@ -20,9 +20,9 @@ options: -N ... name of the archive / top directory (default: "gameshell") - --simple-savefiles - --index-savefiles - --overwrite-savefiles + -S simple + -S index + -S overwrite choose default savefile mode -a keep 'auto.sh' scripts for missions that have one @@ -62,38 +62,29 @@ KEEP_PO=0 # this is set to 1 if we generate .mo files. Setting it to 1 here LANGUAGES="" VERBOSE= -# hack to parse long option --password -# cf https://stackoverflow.com/questions/402377/using-getopts-to-process-long-and-short-command-line-options -_long_option=0 -while getopts ":hp:N:atPzL:Ev-:" opt +while getopts "hp:N:atPzL:EvS:p:" opt do - if [ "$opt" = "-" ] - then - opt="${OPTARG%%=*}" # extract long option name - OPTARG="${OPTARG#"$opt"}" # extract long option argument (may be empty) - OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` - _long_option=1 - fi - case $opt in h) display_help exit 0; ;; - password) + p) ADMIN_PASSWD=$OPTARG ;; N) NAME=$OPTARG ;; - index-savefiles) - GSH_SAVEFILE_MODE=index - ;; - simple-savefiles) - GSH_SAVEFILE_MODE=simple - ;; - overwrite-savefiles) - GSH_SAVEFILE_MODE=overwrite + S) + case "$OPTARG" in + "index" | "simple" | "overwrite") + GSH_SAVEFILE_MODE=$OPTARG + ;; + *) + echo "Error: save mode can only be 'index', 'simple' or 'overwrite'" >&2 + exit 1 + ;; + esac ;; a) KEEP_AUTO=1