Restructure variable initialization.

This commit is contained in:
redxef 2023-02-17 02:45:35 +01:00
parent 975f0a194e
commit 4cf714ce5c
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -1,27 +1,33 @@
#!/bin/sh #!/bin/sh
set -e set -eu
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share:/usr/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 ... # 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 # maybe the command needs to be transformed before being passed to the
# remote command, see _transform_ssh_command for an example # remote command, see _transform_ssh_command for an example
TARBACK_TRANSFORM_REMOTE_COMMAND="${TARBACK_TRANSFORM_REMOTE_COMMAND:-}" TARBACK_TRANSFORM_REMOTE_COMMAND="${TARBACK_TRANSFORM_REMOTE_COMMAND:-$TARBACK_TRANSFORM_REMOTE_COMMAND_DEFAULT}"
# shellcheck disable=SC2016 # disable variable not expanding hint TARBACK_TAR_CREATE_COMMAND="${TARBACK_TAR_CREATE_COMMAND:-$TARBACK_TAR_CREATE_COMMAND_DEFAULT}"
[ -z "$TARBACK_TAR_CREATE_COMMAND" ] \ TARBACK_TAR_EXTRACT_COMMAND="${TARBACK_TAR_EXTRACT_COMMAND:-$TARBACK_TAR_EXTRACT_COMMAND_DEFAULT}"
&& TARBACK_TAR_CREATE_COMMAND='tar c -C "$(dirname "$1")" "$(basename "$1")"' TARBACK_COMPRESSION="${TARBACK_COMPRESSION:-$TARBACK_COMPRESSION_DEFAULT}"
# shellcheck disable=SC2016 # disable variable not expanding hint TARBACK_SPLIT="${TARBACK_SPLIT:-$TARBACK_SPLIT_DEFAULT}"
[ -z "$TARBACK_TAR_EXTRACT_COMMAND" ] \ TARBACK_MERGE="${TARBACK_MERGE:-$TARBACK_MERGE_DEFAULT}"
&& TARBACK_TAR_EXTRACT_COMMAND='tar x -C "$(dirname "$1")"' TARBACK_PLUGIN_SEARCH_PATH="${TARBACK_PLUGIN_SEARCH_PATH:-$TARBACK_PLUGIN_SEARCH_PATH_DEFAULT}"
[ -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_PLUGIN_SEARCH_PATH="$(echo "$TARBACK_PLUGIN_SEARCH_PATH" | tr ':' '\n')" TARBACK_PLUGIN_SEARCH_PATH="$(echo "$TARBACK_PLUGIN_SEARCH_PATH" | tr ':' '\n')"
_transform_split_name() { _transform_split_name() {