From 45ff586b4104591c26d769070535b287672f6cee Mon Sep 17 00:00:00 2001 From: "Huan-Ting,Chen" Date: Sun, 13 Jun 2021 17:43:53 +0800 Subject: [PATCH] fix multi configs bug --- libexec/spc-download | 16 ++++++++-------- libexec/spc-upload | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libexec/spc-download b/libexec/spc-download index fef5ec6..81c5219 100755 --- a/libexec/spc-download +++ b/libexec/spc-download @@ -8,6 +8,8 @@ set -e SCP_OPS=("-3" "-4" "-6" "-B" "-C" "-p" "-q" "-r" "-T" "-v" "-c" "-F" "-i" "-J" "-l" "-o" "-P" "-S") DEFAULT_DOWNLOAD_DIR="${HOME}/" +configs=() + get_config() { local config="$1" local file="$2" @@ -16,7 +18,7 @@ get_config() { } parse_config() { - ## parse config and store in three variables: address, downloaddir, params + ## parse config and store in three variables: address, downloaddir, configs if [ ! -f "${SPC_REMOTES_DIR}/$1" ]; then echo "$1 not found" @@ -31,20 +33,18 @@ parse_config() { if [[ -z "${downloaddir}" ]]; then downloaddir="${DEFAULT_DOWNLOAD_DIR}" fi - - params="" + for ops in "${SCP_OPS[@]}"; do if grep -q -E "^${ops}(=|$)" "${SPC_REMOTES_DIR}/$1"; then value="$(get_config "${ops}" "${SPC_REMOTES_DIR}/$1")" if [[ -n "${value}" ]]; then - params="${params} ${ops} ${value}" + configs+=("${ops} ${value}") else - params="${params} ${ops}" + configs+=("${ops}") fi fi done - params="${params# }" fi } @@ -77,8 +77,8 @@ parse_config "${remote}" if [ $# -gt 1 ]; then IFS="," - scp -r "${params}" "${address}:{$*}" "${downloaddir}" + scp -r "${configs[@]}" "${address}:{$*}" "${downloaddir}" IFS=" " else - scp -r "${params}" "${address}:$*" "${downloaddir}" + scp -r "${configs[@]}" "${address}:$*" "${downloaddir}" fi diff --git a/libexec/spc-upload b/libexec/spc-upload index 3535dea..0d0eb8a 100755 --- a/libexec/spc-upload +++ b/libexec/spc-upload @@ -8,6 +8,8 @@ set -e SCP_OPS=("-3" "-4" "-6" "-B" "-C" "-p" "-q" "-r" "-T" "-v" "-c" "-F" "-i" "-J" "-l" "-o" "-P" "-S") DEFAULT_UPLOAD_DIR="~/" +configs=() + get_config() { local config="$1" local file="$2" @@ -16,7 +18,7 @@ get_config() { } parse_config() { - ## parse config and store in three variables: address, uploaddir, params + ## parse config and store in three variables: address, uploaddir, configs if [ ! -f "${SPC_REMOTES_DIR}/$1" ]; then echo "$1 not found" @@ -31,20 +33,18 @@ parse_config() { if [[ -z "${uploaddir}" ]]; then uploaddir="${DEFAULT_UPLOAD_DIR}" fi - - params="" + for ops in "${SCP_OPS[@]}"; do if grep -q -E "^${ops}(=|$)" "${SPC_REMOTES_DIR}/$1"; then value="$(get_config "${ops}" "${SPC_REMOTES_DIR}/$1")" if [[ -n "${value}" ]]; then - params="${params} ${ops} ${value}" + configs+=("${ops} ${value}") else - params="${params} ${ops}" + configs+=("${ops}") fi fi done - params="${params# }" fi } @@ -75,4 +75,4 @@ fi parse_config "${remote}" -scp -r "${params}" "$@" "${address}:${uploaddir}" +scp -r "${configs[@]}" "$@" "${address}:${uploaddir}"