From c6163da5e4f0cc6587e218944641eb6d9a5faacd Mon Sep 17 00:00:00 2001 From: redxef Date: Thu, 8 Jun 2023 16:47:31 +0200 Subject: [PATCH] Add config parsing. --- tarback.sh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tarback.sh b/tarback.sh index b187d0a..e529a72 100755 --- a/tarback.sh +++ b/tarback.sh @@ -2,8 +2,10 @@ set -eu -XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" -XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" +_="${XDG_DATA_HOME:=$HOME/.local/share}" +_="${XDG_DATA_DIRS:=/usr/local/share:/usr/share}" +_="${XDG_CONFIG_HOME:=$HOME/.config}" +_="${XDG_CONFIG_DIRS:=/etc}" TARBACK_REMOTE_DEFAULT= TARBACK_TRANSFORM_REMOTE_COMMAND_DEFAULT= @@ -22,7 +24,19 @@ 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" +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 ... 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_SPLIT:=$TARBACK_SPLIT_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() { command_name="$(echo "$TARBACK_SPLIT" | awk '{print $1}')"