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

index 6dabcc0b7e05a2a7cc7e07817886ea794c9d2a6a..e18ba765132ce389e4e5a1695f90f8821d9692de 100755 (executable)
@@ -5,6 +5,8 @@ cd $(dirname "$0")
 . lib/get_passphrase
 . lib/path_tmp_timestamped
 
+PATH_BORG_CONF_SECURITY="${PATH_BORG_CONF}/security"
+
 BIN_NAME="$(basename $0)"
 CMD_HELP=help
 CMD_KEYS=keys
@@ -16,7 +18,7 @@ print_usage() {
     echo "Wrapper around certain borgbackup usages.\n"
     echo "Available commands:\n"
     echo "  ${CMD_HELP}      print this help and exit"
-    echo "  ${CMD_KEYS}      list known repo keys by ID and filename"
+    echo "  ${CMD_KEYS}      list known repos in ID, key filename, and alleged location"
     echo "  ${CMD_ORGPULL}   pull most recent org directory available in repos"
 }
 
@@ -40,27 +42,34 @@ check_args_beyond() {
     fi
 }
 
+_path_repo_location() {
+    echo "${PATH_BORG_CONF_SECURITY}/${1}/location"
+}
+
 cmd_keys() {
     _PATH_CONF_KEYS="${PATH_BORG_CONF}/keys"
     echo "Known keys (from ${PATH_BORG_CONF}):"
     ls -1 "${_PATH_CONF_KEYS}" | while read _FILENAME; do
         _KEY_ID=$(head -1 "${_PATH_CONF_KEYS}/${_FILENAME}" | cut -d' ' -f2)
-       echo "${_KEY_ID} ${_FILENAME}"
+        _LOCATION=?
+       _PATH_LOC="$(cat $(_path_repo_location ${_KEY_ID}))"
+        if [ -f "${_PATH_LOC}" ]; then
+            _LOCATION="$(cat ${_PATH_LOC})"
+        fi
+       echo "${_KEY_ID} ${_FILENAME} ${_LOCATION}"
     done
 }
 
 cmd_orgpull() {
-    _PATH_CONF_SECURITY="${PATH_BORG_CONF}/security"
-    _NAME_REPO=borg
     _NAME_ARCHIVE=orgdir
 
-    # determine server
+    # determine server and repo
     _PATH_PIPE="$(path_tmp_timestamped 'pipe')"
     mkfifo "${_PATH_PIPE}"
-    ls -1 "${_PATH_CONF_SECURITY}/" > "${_PATH_PIPE}" &
+    ls -1 "${_PATH_BORG_CONF_SECURITY}/" > "${_PATH_PIPE}" &
     while read _FILENAME; do
-        _PATH_LOC="${_PATH_CONF_SECURITY}/${_FILENAME}/location"
-        _NAME_SERVER="$(cat ${_PATH_LOC} | cut -d'/' -f3)"
+        _REPO="$(cat $(_path_repo_location ${_FILENAME}))"
+        _NAME_SERVER="$(echo ${_REPO} | cut -d'/' -f3)"
         if ping -c1 -W2 "${_NAME_SERVER}" > /dev/null 2>&1; then
             break
         else
@@ -70,7 +79,6 @@ cmd_orgpull() {
     rm "${_PATH_PIPE}"
 
     # determine passphrase and archive
-    _REPO="${_NAME_SERVER}:${_NAME_REPO}"
     echo "Checking out ${_REPO} …"
     while true; do
         if [ -z "${BORG_PASSPHRASE}" ]; then