. lib/constants_borg # PATH_BORG_CONF
. lib/get_passphrase
. lib/path_tmp_timestamped
+. lib/print_usage
cd - > /dev/null
-BIN_NAME="$(basename $0)"
+USAGE_DESCRIPTION='Wrapper around certain borgbackup usages.'
+USAGE_LINES='COMMAND\nCOMMAND PATH'
PATH_BORG_CONF_SECURITY="${PATH_BORG_CONF}/security"
PATH_BORG_CONF_KEYS="${PATH_BORG_CONF}/keys"
location_to_servername() { echo "$1" | cut -d'/' -f3 | cut -d'@' -f2; }
path_repo_location() { printf '%s' "${PATH_BORG_CONF_SECURITY}/${1}/location"; }
-_print_usage() {
- echo "Usage: ${BIN_NAME} COMMAND"
- echo "Usage: ${BIN_NAME} COMMAND TARGET"
- echo "Wrapper around certain borgbackup usages.\n"
- echo "Available commands:\n"
-
- _var_of() { eval printf '"%s"' '"${'"${1}${2}"'}"'; }
- _build_index() {
- _ARGS="$(_var_of 'HELP_ARGS_' ${_CMD})"
- if [ ! -z "${_ARGS}" ]; then
- _ARGS=" ${_ARGS}"
- fi
- _INDEX=" ${_CMD}${_ARGS}"
- _LEN_INDEX=$(echo -n "${_INDEX}" | wc -c)
- }
- _MAX_LEN_INDEX=0
- for _CMD in ${COMMANDS}; do
- _build_index
- if [ "${_LEN_INDEX}" -gt "${_MAX_LEN_INDEX}" ]; then
- _MAX_LEN_INDEX="${_LEN_INDEX}"
- fi
- done
- for _CMD in ${COMMANDS}; do
- _build_index
- printf '%s' "${_INDEX}"
- _LEN_GAP=$(calc "${_MAX_LEN_INDEX} - ${_LEN_INDEX} + 2")
- for _ in $(seq 1 ${_LEN_GAP}); do
- printf ' '
- done
- printf '%s\n' "$(_var_of 'HELP_DESC_' ${_CMD})"
- done
-}
-
# exits
error_exit() { abort "Aborting due to $1"; }
error_exit_with_usage() { error_exit "${1}\n\n$(_print_usage)"; }
# commands
-COMMANDS='backup_keys claim help keys orgpull'
+USAGE_INDICES='backup_keys claim help keys orgpull'
_check_args_n() {
_N_MAX_ARGS="$1"
_id_from_file() { head -1 "$1" | cut -d' ' -f2; }
-HELP_ARGS_backup_keys='PATH'
-HELP_DESC_backup_keys="copy known keys to PATH/, with their repos' server names as filenames"
+USAGE_ARGS_backup_keys='PATH'
+USAGE_DESC_backup_keys="copy known keys to PATH/, with their repos' server names as filenames"
CMDFNC_backup_keys() {
_check_args_n 1 "$@"
_PATH_TARGET_DIR=$(realpath "$1")
cd - > /dev/null
}
-HELP_ARGS_claim='PATH'
-HELP_DESC_claim="register file of PATH as key to repo at \"$(servername_to_location SERVERNAME)\", with SERVERNAME the filename portion of PATH"
+USAGE_ARGS_claim='PATH'
+USAGE_DESC_claim="register file of PATH as key to repo at \"$(servername_to_location SERVERNAME)\", with SERVERNAME the filename portion of PATH"
CMDFNC_claim() {
_check_args_n 1 "$@"
_PATH_SOURCE="$1"
chmod a-rwx,u+rw "${_PATH_TARGET_KEY}" "${_PATH_TARGET_LOCATION}"
}
-HELP_DESC_help='print this help and exit'
+USAGE_DESC_help='print this help and exit'
CMDFNC_help() {
_check_args_n 0 "$@"
_print_usage
}
-HELP_DESC_keys='list known repos in ID, key filename, and alleged location'
+USAGE_DESC_keys='list known repos in ID, key filename, and alleged location'
CMDFNC_keys() {
_check_args_n 0 "$@"
_exit_ok() {
done
}
-HELP_DESC_orgpull='pull most recent org directory available in repos'
+USAGE_DESC_orgpull='pull most recent org directory available in repos'
CMDFNC_orgpull() {
_check_args_n 0 "$@"
_NAME_ARCHIVE=orgdir
if [ "$#" -lt 1 ]; then
error_exit_with_usage 'missing command.'
fi
-for CMD in ${COMMANDS}; do
+for CMD in ${USAGE_INDICES}; do
if [ "$1" = "${CMD}" ]; then
break
fi
cd $(dirname "$0")
. lib/abort
. lib/audio_dev_is_mute
+. lib/print_usage
MAX_LOUDNESS=150
-BIN_NAME="$(basename $0)"
FLAG_HELP_SHORT='-h'
FLAG_HELP_LONG='--help'
-print_usage() {
- echo "Usage: ${BIN_NAME} [${FLAG_HELP_SHORT}] [${FLAG_HELP_LONG}] [LOUDNESS]"
- echo "Set audio volume, or (if called without any arguments) toggle audio device muteness.\n"
- echo "Available arguments (of which at most one may be used):\n"
- echo " LOUDNESS\taudio volume to set (as percentage, must be integer)"
- echo " ${FLAG_HELP_SHORT}, ${FLAG_HELP_LONG}\tdisplay this help and exit"
-}
+USAGE_DESCRIPTION='Set audio volume, or (if called without any arguments) toggle audio device muteness.'
+USAGE_LINES='[COMMAND]\nLOUDNESS'
+USAGE_INDICES='LOUDNESS _help'
+USAGE_DESC_LOUDNESS='audio volume to set (as percentage, must be integer)'
+USAGE_DESC__help='display this help and exit'
+USAGE_NAME__help="${FLAG_HELP_SHORT}, ${FLAG_HELP_LONG}"
error_exit() { abort "Aborting due to $1\n\n$(print_usage)"; }
--- /dev/null
+USAGE_BIN_NAME="$(basename $0)"
+
+print_usage() {
+ echo 'Usage:'
+ echo "${USAGE_LINES}" | while read _LINE; do
+ echo " ${USAGE_BIN_NAME} ${_LINE}"
+ done
+ echo "\n${USAGE_DESCRIPTION}\n"
+ echo "Available arguments:\n"
+ _var_of() { eval printf '"%s"' '"${'"${1}${2}"'}"'; }
+ _build_index() {
+ _ARGS="$(_var_of 'USAGE_ARGS_' ${_IDX})"
+ if [ ! -z "${_ARGS}" ]; then
+ _ARGS=" ${_ARGS}"
+ fi
+ _NAME="${_IDX}"
+ _ALT_NAME="$(_var_of 'USAGE_NAME_' ${_IDX})"
+ if [ ! -z "${_ALT_NAME}" ]; then
+ _NAME="${_ALT_NAME}"
+ fi
+ _KEY=" ${_NAME}${_ARGS}"
+ _LEN_KEY=$(echo -n "${_KEY}" | wc -c)
+ }
+ _MAX_LEN_KEY=0
+ for _IDX in ${USAGE_INDICES}; do
+ _build_index
+ if [ "${_LEN_KEY}" -gt "${_MAX_LEN_KEY}" ]; then
+ _MAX_LEN_KEY="${_LEN_KEY}"
+ fi
+ done
+ for _IDX in ${USAGE_INDICES}; do
+ _build_index
+ printf '%s' "${_KEY}"
+ _LEN_GAP=$(calc "${_MAX_LEN_KEY} - ${_LEN_KEY} + 4")
+ for _ in $(seq 1 ${_LEN_GAP}); do
+ printf ' '
+ done
+ printf '%s\n' "$(_var_of 'USAGE_DESC_' ${_IDX})"
+ done
+}