1
0
Fork 1
mirror of https://github.com/Burnett01/rsync-deployments.git synced 2025-04-13 16:51:03 +02:00
This commit is contained in:
Nils 2025-01-19 19:30:25 +00:00 committed by GitHub
commit 60a55c7be0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,25 +1,41 @@
#!/bin/sh #!/bin/sh
# Exit the script on any error, undefined variable, or in a pipeline.
set -euo pipefail
# Check if the remote path is empty.
if [ -z "$(echo "$INPUT_REMOTE_PATH" | awk '{$1=$1};1')" ]; then if [ -z "$(echo "$INPUT_REMOTE_PATH" | awk '{$1=$1};1')" ]; then
echo "The remote_path can not be empty. see: github.com/Burnett01/rsync-deployments/issues/44" printf "Error: The remote_path cannot be empty. See: github.com/Burnett01/rsync-deployments/issues/44\n"
exit 1 exit 1
fi fi
# Start the SSH agent and load key. # Start the SSH agent and load the key.
source agent-start "$GITHUB_ACTION" if ! source agent-start "$GITHUB_ACTION"; then
echo "$INPUT_REMOTE_KEY" | SSH_PASS="$INPUT_REMOTE_KEY_PASS" agent-add printf "Error: SSH agent could not be started.\n"
exit 1
fi
# Add strict errors. if ! echo "$INPUT_REMOTE_KEY" | SSH_PASS="$INPUT_REMOTE_KEY_PASS" agent-add; then
set -eu printf "Error: SSH key could not be added.\n"
exit 1
fi
# Variables. # Optionally add Legacy RSA Hostkeys.
LEGACY_RSA_HOSTKEYS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa" LEGACY_RSA_HOSTKEYS=""
LEGACY_RSA_HOSTKEYS=$([ "$INPUT_LEGACY_ALLOW_RSA_HOSTKEYS" = "true" ] && echo "$LEGACY_RSA_HOSTKEYS" || echo "") if [ "$INPUT_LEGACY_ALLOW_RSA_HOSTKEYS" = "true" ]; then
LEGACY_RSA_HOSTKEYS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
fi
# Define variables.
SWITCHES="$INPUT_SWITCHES" SWITCHES="$INPUT_SWITCHES"
RSH="ssh -o StrictHostKeyChecking=no $LEGACY_RSA_HOSTKEYS -p $INPUT_REMOTE_PORT $INPUT_RSH" RSH="ssh -o StrictHostKeyChecking=no $LEGACY_RSA_HOSTKEYS -p $INPUT_REMOTE_PORT $INPUT_RSH"
LOCAL_PATH="$GITHUB_WORKSPACE/$INPUT_PATH" LOCAL_PATH="$GITHUB_WORKSPACE/$INPUT_PATH"
DSN="$INPUT_REMOTE_USER@$INPUT_REMOTE_HOST" DSN="$INPUT_REMOTE_USER@$INPUT_REMOTE_HOST"
# Deploy. # Perform deployment.
sh -c "rsync $SWITCHES -e '$RSH' $LOCAL_PATH $DSN:$INPUT_REMOTE_PATH" 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"