-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh_wrapper.sh
More file actions
executable file
·35 lines (27 loc) · 913 Bytes
/
ssh_wrapper.sh
File metadata and controls
executable file
·35 lines (27 loc) · 913 Bytes
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
33
34
35
#!/bin/bash
id="$1"
filename="/tmp/$id.json"
ssh_options=()
port=$(jq -r '.port // empty' $filename 2> /dev/null)
if [ -n "$port" ]; then
ssh_options+=(-p $port)
fi
key=$(jq -r '.key // empty' $filename 2> /dev/null)
if [ -n "$key" ]; then
TMP_KEY=$(mktemp)
echo "$key" > $TMP_KEY
chmod 600 "$TMP_KEY"
ssh_options+=(-i $TMP_KEY)
fi
password=$(jq -r '.password // empty' $filename 2> /dev/null)
if [ -n "$password" ]; then
TMP_PASS=$(mktemp)
echo "$password" > $TMP_PASS
if [ -n "$key" ]; then
sshpass_command="sshpass -P passphrase -f $TMP_PASS"
else
sshpass_command="sshpass -f $TMP_PASS"
fi
fi
destination=$(jq -r '.destination // empty' $filename 2> /dev/null)
exec $sshpass_command ssh -o LogLevel=ERROR -o ServerAliveInterval=60 -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "${ssh_options[@]}" "$destination"