diff --git a/prepare-ssh/action.yml b/prepare-ssh/action.yml index 8690184..133ca54 100644 --- a/prepare-ssh/action.yml +++ b/prepare-ssh/action.yml @@ -20,10 +20,28 @@ runs: run: | set -eu + SUDO="" + [ "$(id -u)" -ne 0 ] && SUDO="sudo" + + if ! command -v ssh-keyscan >/dev/null 2>&1; then + if command -v apt-get >/dev/null 2>&1; then + $SUDO apt-get update + $SUDO apt-get install -y --no-install-recommends openssh-client + else + echo "ssh-keyscan이 없습니다. openssh-client를 설치한 러너가 필요합니다." + exit 1 + fi + fi + mkdir -p ~/.ssh chmod 700 ~/.ssh - printf '%s\n' "${{ inputs.ssh-key }}" > ${{ inputs.key-path }} - chmod 600 ${{ inputs.key-path }} + KEY_PATH="${{ inputs.key-path }}" + case "$KEY_PATH" in + "~/"*) KEY_PATH="$HOME/${KEY_PATH#~/}" ;; + esac - ssh-keyscan -p ${{ inputs.port }} -H "${{ inputs.host }}" >> ~/.ssh/known_hosts \ No newline at end of file + printf '%s\n' "${{ inputs.ssh-key }}" > "$KEY_PATH" + chmod 600 "$KEY_PATH" + + ssh-keyscan -p ${{ inputs.port }} -H "${{ inputs.host }}" >> ~/.ssh/known_hosts diff --git a/remote-command/action.yml b/remote-command/action.yml index 99e9606..df9005d 100644 --- a/remote-command/action.yml +++ b/remote-command/action.yml @@ -22,6 +22,19 @@ runs: run: | set -eu + SUDO="" + [ "$(id -u)" -ne 0 ] && SUDO="sudo" + + if ! command -v ssh >/dev/null 2>&1; then + if command -v apt-get >/dev/null 2>&1; then + $SUDO apt-get update + $SUDO apt-get install -y --no-install-recommends openssh-client + else + echo "ssh가 없습니다. openssh-client를 설치한 러너가 필요합니다." + exit 1 + fi + fi + KEY_PATH="${{ inputs.key-path }}" if [ -z "$KEY_PATH" ]; then KEY_PATH="$HOME/.ssh/deploy_key" @@ -32,4 +45,4 @@ runs: "${{ inputs.user }}@${{ inputs.host }}" \ 'bash -se' << 'EOF' ${{ inputs.command }} - EOF \ No newline at end of file + EOF