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"
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
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"
}
cmd_orgpull() {
+ _check_args_beyond 0 "$@"
_NAME_ARCHIVE=orgdir
# determine server and repo
# 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