From e58c2eb875dcfbcd1570d5a4bce3430611c24feb Mon Sep 17 00:00:00 2001 From: redxef Date: Thu, 22 Feb 2024 14:22:20 +0100 Subject: [PATCH] Fix tests and option parsing of plugins. --- tarback.sh | 8 ++++++ tarback/docker.sh | 3 +- tarback/postgres.sh | 3 +- tarback/ssh.sh | 3 +- tests/test-004-postgres.sh | 4 +-- tests/test-005-ssh-postgres.sh | 52 ++++++++++++++++++++++++++++++++++ 6 files changed, 68 insertions(+), 5 deletions(-) create mode 100755 tests/test-005-ssh-postgres.sh diff --git a/tarback.sh b/tarback.sh index a47b2fb..e6e2d04 100755 --- a/tarback.sh +++ b/tarback.sh @@ -135,7 +135,15 @@ while getopts "$short_options" arg; do for loc in $TARBACK_PLUGIN_SEARCH_PATH; do if [ -e "$loc/tarback/$p.sh" ]; then # shellcheck disable=SC1090 # disable cannot follow source + old_short_options="$short_options" + old_arg="$arg" + old_OPTIND="$OPTIND" + old_OPTARG="$OPTARG" . "$loc/tarback/$p.sh" + short_options="$old_short_options" + arg="$old_arg" + OPTIND="$old_OPTIND" + OPTARG="$old_OPTARG" sourced=true break fi diff --git a/tarback/docker.sh b/tarback/docker.sh index f8a748b..9ef8c6a 100644 --- a/tarback/docker.sh +++ b/tarback/docker.sh @@ -3,7 +3,8 @@ _tarback_plugin_docker_use_container= short_options='c:' -while getopts "$short_options" arg; do +OPTIND=1 +while [ "${TARBACK_DOCKER_ARGS:-}" != '' ] && getopts "$short_options" arg ${TARBACK_DOCKER_ARGS:-}; do case "$arg" in c) _tarback_plugin_docker_use_container="$OPTARG" diff --git a/tarback/postgres.sh b/tarback/postgres.sh index 012a76c..173f977 100644 --- a/tarback/postgres.sh +++ b/tarback/postgres.sh @@ -6,7 +6,8 @@ _tarback_plugin_postgres_user= _tarback_plugin_postgres_password= short_options='h:p:U:w:' -while getopts "$short_options" arg; do +OPTIND=1 +while [ "${TARBACK_POSTGRES_ARGS:-}" != '' ] && getopts "$short_options" arg ${TARBACK_POSTGRES_ARGS:-}; do case "$arg" in h) _tarback_plugin_postgres_host="$OPTARG" diff --git a/tarback/ssh.sh b/tarback/ssh.sh index 7d6163a..5bae1b3 100644 --- a/tarback/ssh.sh +++ b/tarback/ssh.sh @@ -19,7 +19,8 @@ _tarback_plugin_ssh_transform_ssh_argument() { } short_options='s:' -while getopts "$short_options" arg; do +OPTIND=1 +while [ "${TARBACK_SSH_ARGS:-}" != '' ] && getopts "$short_options" arg ${TARBACK_SSH_ARGS:-}; do case "$arg" in s) TARBACK_REMOTE="$OPTARG" diff --git a/tests/test-004-postgres.sh b/tests/test-004-postgres.sh index 82b8627..bcba335 100755 --- a/tests/test-004-postgres.sh +++ b/tests/test-004-postgres.sh @@ -23,11 +23,11 @@ EOF d="$(mktemp -d)" -./tarback.sh -P postgres -h 10.1.0.100 -U postgres -p 5432 -w password123 create postgres "$d/dump" +TARBACK_POSTGRES_ARGS='-h 10.1.0.100 -U postgres -p 5432 -w password123' ./tarback.sh -P postgres create postgres "$d/dump" PGPASSWORD=password123 psql -h 10.1.0.100 -U postgres -p 5432 postgres <