rsync client, to use with ci

main
Ricard Illa 2022-09-13 10:27:47 +02:00
parent 6d8109d9a0
commit 7f98752cb9
No known key found for this signature in database
GPG Key ID: F69A672B72E54902
1 changed files with 20 additions and 5 deletions

View File

@ -18,11 +18,14 @@ if [ -z "$SSH_KEY" ]; then
exit 1
fi
SSH_KEY_CERT="${SSH_KEY_CERT:-${PLUGIN_KEY_CERT}}"
KNOWN_HOSTS="${KNOWN_HOSTS:=${PLUGIN_KNOWN_HOSTS}}"
SOURCE="${SOURCE:-${PLUGIN_SOURCE}}"
if [ -z "$SOURCE" ]; then
echo "'source' must be specified"
SOURCES="${SOURCES:-${PLUGIN_SOURCES}}"
SOURCES=$(echo "$SOURCES" | tr ',' ' ')
if [ -z "$SOURCES" ]; then
echo "specify at least one source"
exit 1
fi
@ -37,10 +40,19 @@ ARGS=${ARGS:-${PLUGIN_ARGS}}
# prepare SSH
mkdir -p "$HOME/.ssh"
keyfile="$HOME/.ssh/id_rsa"
keyfile="$HOME/.ssh/user_key"
echo "$SSH_KEY" > "$keyfile"
chmod 0600 "$keyfile"
echo 'Host *' > "$HOME/.ssh/config"
echo " IdentityFile $keyfile" >> "$HOME/.ssh/config"
if [ -n "${SSH_KEY_CERT}" ]; then
certfile="$HOME/.ssh/user_key-cert.pub"
echo "${SSH_KEY_CERT}" > "$certfile"
echo " CertificateFile $certfile" >> "$HOME/.ssh/config"
fi
known_hosts_file="${HOME}/.ssh/known_hosts"
[ -n "${KNOWN_HOSTS}" ] && echo "${KNOWN_HOSTS}" >> "$known_hosts_file"
[ -f "${known_hosts_file}" ] && chmod 0600 "$known_hosts_file"
@ -48,4 +60,7 @@ known_hosts_file="${HOME}/.ssh/known_hosts"
# run rsync
# shellcheck disable=SC2086
exec rsync $ARGS "${SOURCE}" "${USER}"@"${HOST}":"${TARGET}"
for SOURCE in $SOURCES; do
echo "copying '$SOURCE' to '$TARGET'"
rsync $ARGS "${SOURCE}" "${USER}"@"${HOST}":"${TARGET}"
done