From 4cf714ce5c6860dfbc579dbd236eb0d9d62a8664 Mon Sep 17 00:00:00 2001 From: redxef Date: Fri, 17 Feb 2023 02:45:35 +0100 Subject: [PATCH] Restructure variable initialization. --- tarback.sh | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tarback.sh b/tarback.sh index 6b12d1b..67d6e45 100755 --- a/tarback.sh +++ b/tarback.sh @@ -1,27 +1,33 @@ #!/bin/sh -set -e +set -eu XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" +TARBACK_REMOTE_DEFAULT= +TARBACK_TRANSFORM_REMOTE_COMMAND_DEFAULT= +# shellcheck disable=SC2016 # disable variable not expanding hint +TARBACK_TAR_CREATE_COMMAND_DEFAULT='tar c -C "$(dirname "$1")" "$(basename "$1")"' +# shellcheck disable=SC2016 # disable variable not expanding hint +TARBACK_TAR_EXTRACT_COMMAND_DEFAULT='tar x -C "$(dirname "$1")"' +TARBACK_COMPRESSION_DEFAULT='xz' +TARBACK_SPLIT_DEFAULT="split -b $((128*1024*1024)) -" +TARBACK_MERGE_DEFAULT='cat' +TARBACK_PLUGIN_SEARCH_PATH_DEFAULT="$(dirname "$0"):$XDG_DATA_HOME:$XDG_DATA_DIRS" + + # example: TARBACK_REMOTE="ssh myuser@myserver" ./tarback ... -TARBACK_REMOTE="${TARBACK_REMOTE:-}" +TARBACK_REMOTE="${TARBACK_REMOTE:-$TARBACK_REMOTE_DEFAULT}" # maybe the command needs to be transformed before being passed to the # remote command, see _transform_ssh_command for an example -TARBACK_TRANSFORM_REMOTE_COMMAND="${TARBACK_TRANSFORM_REMOTE_COMMAND:-}" -# shellcheck disable=SC2016 # disable variable not expanding hint -[ -z "$TARBACK_TAR_CREATE_COMMAND" ] \ - && TARBACK_TAR_CREATE_COMMAND='tar c -C "$(dirname "$1")" "$(basename "$1")"' -# shellcheck disable=SC2016 # disable variable not expanding hint -[ -z "$TARBACK_TAR_EXTRACT_COMMAND" ] \ - && TARBACK_TAR_EXTRACT_COMMAND='tar x -C "$(dirname "$1")"' -[ -z "$TARBACK_COMPRESSION" ] && TARBACK_COMPRESSION="xz" -[ -z "$TARBACK_SPLIT" ] && TARBACK_SPLIT="split -b $((128*1024*1024)) -" -[ -z "$TARBACK_MERGE" ] && TARBACK_MERGE='cat' -[ -z "$TARBACK_PLUGIN_SEARCH_PATH" ] \ - && TARBACK_PLUGIN_SEARCH_PATH="$(dirname "$0"):$XDG_DATA_HOME:$XDG_DATA_DIRS" - +TARBACK_TRANSFORM_REMOTE_COMMAND="${TARBACK_TRANSFORM_REMOTE_COMMAND:-$TARBACK_TRANSFORM_REMOTE_COMMAND_DEFAULT}" +TARBACK_TAR_CREATE_COMMAND="${TARBACK_TAR_CREATE_COMMAND:-$TARBACK_TAR_CREATE_COMMAND_DEFAULT}" +TARBACK_TAR_EXTRACT_COMMAND="${TARBACK_TAR_EXTRACT_COMMAND:-$TARBACK_TAR_EXTRACT_COMMAND_DEFAULT}" +TARBACK_COMPRESSION="${TARBACK_COMPRESSION:-$TARBACK_COMPRESSION_DEFAULT}" +TARBACK_SPLIT="${TARBACK_SPLIT:-$TARBACK_SPLIT_DEFAULT}" +TARBACK_MERGE="${TARBACK_MERGE:-$TARBACK_MERGE_DEFAULT}" +TARBACK_PLUGIN_SEARCH_PATH="${TARBACK_PLUGIN_SEARCH_PATH:-$TARBACK_PLUGIN_SEARCH_PATH_DEFAULT}" TARBACK_PLUGIN_SEARCH_PATH="$(echo "$TARBACK_PLUGIN_SEARCH_PATH" | tr ':' '\n')" _transform_split_name() {