2020-01-05 12:11:59 +01:00
|
|
|
#!/bin/sh
|
2019-02-09 14:17:45 +01:00
|
|
|
|
2024-08-22 20:44:37 +02:00
|
|
|
# Exit the script on any error, undefined variable, or in a pipeline.
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# Check if the remote path is empty.
|
2023-06-08 17:35:29 +02:00
|
|
|
if [ -z "$(echo "$INPUT_REMOTE_PATH" | awk '{$1=$1};1')" ]; then
|
2024-08-22 20:44:37 +02:00
|
|
|
printf "Error: The remote_path cannot be empty. See: github.com/Burnett01/rsync-deployments/issues/44\n"
|
2023-06-08 17:23:41 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-08-22 20:44:37 +02:00
|
|
|
# Start the SSH agent and load the key.
|
|
|
|
if ! source agent-start "$GITHUB_ACTION"; then
|
|
|
|
printf "Error: SSH agent could not be started.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-02-09 14:17:45 +01:00
|
|
|
|
2024-08-22 20:44:37 +02:00
|
|
|
if ! echo "$INPUT_REMOTE_KEY" | SSH_PASS="$INPUT_REMOTE_KEY_PASS" agent-add; then
|
|
|
|
printf "Error: SSH key could not be added.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-06-22 21:40:12 +02:00
|
|
|
|
2024-08-22 20:44:37 +02:00
|
|
|
# Optionally add Legacy RSA Hostkeys.
|
|
|
|
LEGACY_RSA_HOSTKEYS=""
|
|
|
|
if [ "$INPUT_LEGACY_ALLOW_RSA_HOSTKEYS" = "true" ]; then
|
|
|
|
LEGACY_RSA_HOSTKEYS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
|
|
|
|
fi
|
2024-03-06 12:16:35 +01:00
|
|
|
|
2024-08-22 20:44:37 +02:00
|
|
|
# Define variables.
|
2020-06-22 21:40:12 +02:00
|
|
|
SWITCHES="$INPUT_SWITCHES"
|
2024-03-06 12:16:35 +01:00
|
|
|
RSH="ssh -o StrictHostKeyChecking=no $LEGACY_RSA_HOSTKEYS -p $INPUT_REMOTE_PORT $INPUT_RSH"
|
2020-06-22 21:40:12 +02:00
|
|
|
LOCAL_PATH="$GITHUB_WORKSPACE/$INPUT_PATH"
|
|
|
|
DSN="$INPUT_REMOTE_USER@$INPUT_REMOTE_HOST"
|
|
|
|
|
2024-08-22 20:44:37 +02:00
|
|
|
# Perform deployment.
|
|
|
|
if ! sh -c "rsync $SWITCHES -e '$RSH' $LOCAL_PATH $DSN:$INPUT_REMOTE_PATH"; then
|
|
|
|
printf "Error: Deployment failed.\n"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
printf "Deployment completed successfully.\n"
|