home · contact · privacy
Improve borgplom.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 2 Apr 2025 11:58:49 +0000 (13:58 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 2 Apr 2025 11:58:49 +0000 (13:58 +0200)
testing/home/desktop/.local/bin/borgplom

index f94d64b03b0e0a54ecec0cd629855b4a9f243f23..40e0466fb00ca6a2b6178dc7ced7118c76f4c776 100755 (executable)
@@ -22,6 +22,8 @@ print_usage() {
     echo "  ${CMD_ORGPULL}   pull most recent org directory available in repos"
 }
 
+# exits
+
 error_exit() {
     echo "${PREFIX_ABORTING}$1"
     exit 1
@@ -33,39 +35,33 @@ error_exit_with_usage() {
     exit 1
 }
 
-check_args_beyond() {
-    _CMD="$1"
-    shift 1
-    if [ "$#" -gt 0 ]; then
-        _MSG="unexpected arguments beyond command '${_CMD}': $@"
-        error_exit "${_MSG}"
-    fi
-}
+# commands beyond print_usage
 
-_path_repo_location() {
-    echo "${PATH_BORG_CONF_SECURITY}/${1}/location"
-}
+_path_repo_location() { echo "${PATH_BORG_CONF_SECURITY}/${1}/location" }
 
 cmd_keys() {
     _PATH_CONF_KEYS="${PATH_BORG_CONF}/keys"
-    echo "Known keys as per ${PATH_BORG_CONF}:"
-    if [ ! -d "${_PATH_CONF_KEYS}" ]; then
-       echo "(none, since no ${_PATH_CONF_KEYS})"
+    _exit_ok() {
+       echo "(none, since directory ${1}."
        exit 0
+    }
+    echo "Known keys, as per ${_PATH_BORG_CONF_KEYS}:"
+    if [ ! -d "${_PATH_CONF_KEYS}" ]; then
+       exit_ok "non-existant"
     fi
     _KEYFILES="$(ls -1 ${_PATH_CONF_KEYS})"
     if [ -z "${_KEYFILES}" ]; then
-       echo "(none, directory empty)"
-       exit 0
+       exit_ok "empty"
     fi
     echo "${_KEYFILES}" | while read _FILENAME; do
         _KEY_ID=$(head -1 "${_PATH_CONF_KEYS}/${_FILENAME}" | cut -d' ' -f2)
-        _LOCATION=?
+        printf "${KEY_ID} ${_FILENAME} "
        _PATH_LOC="$(cat $(_path_repo_location ${_KEY_ID}))"
         if [ -f "${_PATH_LOC}" ]; then
-            _LOCATION="$(cat ${_PATH_LOC})"
+            printf '%s\n' "$(cat ${_PATH_LOC})"
+        else
+            printf '?\n'
         fi
-       echo "${_KEY_ID} ${_FILENAME} ${_LOCATION}"
     done
 }
 
@@ -114,6 +110,17 @@ cmd_orgpull() {
     borg extract --verbose "${_REPO}::${_ARCHIVE}"
 }
 
+# parse args to execution
+
+check_args_beyond() {
+    _CMD="$1"
+    shift 1
+    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_HELP}" ]; then