-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathout
executable file
·32 lines (21 loc) · 804 Bytes
/
out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
set -e
exec 3>&1 # make stdout available as fd 3 for the result
exec 1>&2 # redirect all output to stderr for logging
source=$1
if [ -z "$source" ]; then
echo "usage: $0 <path/to/source>"
exit 1
fi
payload=$(mktemp /tmp/resource-out.XXXXXX)
cat > $payload <&0
cd $source
hostname=$(jq -r '.source.hostname' < $payload)
username=$(jq -r '.source.username' < $payload)
port=$(jq -r '.source.port // "22"' < $payload)
private_key_file=$(mktemp /tmp/resource-out.XXXXXX)
chmod 600 $private_key_file
jq -r '.source.private_key // ""' $payload > $private_key_file
command=$(jq -r '.params.command' < $payload)
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 -p $port -i $private_key_file $username@$hostname $command
echo "{\"version\": {\"time\": \"$(date +%s)\"}}" >&3