Add config parsing.

This commit is contained in:
redxef 2023-06-08 16:47:31 +02:00
parent d8c6d40dd9
commit c6163da5e4
Signed by: redxef
GPG key ID: 7DAC3AA211CBD921

View file

@ -2,8 +2,10 @@
set -eu set -eu
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" _="${XDG_DATA_HOME:=$HOME/.local/share}"
XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" _="${XDG_DATA_DIRS:=/usr/local/share:/usr/share}"
_="${XDG_CONFIG_HOME:=$HOME/.config}"
_="${XDG_CONFIG_DIRS:=/etc}"
TARBACK_REMOTE_DEFAULT= TARBACK_REMOTE_DEFAULT=
TARBACK_TRANSFORM_REMOTE_COMMAND_DEFAULT= TARBACK_TRANSFORM_REMOTE_COMMAND_DEFAULT=
@ -22,7 +24,19 @@ TARBACK_COMPRESSION_DEFAULT='xz'
TARBACK_SPLIT_DEFAULT="split -b $((128*1024*1024)) -" TARBACK_SPLIT_DEFAULT="split -b $((128*1024*1024)) -"
TARBACK_MERGE_DEFAULT='cat' TARBACK_MERGE_DEFAULT='cat'
TARBACK_PLUGIN_SEARCH_PATH_DEFAULT="$(dirname "$0"):$XDG_DATA_HOME:$XDG_DATA_DIRS" TARBACK_PLUGIN_SEARCH_PATH_DEFAULT="$(dirname "$0"):$XDG_DATA_HOME:$XDG_DATA_DIRS"
TARBACK_CONFIG_SEARCH_PATH_DEFAULT="$(dirname "$0"):$XDG_CONFIG_HOME:$XDG_CONFIG_DIRS"
_="${TARBACK_PLUGIN_SEARCH_PATH:=$TARBACK_PLUGIN_SEARCH_PATH_DEFAULT}"
_="${TARBACK_CONFIG_SEARCH_PATH:=$TARBACK_CONFIG_SEARCH_PATH_DEFAULT}"
TARBACK_PLUGIN_SEARCH_PATH="$(echo "$TARBACK_PLUGIN_SEARCH_PATH" | tr ':' '\n')"
TARBACK_CONFIG_SEARCH_PATH="$(echo "$TARBACK_CONFIG_SEARCH_PATH" | tr ':' '\n' | tac)"
# load configs
for config_dir in $TARBACK_CONFIG_SEARCH_PATH; do
config_file="$config_dir/tarback/config.sh"
[ ! -f "$config_file" ] && continue
. "$config_file"
done
# example: TARBACK_REMOTE="ssh myuser@myserver" ./tarback ... # example: TARBACK_REMOTE="ssh myuser@myserver" ./tarback ...
TARBACK_REMOTE="${TARBACK_REMOTE:-$TARBACK_REMOTE_DEFAULT}" TARBACK_REMOTE="${TARBACK_REMOTE:-$TARBACK_REMOTE_DEFAULT}"
@ -39,8 +53,6 @@ _="${TARBACK_TAR_EXTRACT_USE_ALT_COMMAND:=$TARBACK_TAR_EXTRACT_USE_ALT_COMMAND_D
_="${TARBACK_COMPRESSION:=$TARBACK_COMPRESSION_DEFAULT}" _="${TARBACK_COMPRESSION:=$TARBACK_COMPRESSION_DEFAULT}"
_="${TARBACK_SPLIT:=$TARBACK_SPLIT_DEFAULT}" _="${TARBACK_SPLIT:=$TARBACK_SPLIT_DEFAULT}"
_="${TARBACK_MERGE:=$TARBACK_MERGE_DEFAULT}" _="${TARBACK_MERGE:=$TARBACK_MERGE_DEFAULT}"
_="${TARBACK_PLUGIN_SEARCH_PATH:=$TARBACK_PLUGIN_SEARCH_PATH_DEFAULT}"
TARBACK_PLUGIN_SEARCH_PATH="$(echo "$TARBACK_PLUGIN_SEARCH_PATH" | tr ':' '\n')"
_transform_split_name() { _transform_split_name() {
command_name="$(echo "$TARBACK_SPLIT" | awk '{print $1}')" command_name="$(echo "$TARBACK_SPLIT" | awk '{print $1}')"