-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh-wrapper.sh
executable file
·46 lines (36 loc) · 1.28 KB
/
ssh-wrapper.sh
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
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -e
export SSHPASS="$SSH_PASSWORD"
[ "$PROVISION_DEBUG" == true ] && set -x
export SSH_OPTIONS="-o StrictHostKeyChecking=off -o IdentityAgent=none -o UserKnownHostsFile=/dev/null"
{
echo SSH wrapper[$#]: $@
if [ "$PROVISION_DEBUG" == true ] ; then
echo "Hostname: "
sshpass -e ssh $SSH_OPTIONS -i $SSH_PRIVATE_KEY $SSH_USER@$SSH_HOST 'hostname && date && uptime'
echo -----
echo "SSH_HOST = $SSH_HOST"
echo "SSH_USER = $SSH_USER"
echo "SSH_PASSWORD = ${SSH_PASSWORD//?/\*}"
echo "SSH_BASTION_HOST = $SSH_BASTION_HOST"
echo "SSH_BASTION_USER = $SSH_BASTION_USER"
echo "SSH_BASTION_PASSWORD = $SSH_BASTION_PASSWORD"
echo "SSH_BASTION_PRIVATE_KEY = ${SSH_BASTION_PRIVATE_KEY//?/\*}"
echo -----
fi
} >&2
set -- $@
COMMAND=$1
shift
function make_envs()
{
for v in "${!PROVISION_@}"; do
echo "export $v=${!v@Q}"
done
for v in "${!SSH_@}"; do
echo "export PROVISION_$v=${!v@Q}"
done
}
# insert env vars and send script to remote host t oexecute
sed -e "/^# placeholder=enviroment.*/r "<(make_envs) $COMMAND \
| sshpass -e ssh $SSH_OPTIONS -i $SSH_PRIVATE_KEY $SSH_USER@$SSH_HOST -- "script=\$(mktemp) && cat >\$script && ${SUDO} bash \$script $*"