Skip to content

Commit

Permalink
fix multi configs bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyiyi0226 committed Jun 13, 2021
1 parent e38e13f commit 45ff586
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions libexec/spc-download
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -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
14 changes: 7 additions & 7 deletions libexec/spc-upload
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
}

Expand Down Expand Up @@ -75,4 +75,4 @@ fi

parse_config "${remote}"

scp -r "${params}" "$@" "${address}:${uploaddir}"
scp -r "${configs[@]}" "$@" "${address}:${uploaddir}"

0 comments on commit 45ff586

Please sign in to comment.