63 lines
1.4 KiB
YAML
63 lines
1.4 KiB
YAML
name: SSH copy
|
|
description: copy files to SSH hosts
|
|
inputs:
|
|
host:
|
|
description: SSH host
|
|
required: true
|
|
user:
|
|
description: SSH user
|
|
required: true
|
|
key:
|
|
description: SSH private key
|
|
required: true
|
|
source:
|
|
description: directory to copy
|
|
required: true
|
|
target:
|
|
description: destination path on remote
|
|
required: true
|
|
port:
|
|
description: SSH port
|
|
required: false
|
|
default: "22"
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: install rsync
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
command -v rsync >/dev/null && exit 0
|
|
|
|
sudo apt-get -qq update
|
|
sudo apt-get -yqq install rsync
|
|
|
|
- name: setup ssh
|
|
shell: bash
|
|
env:
|
|
SSH_KEY: ${{ inputs.key }}
|
|
HOST: ${{ inputs.host }}
|
|
PORT: ${{ inputs.port }}
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p ~/.ssh
|
|
|
|
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
|
|
ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts
|
|
chmod 600 ~/.ssh/known_hosts
|
|
|
|
- name: rsync directory
|
|
shell: bash
|
|
env:
|
|
SRC: ${{ inputs.source }}
|
|
HOST: ${{ inputs.host }}
|
|
USER: ${{ inputs.user }}
|
|
TARGET: ${{ inputs.target }}
|
|
PORT: ${{ inputs.port }}
|
|
run: |
|
|
set -euo pipefail
|
|
rsync -rlptz --delete -e "ssh -p $PORT" "$SRC" "$USER@$HOST:$TARGET"
|