From 0a90c749826080cdbd813f4f17d7ef9dbe8caaca Mon Sep 17 00:00:00 2001 From: Pierre Hyvernat Date: Wed, 20 Nov 2024 16:24:13 +0100 Subject: [PATCH] fix minor problem in the handling of options and parameters options -A and -P have been replaced by -M anonymous and -M passport as well --- i18n/en.po | 4 + i18n/fr.po | 4 + i18n/it.po | 4 + i18n/start-full-help/en.txt | 9 ++- i18n/start-full-help/fr.txt | 9 ++- i18n/start-full-help/it.txt | 9 ++- i18n/template.pot | 4 + lib/header.sh | 153 +++++++++++++++++++++--------------- start.sh | 22 ++++-- utils/archive.sh | 23 ++++-- 10 files changed, 152 insertions(+), 89 deletions(-) diff --git a/i18n/en.po b/i18n/en.po index 8e948fea..e80105cd 100644 --- a/i18n/en.po +++ b/i18n/en.po @@ -100,6 +100,10 @@ msgstr "Error: a least one base function is not working properly.\n" msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)" msgstr "Error: couldn't get mission number $MISSION_NB (from $fn_name)" +#, sh-format +msgid "Error: invalid mode (option -M): '-$OPTARG'" +msgstr "Error: invalid mode (option -M): '-$OPTARG'" + #, sh-format msgid "Error: invalid option: '-$OPTARG'" msgstr "Error: invalid option: '-$OPTARG'" diff --git a/i18n/fr.po b/i18n/fr.po index 8ca74d71..b2edc6b7 100644 --- a/i18n/fr.po +++ b/i18n/fr.po @@ -104,6 +104,10 @@ msgstr "Erreur : au moins une fonction de base ne marche pas correctement.\n" msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)" msgstr "Error : mission '$MISSION_NB' introuvable (dans $fn_name)" +#, sh-format +msgid "Error: invalid mode (option -M): '-$OPTARG'" +msgstr "Erreur : mode invalide (option -M) : '-$OPTARG'" + #, sh-format msgid "Error: invalid option: '-$OPTARG'" msgstr "Erreur : option invalide: '-$OPTARG'" diff --git a/i18n/it.po b/i18n/it.po index a7b514ff..e74181cb 100644 --- a/i18n/it.po +++ b/i18n/it.po @@ -114,6 +114,10 @@ msgstr "Errore: almeno una delle funzioni base non funziona correttamente.\n" msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)" msgstr "Errore: non é stato possibile ottenere il numero $MISSION_NB (da $fn_name)" +#, sh-format +msgid "Error: invalid mode (option -M): '-$OPTARG'" +msgstr "" + #, sh-format msgid "Error: invalid option: '-$OPTARG'" msgstr "Errore: opzione non valida: '-$OPTARG'" diff --git a/i18n/start-full-help/en.txt b/i18n/start-full-help/en.txt index 199498c3..eb17b4bf 100644 --- a/i18n/start-full-help/en.txt +++ b/i18n/start-full-help/en.txt @@ -14,10 +14,11 @@ options: -V display version -I show list of available index files - -P passport mode: ask for name / emails of player - -A anonymous mode - -d debug mode - -D verbose debug mode + -M passport passport mode: ask for name / emails of player + -M anonymous anonymous mode + -M debug debug mode + -d alias for -M debug + -D verbose debug mode -C continue current game (if relevant) -R reset game diff --git a/i18n/start-full-help/fr.txt b/i18n/start-full-help/fr.txt index 74e7d796..997af99f 100644 --- a/i18n/start-full-help/fr.txt +++ b/i18n/start-full-help/fr.txt @@ -15,10 +15,11 @@ options : -V affiche la version -I affiche la liste des fichier index disponibles - -P mode passeport : demande le nom / email du joueur - -D mode debug - -v lecture "verbeuse" des scripts de mission (seulement en mode debug) - -A mode anonyme + -M passport mode passeport : demande le nom / email du joueur + -M anonymous mode anonyme + -M debug mode debug + -d alias pour -M debug + -D mode debug verbeux -C continue la partie en cours (si pertinent) -R recommence une partie du début diff --git a/i18n/start-full-help/it.txt b/i18n/start-full-help/it.txt index 3762f7e4..ba5a5939 100644 --- a/i18n/start-full-help/it.txt +++ b/i18n/start-full-help/it.txt @@ -4,10 +4,11 @@ options: -V mostra versione -I ... - -P modalitá passaporto: chiede il nome/email del giocatore - -A modalitá anonima - -d modalitá debug - -D modalitá debug verbosa + -M passport modalitá passaporto: chiede il nome/email del giocatore + -M anonymous modalitá anonima + -M debug modalitá debug + -d modalitá debug + -D modalitá debug verbosa -C continua la partita corrente (se rilevante) -R reimposta la partita diff --git a/i18n/template.pot b/i18n/template.pot index e62365a8..5ef31a93 100644 --- a/i18n/template.pot +++ b/i18n/template.pot @@ -98,6 +98,10 @@ msgstr "" msgid "Error: couldn't get mission number $MISSION_NB (from $fn_name)" msgstr "" +#, sh-format +msgid "Error: invalid mode (option -M): '-$OPTARG'" +msgstr "" + #, sh-format msgid "Error: invalid option: '-$OPTARG'" msgstr "" diff --git a/lib/header.sh b/lib/header.sh index d1179bb0..c3f5da4e 100644 --- a/lib/header.sh +++ b/lib/header.sh @@ -34,75 +34,98 @@ GSH_EXEC_DIR=$(cd "$GSH_EXEC_DIR"; pwd -P) # just in case GSH_EXEC_DIR=${GSH_EXEC_DIR:-.} -while getopts ":hHInPdDACRXUVqGL:KBZc:FS:" opt +CHECK_SAVEFILE="true" + +while getopts ":hHIndDM:CRXUVqL:KBZc:FS:" opt do - case "$opt" in - V) - echo "Gameshell $GSH_VERSION" - if [ -n "$GSH_LAST_CHECKED_MISSION" ] + 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 + ;; + 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 - echo "saved game: [mission $GSH_LAST_CHECKED_MISSION] OK" + 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 - exit 0 - ;; - U) - TARGET="$GSH_EXEC_DIR/gameshell.sh" - TMPFILE="$GSH_EXEC_DIR/gameshell.sh$$" - if command -v wget >/dev/null + elif command -v curl >/dev/null + then + if curl -fo "$TMPFILE" https://github.com/phyver/GameShell/releases/download/latest/gameshell.sh 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 + 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 - ;; - X) - GSH_EXTRACT="true" - ;; - K) - KEEP_DIR="true" - ;; - F) - GSH_FORCE="true" - ;; - h | H | I) - # used to avoid checking for more recent files - GSH_HELP="true" - ;; - '?') - echo "$0: invalid option '-$OPTARG'" >&2 - echo "use $0 -h to get the list of available options" >&2 - exit 1 - ;; - :) - echo "$0: missing parameter for option '-$OPTARG'" >&2 - echo "use $0 -h to get the list of available options" >&2 - exit 1 - ;; - *) - # ignore other options, they will be passed to start.sh - ;; - esac + fi + ;; + X) + GSH_EXTRACT="true" + ;; + K) + KEEP_DIR="true" + ;; + F) + GSH_FORCE="true" + ;; + h | H | I) + # used to avoid checking for more recent files + CHECK_SAVEFILE="false" + ;; + + S) + # the next cases are used to check validity of parameters, to avoid + # checking for savefiles the error message will be displayed with + # appropriate language by start.sh + case "$OPTARG" in + "index" | "simple" | "overwrite") + : + ;; + *) + CHECK_SAVEFILE="false" + ;; + esac + ;; + M) + case "$OPTARG" in + passport | anonymous | debug) + : + ;; + *) + CHECK_SAVEFILE="false" + ;; + esac + ;; + + '?') + CHECK_SAVEFILE="false" + ;; + :) + CHECK_SAVEFILE="false" + ;; + *) + # ignore other options, they will be passed to start.sh + ;; + esac done @@ -115,7 +138,7 @@ GSH_NAME=${GSH_NAME%-save*} GSH_NAME=$(basename "$GSH_NAME") -if [ "$GSH_HELP" != "true" ] && [ "$GSH_FORCE" != "true" ] +if [ "$CHECK_SAVEFILE" = "true" ] && [ "$GSH_FORCE" != "true" ] then LAST_SAVEFILE=$(ls "$GSH_EXEC_DIR/$GSH_NAME-save"*".$EXT" 2>/dev/null | sort | tail -n 1) diff --git a/start.sh b/start.sh index 96948cb3..bc6638cd 100755 --- a/start.sh +++ b/start.sh @@ -49,7 +49,7 @@ GSH_EXPLICIT_LANGUAGE="false" # 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="" -while getopts ":hHInPdDACRXUVqL:KBZc:FS:" opt +while getopts ":hHIndDM:CRXUVqL:KBZc:FS:" opt do case $opt in S) @@ -79,8 +79,21 @@ do n) GSH_COLOR="" ;; - P) - GSH_MODE="PASSPORT" + M) + case "$OPTARG" in + passport) + GSH_MODE="PASSPORT" + ;; + anonymous) + GSH_MODE="ANONYMOUS" + ;; + debug) + GSH_MODE="debug" + ;; + *) + echo "$(eval_gettext "Error: invalid mode (option -M): '-\$OPTARG'")" >&2 + exit 1 + esac ;; d) GSH_MODE="DEBUG" @@ -92,9 +105,6 @@ do q) export GSH_QUIET_INTRO="true" ;; - A) - GSH_MODE="ANONYMOUS" - ;; C) RESET="FALSE" ;; diff --git a/utils/archive.sh b/utils/archive.sh index d1734ae4..8443b33b 100755 --- a/utils/archive.sh +++ b/utils/archive.sh @@ -12,8 +12,8 @@ options: -h this message -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 + -M passport use the "passport mode" by default when running GameShell + -M anonymous use the "anonymous mode" by default when running GameShell -L LANGS only keep the given languages (ex: -L 'en*,fr') if LANGS is empty (-L ""), only keep english as a language, not generating any ".mo" file and not using gettext @@ -67,7 +67,7 @@ VERBOSE="" INDEX_FILES="" -while getopts "hp:N:atPzL:vS:p:I:" opt +while getopts "hp:N:atM:zL:vS:p:I:" opt do case $opt in h) @@ -94,7 +94,7 @@ do I) if [ "$OPTARG" = "default.idx" ] then - echo "Warning: ignoring additional index file with name '$OPTARG'" + echo "Warning: ignoring additional index file with name '$OPTARG'" >&2 else INDEX_FILES="$INDEX_FILES:$OPTARG" fi @@ -105,8 +105,19 @@ do t) KEEP_TEST=1 ;; - P) - DEFAULT_MODE="PASSPORT" + M) + case "$OPTARG" in + passport) + DEFAULT_MODE="PASSPORT" + ;; + anonymous) + DEFAULT_MODE="ANONYMOUS" + ;; + *) + echo "Error: default mode (option -M) can only be 'anonymous' or 'passport' (got '$OPTARG')" >&2 + exit 1 + ;; + esac ;; z) KEEP_TGZ=1