From 73eeea841a3e44497e778ffc227c243df8f224fa Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 2 Apr 2025 13:37:12 +0200 Subject: [PATCH] Improve borgplom. --- testing/home/desktop/.local/bin/borgplom | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/testing/home/desktop/.local/bin/borgplom b/testing/home/desktop/.local/bin/borgplom index 6dabcc0..e18ba76 100755 --- a/testing/home/desktop/.local/bin/borgplom +++ b/testing/home/desktop/.local/bin/borgplom @@ -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 -- 2.30.2