rsync-action/action.yml

111 lines
2.9 KiB
YAML
Raw Normal View History

2024-05-01 13:32:38 +02:00
name: 'Rsync SSH transfer'
description: 'Transfer files to another location'
inputs:
username:
description: "Username to be used for login"
required: true
ssh-key:
description: "private SSH key to use for logging int"
required: false
host:
description: "Host to log in at"
required: true
port:
description: "Port to connect to"
required: true
default: "22"
known-host-content:
description: "Content to add to the known_hosts file, to verify the authenticity of the remote"
required: false
source:
description: "Which files to copy"
required: true
target:
description: "Where on the host to copy the files"
required: true
args:
description: "Command line args to pass to rsync"
required: true
default: "--archive --compress --verbose --mkpath"
runs:
using: "composite"
steps:
- name: Install rsync
run: |
if ! command -v apt-get &> /dev/null
then
echo "Only apt is supported"
exit 1
fi
if command -v rsync &> /dev/null
then
echo "rsync is already installed"
else
echo "Updating package index"
2024-05-01 13:32:38 +02:00
apt-get update
echo "Installing rsync"
2024-05-01 13:32:38 +02:00
apt-get install -y rsync
fi
shell: bash
- name: Create SSH directory
run: |
echo "Creating ~/.ssh"
2024-05-01 13:32:38 +02:00
mkdir -p ~/.ssh
shell: bash
- name: Install SSH config
run: |
echo "Installing SSH config"
2024-05-01 15:08:12 +02:00
cat <<EOF > ~/.ssh/config
2024-05-01 13:32:38 +02:00
Host targethost
User ${{ inputs.username }}
HostName ${{ inputs.host }}
Port ${{ inputs.port }}
2024-05-01 15:08:12 +02:00
IdentityFile ~/.ssh/key
2024-05-01 13:32:38 +02:00
ForwardAgent no
ForwardX11 no
PasswordAuthentication no
EOF
2024-05-01 15:08:12 +02:00
chmod 600 ~/.ssh/config
2024-05-01 13:32:38 +02:00
shell: bash
- name: Install SSH known_hosts
run: |
echo "Installing known_hosts"
2024-05-01 13:32:38 +02:00
echo "${{ inputs.known-host-content }}" > ~/.ssh/known_hosts
echo " StrictHostKeyChecking yes" >> ~/.ssh/config
shell: bash
if: ${{ inputs.known-host-content != null }}
- name: Disable SSH host key checking
run: |
echo "Disabling host key checking"
2024-05-01 13:32:38 +02:00
echo " StrictHostKeyChecking no" >> ~/.ssh/config
shell: bash
if: ${{ inputs.known-host-content == null }}
- name: Install SSH key
run: |
echo "Installing SSH key"
2024-05-01 15:08:12 +02:00
echo "${{ inputs.ssh-key }}" > ~/.ssh/key
chmod 600 ~/.ssh/key
2024-05-01 13:32:38 +02:00
shell: bash
if: ${{ inputs.ssh-key != null }}
- name: Transfer files
run: |
echo "Transferring files"
2024-05-01 15:08:12 +02:00
ls -lah ~/.ssh
cat ~/.ssh/config
ssh -vvvvv -G targethost
rsync ${{ inputs.args }} "${{ inputs.source }}" "targethost:${{ inputs.target }}"
2024-05-01 15:08:12 +02:00
shell: bash
# - name: Cleanup
# run: |
# echo "Cleaning up"
# rm -f ~/.ssh/{config,key,known_hosts} || true
# shell: bash