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

index 379e934175d95d6dcf1b3902626cdb2b9a73dd60..f3695c3cde1475817567743304b95fa40339f340 100755 (executable)
@@ -14,7 +14,7 @@ CMD_ORGPULL=orgpull
 location_from_servername() { printf 'ssh://plom@%s/./borg' "$1"; }
 path_repo_location() { printf '%s' "${PATH_BORG_CONF_SECURITY}/${1}/location"; }
 
-print_usage() {
+_print_usage() {
     echo "Usage: ${BIN_NAME} COMMAND"
     echo "Wrapper around certain borgbackup usages.\n"
     echo "Available commands:\n"
@@ -35,22 +35,34 @@ error_exit() {
 
 error_exit_with_usage() {
     echo "${_PREFIX_ABORTING}$1\n"
-    print_usage
+    _print_usage
     exit 1
 }
 
-# commands beyond print_usage
+# commands
 
 PATH_BORG_CONF_SECURITY="${PATH_BORG_CONF}/security"
 PATH_BORG_CONF_KEYS="${PATH_BORG_CONF}/keys"
 
+_check_args_beyond() {
+    _N_MAX_ARGS="$1"
+    _CMD="$2"
+    shift $(calc "${_N_MAX_ARGS} + 1" | cut -f2)
+    if [ "$#" -gt 0 ]; then
+        _MSG="unexpected arguments beyond command '${_CMD}': $@"
+        error_exit "${_MSG}"
+    fi
+}
+
 cmd_claim() {
+    _check_args_beyond 1 "$@"
+    _PATH_SOURCE="$1"
     _ensure_no_overwrite_at() {
         if [ -f "$1" ]; then
             error_exit "refusing to overwrite pre-existing file at $1"
         fi
     }
-    _PATH_SOURCE="$1"
+
     _FILENAME=$(basename ${_PATH_SOURCE})
     _PATH_TARGET_KEY="${PATH_BORG_CONF_KEYS}/${_FILENAME}"
     if [ ! -f "${_PATH_SOURCE}" ]; then
@@ -72,11 +84,18 @@ cmd_claim() {
     chmod u+rw "${_PATH_TARGET_KEY}" "${_PATH_TARGET_LOCATION}"
 }
 
+cmd_help() {
+    _check_args_beyond 0 "$@"
+    _print_usage
+}
+
 cmd_keys() {
+    _check_args_beyond 0 "$@"
     _exit_ok() {
        echo "(none, since directory ${1})"
        exit 0
     }
+
     echo "Known keys, as per ${PATH_BORG_CONF_KEYS}:"
     if [ ! -d "${PATH_BORG_CONF_KEYS}" ]; then
        _exit_ok "non-existant"
@@ -98,6 +117,7 @@ cmd_keys() {
 }
 
 cmd_orgpull() {
+    _check_args_beyond 0 "$@"
     _NAME_ARCHIVE=orgdir
 
     # determine server and repo
@@ -144,30 +164,19 @@ cmd_orgpull() {
 
 # parse args to execution
 
-check_args_beyond() {
-    _N_MAX_ARGS="$1"
-    _CMD="$2"
-    shift $(calc "${_N_MAX_ARGS} + 2" | cut -f2)
-    if [ "$#" -gt 0 ]; then
-        _MSG="unexpected arguments beyond command '${_CMD}': $@"
-        error_exit "${_MSG}"
-    fi
-}
-
 if [ "$#" -lt 1 ]; then
     error_exit_with_usage "missing command."
-elif [ "$1" = "${CMD_CLAIM}" ]; then
-    check_args_beyond 1 "$@"
-    cmd_claim "$2"
-elif [ "$1" = "${CMD_HELP}" ]; then
-    check_args_beyond 0 "$@"
-    print_usage
-elif [ "$1" = "${CMD_KEYS}" ]; then
-    check_args_beyond 0 "$@"
-    cmd_keys
-elif [ "$1" = "${CMD_ORGPULL}" ]; then
-    check_args_beyond 0 "$@"
-    cmd_orgpull
+fi
+CMD="$1"
+shift 1
+if [ "${CMD}" = "${CMD_CLAIM}" ]; then
+    cmd_claim $@ 
+elif [ "${CMD}" = "${CMD_HELP}" ]; then
+    cmd_help $@
+elif [ "${CMD}" = "${CMD_KEYS}" ]; then
+    cmd_keys $@
+elif [ "${CMD}" = "${CMD_ORGPULL}" ]; then
+    cmd_orgpull $@
 else
-    error_exit_with_usage "unexpected command: ${1}"
+    error_exit_with_usage "unknown command: ${1}"
 fi