home · contact · privacy
Fix.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 2 Apr 2025 21:07:12 +0000 (23:07 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 2 Apr 2025 21:07:12 +0000 (23:07 +0200)
testing/home/desktop/.local/bin/borgplom

index a52fcfec8673888ecd476831325d7c715ec13965..2fa1dbb4108beb8efb8eb33655d4c59623cd1d2e 100755 (executable)
@@ -6,10 +6,6 @@ cd $(dirname "$0")
 . lib/path_tmp_timestamped
 
 BIN_NAME="$(basename $0)"
-CMD_CLAIM=claim
-CMD_HELP=help
-CMD_KEYS=keys
-CMD_ORGPULL=orgpull
 
 PATH_BORG_CONF_SECURITY="${PATH_BORG_CONF}/security"
 PATH_BORG_CONF_KEYS="${PATH_BORG_CONF}/keys"
@@ -20,10 +16,10 @@ _print_usage() {
     echo "Usage: ${BIN_NAME} COMMAND"
     echo "Wrapper around certain borgbackup usages.\n"
     echo "Available commands:\n"
-    echo "  ${CMD_CLAIM} PATH   register file of PATH as key to repo at \"$(location_from_servername SERVERNAME)\", with SERVERNAME the filename portion of PATH"
-    echo "  ${CMD_HELP}         print this help and exit"
-    echo "  ${CMD_KEYS}         list known repos in ID, key filename, and alleged location"
-    echo "  ${CMD_ORGPULL}      pull most recent org directory available in repos"
+    echo "  claim PATH   register file of PATH as key to repo at \"$(location_from_servername SERVERNAME)\", with SERVERNAME the filename portion of PATH"
+    echo "  help         print this help and exit"
+    echo "  keys         list known repos in ID, key filename, and alleged location"
+    echo "  orgpull      pull most recent org directory available in repos"
 }
 
 # exits
@@ -42,6 +38,7 @@ error_exit_with_usage() {
 }
 
 # commands
+COMMANDS='claim help keys orgpull'
 
 _check_args_beyond() {
     _N_MAX_ARGS="$1"
@@ -53,7 +50,7 @@ _check_args_beyond() {
     fi
 }
 
-CMD__claim() {
+cmd_claim() {
     _check_args_beyond 1 "$@"
     _PATH_SOURCE="$1"
     _ensure_no_overwrite_at() {
@@ -83,12 +80,12 @@ CMD__claim() {
     chmod u+rw "${_PATH_TARGET_KEY}" "${_PATH_TARGET_LOCATION}"
 }
 
-CMD__help() {
+cmd_help() {
     _check_args_beyond 0 "$@"
     _print_usage
 }
 
-CMD__keys() {
+cmd_keys() {
     _check_args_beyond 0 "$@"
     _exit_ok() {
        echo "(none, since directory ${1})"
@@ -115,7 +112,7 @@ CMD__keys() {
     done
 }
 
-CMD__orgpull() {
+cmd_orgpull() {
     _check_args_beyond 0 "$@"
     _NAME_ARCHIVE=orgdir
 
@@ -170,13 +167,13 @@ CMD__orgpull() {
 if [ "$#" -lt 1 ]; then
     error_exit_with_usage "missing command."
 fi
-CMD_FUNC="CMD__$1"
-set +e
-type "${CMD_FUNC}" > /dev/null 2>&1
-RESULT="$?"
-set -e
-if [ ! "${RESULT}" = 0 ]; then
+for CMD in COMMANDS; do
+    if [ "$1" = "${CMD}" ]; then
+       break
+    fi
+done
+if [ -z "${CMD}" ]; then
     error_exit_with_usage "unknown command: ${1}"
 fi
 shift 1
-"${CMD_FUNC}" $@
+"cmd_$1"