From dfb36969103ac1820de22913a3cf2f84ddcae7ae Mon Sep 17 00:00:00 2001 From: redxef Date: Thu, 8 Jun 2023 00:15:13 +0200 Subject: [PATCH] Make alternative tar command settable. --- tarback.sh | 12 ++++++++---- tarback/docker.sh | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tarback.sh b/tarback.sh index 6166130..57a9772 100755 --- a/tarback.sh +++ b/tarback.sh @@ -12,10 +12,12 @@ TARBACK_TRANSFORM_REMOTE_ARGUMENT_COMMAND_DEFAULT= TARBACK_TAR_CREATE_COMMAND_DEFAULT='tar c -C "$1" .' # shellcheck disable=SC2016 # disable variable not expanding hint TARBACK_TAR_CREATE_COMMAND_FILE_DEFAULT='tar c -C "$(dirname "$1")" "$(basename "$1")"' +TARBACK_TAR_CREATE_USE_ALT_COMMAND_DEFAULT='[ ! -d "$1" ]' # shellcheck disable=SC2016 # disable variable not expanding hint TARBACK_TAR_EXTRACT_COMMAND_DEFAULT='tar x -C "$1"' # shellcheck disable=SC2016 # disable variable not expanding hint TARBACK_TAR_EXTRACT_COMMAND_FILE_DEFAULT='tar x -C "$(dirname "$1")"' +TARBACK_TAR_EXTRACT_USE_ALT_COMMAND_DEFAULT='[ ! -e "$1" ] && [ -d "$(dirname "$1")" ]' TARBACK_COMPRESSION_DEFAULT='xz' TARBACK_SPLIT_DEFAULT="split -b $((128*1024*1024)) -" TARBACK_MERGE_DEFAULT='cat' @@ -30,8 +32,10 @@ TARBACK_TRANSFORM_REMOTE_COMMAND="${TARBACK_TRANSFORM_REMOTE_COMMAND:-$TARBACK_T TARBACK_TRANSFORM_REMOTE_ARGUMENT_COMMAND="${TARBACK_TRANSFORM_REMOTE_ARGUMENT_COMMAND:-$TARBACK_TRANSFORM_REMOTE_ARGUMENT_COMMAND_DEFAULT}" TARBACK_TAR_CREATE_COMMAND="${TARBACK_TAR_CREATE_COMMAND:-$TARBACK_TAR_CREATE_COMMAND_DEFAULT}" TARBACK_TAR_CREATE_COMMAND_FILE="${TARBACK_TAR_CREATE_COMMAND_FILE:-$TARBACK_TAR_CREATE_COMMAND_FILE_DEFAULT}" +TARBACK_TAR_CREATE_USE_ALT_COMMAND="${TARBACK_TAR_CREATE_USE_ALT_COMMAND:-$TARBACK_TAR_CREATE_USE_ALT_COMMAND_DEFAULT}" TARBACK_TAR_EXTRACT_COMMAND="${TARBACK_TAR_EXTRACT_COMMAND:-$TARBACK_TAR_EXTRACT_COMMAND_DEFAULT}" TARBACK_TAR_EXTRACT_COMMAND_FILE="${TARBACK_TAR_EXTRACT_COMMAND_FILE:-$TARBACK_TAR_EXTRACT_COMMAND_FILE_DEFAULT}" +TARBACK_TAR_EXTRACT_USE_ALT_COMMAND="${TARBACK_TAR_EXTRACT_USE_ALT_COMMAND:-$TARBACK_TAR_EXTRACT_USE_ALT_COMMAND_DEFAULT}" TARBACK_COMPRESSION="${TARBACK_COMPRESSION:-$TARBACK_COMPRESSION_DEFAULT}" TARBACK_SPLIT="${TARBACK_SPLIT:-$TARBACK_SPLIT_DEFAULT}" TARBACK_MERGE="${TARBACK_MERGE:-$TARBACK_MERGE_DEFAULT}" @@ -68,7 +72,7 @@ _create() { # $2 ... dst src="$1" dst="$(_transform_split_name "$2")" - if [ -d "$src" ]; then + if ! sh -c "$TARBACK_TAR_CREATE_USE_ALT_COMMAND" - "$src"; then tarback_tar_create_command="$TARBACK_TAR_CREATE_COMMAND" else tarback_tar_create_command="$TARBACK_TAR_CREATE_COMMAND_FILE" @@ -86,10 +90,10 @@ create() { _restore() { src="$(_transform_split_name "$1")" dst="$2" - if [ ! -e "$dst" ] && [ -d "$(dirname "$dst")" ]; then - tarback_tar_extract_command="$TARBACK_TAR_EXTRACT_COMMAND_FILE" - else + if ! sh -c "$TARBACK_TAR_EXTRACT_USE_ALT_COMMAND" - "$dst"; then tarback_tar_extract_command="$TARBACK_TAR_EXTRACT_COMMAND" + else + tarback_tar_extract_command="$TARBACK_TAR_EXTRACT_COMMAND_FILE" fi tarback_tar_extract_command="$(_transform_remote "$tarback_tar_extract_command")" $TARBACK_MERGE "$src"* \ diff --git a/tarback/docker.sh b/tarback/docker.sh index f277d56..9e66adf 100644 --- a/tarback/docker.sh +++ b/tarback/docker.sh @@ -1,5 +1,7 @@ #!/bin/sh _tarback_plugin_docker_cmd='docker run -i --rm --workdir=/mnt --volume="$1":/mnt/"$1" alpine ' -TARBACK_TAR_CREATE_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar c -C "/mnt/$1" .' -TARBACK_TAR_EXTRACT_COMMAND_FILE="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"' +TARBACK_TAR_CREATE_COMMAND="$_tarback_plugin_docker_cmd "'tar c -C "/mnt/$1" .' +TARBACK_TAR_EXTRACT_COMMAND="$_tarback_plugin_docker_cmd "'tar x -C "/mnt/$1"' +TARBACK_TAR_CREATE_USE_ALT_COMMAND=false +TARBACK_TAR_EXTRACT_USE_ALT_COMMAND=false