rsync/rsync-docker.sh

40 lines
1.1 KiB
Bash
Raw Normal View History

2023-05-11 22:41:39 +02:00
#! /usr/bin/env bash
set -Eeuo pipefail
set -x
# Generates client.
# env:
# SOURCE: ${{ inputs.source }}
# DESTINATION: ${{ inputs.destionation }}
# HOST: ${{ inputs.host }}
# USER: ${{ inputs.user }}
# SSHKEY: ${{ inputs.sshkey }}
2023-05-12 00:26:36 +02:00
echo "${SOURCE} or $SOURCE or ..."
2023-05-11 22:41:39 +02:00
rsync::ssh() {
: "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}"
2023-05-12 00:03:37 +02:00
: "${SSHKEY?Please provide a SSH Private Key (ED25519).}"
2023-05-11 23:51:32 +02:00
: "${HOST?Destination Server}"
2023-05-11 22:41:39 +02:00
pushd "${GITHUB_WORKSPACE}"
2023-05-11 23:51:32 +02:00
printf "Add SSH Private Key"
2023-05-11 22:41:39 +02:00
mkdir ~/.ssh
chmod 700 ~/.ssh
echo "${SSHKEY}" | tee ~/.ssh/id_ed25519 > /dev/null
chmod 400 ~/.ssh/id_ed25519
2023-05-11 23:51:32 +02:00
ssh-keyscan -t ed25519 "${HOST}" | tee -a ~/.ssh/known_hosts
2023-05-11 22:41:39 +02:00
}
rsync::transfer() {
: "${GITHUB_WORKSPACE?GITHUB_WORKSPACE has to be set. Did you use the actions/checkout action?}"
: "${SOURCE?Define File to copy.}"
: "${DESTINATION?Define File destination.}"
2023-05-11 23:51:32 +02:00
: "${HOST?Destination Server}"
2023-05-11 22:41:39 +02:00
: "${USER?Destination User}"
pushd "${GITHUB_WORKSPACE}"
2023-05-11 23:51:32 +02:00
rsync --progress "${SOURCE}" "${USER}@${HOST}:${DESTINATION}"
2023-05-11 22:41:39 +02:00
}
rsync::ssh
2023-05-12 00:03:37 +02:00
rsync::transfer