Compare commits
2
Commits
f6a66c462d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
994b093ada | ||
|
|
89086c4163 |
+11
-9
@@ -25,22 +25,24 @@ runs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Execute SSH/SCP Transfers
|
- name: Execute SSH/SCP Transfers
|
||||||
shell: bash
|
shell: bash
|
||||||
|
env:
|
||||||
|
PRIVATE_KEY: ${{ inputs.private_key }}
|
||||||
|
TRANSFERS: ${{ inputs.transfers }}
|
||||||
|
HOST: ${{ inputs.host }}
|
||||||
|
PORT: ${{ inputs.port }}
|
||||||
|
USERNAME: ${{ inputs.username }}
|
||||||
run: |
|
run: |
|
||||||
# 1. Create a secure temporary file for the SSH key
|
# 1. Create a secure temporary file for the SSH key
|
||||||
SSH_KEY_PATH=$(mktemp)
|
SSH_KEY_PATH=$(mktemp)
|
||||||
cat << 'EOF' > "$SSH_KEY_PATH"
|
printf '%s\n' "$PRIVATE_KEY" > "$SSH_KEY_PATH"
|
||||||
${{ inputs.private_key }}
|
|
||||||
EOF
|
|
||||||
chmod 600 "$SSH_KEY_PATH"
|
chmod 600 "$SSH_KEY_PATH"
|
||||||
|
|
||||||
# 2. Add Host to known_hosts to prevent verification prompts
|
# 2. Add Host to known_hosts to prevent verification prompts
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
ssh-keyscan -p ${{ inputs.port }} -H ${{ inputs.host }} >> ~/.ssh/known_hosts 2>/dev/null
|
ssh-keyscan -p "$PORT" -H "$HOST" >> ~/.ssh/known_hosts 2>/dev/null
|
||||||
|
|
||||||
# 3. Securely write transfers input to a file for parsing
|
# 3. Securely write transfers input to a file for parsing
|
||||||
cat << 'EOF' > transfers.txt
|
printf '%s\n' "$TRANSFERS" > transfers.txt
|
||||||
${{ inputs.transfers }}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# 4. Loop through each line and execute commands
|
# 4. Loop through each line and execute commands
|
||||||
while IFS= read -r line || [ -n "$line" ]; do
|
while IFS= read -r line || [ -n "$line" ]; do
|
||||||
@@ -58,11 +60,11 @@ runs:
|
|||||||
echo "::group::Transfer to $dest"
|
echo "::group::Transfer to $dest"
|
||||||
|
|
||||||
echo "Creating remote directory: $dest"
|
echo "Creating remote directory: $dest"
|
||||||
ssh -i "$SSH_KEY_PATH" -p ${{ inputs.port }} ${{ inputs.username }}@${{ inputs.host }} "mkdir -p \"$dest\"" < /dev/null
|
ssh -i "$SSH_KEY_PATH" -p "$PORT" "$USERNAME@$HOST" "mkdir -p \"$dest\"" < /dev/null
|
||||||
|
|
||||||
echo "Copying $src to $dest..."
|
echo "Copying $src to $dest..."
|
||||||
# Note: eval is used so wildcards or multiple space-separated files expand properly
|
# Note: eval is used so wildcards or multiple space-separated files expand properly
|
||||||
eval "scp -r -i \"$SSH_KEY_PATH\" -P ${{ inputs.port }} $src \"${{ inputs.username }}@${{ inputs.host }}:$dest/\"" < /dev/null
|
eval "scp -r -i \"$SSH_KEY_PATH\" -P $PORT $src \"$USERNAME@$HOST:$dest/\"" < /dev/null
|
||||||
|
|
||||||
echo "::endgroup::"
|
echo "::endgroup::"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user