forked from jetbrains-infra/docker-anyconnect-vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·42 lines (37 loc) · 1.21 KB
/
entrypoint.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
#!/bin/sh
function terminate() {
echo "Detected SIGTERM, shuting down..."
killall -9 openconnect &>/dev/null
killall -9 socat &>/dev/null
exit 0
}
trap terminate TERM INT
connect() {
killall -9 openconnect &>/dev/null
killall -9 socat &>/dev/null
for NAME in $(awk "END { for (name in ENVIRON) { print name; }}" < /dev/null)
do
if test "${NAME#*PORT_MAP_}" != "$NAME"
then
VAL=$(awk "END { printf ENVIRON[\"$NAME\"]; }" < /dev/null)
PORT="${VAL%|*}"
TARGET="${VAL#*|}"
socat TCP4-LISTEN:${PORT},fork TCP4:${TARGET} &
fi
done
# Start openconnect
if [[ -z "${PASSWORD}" ]]; then
# Ask for password
openconnect -u $USER $OPTIONS $URL
elif [[ ! -z "${PASSWORD}" ]] && [[ ! -z "${MFA_CODE}" ]]; then
# Multi factor authentication (MFA)
(echo $PASSWORD echo $MFA_CODE) | openconnect -u $USER $OPTIONS --passwd-on-stdin $URL
elif [[ ! -z "${PASSWORD}" ]]; then
# Standard authentication
echo $PASSWORD | openconnect -u $USER $OPTIONS --passwd-on-stdin $URL
fi
}
until (connect); do
echo "openconnect exited. Restarting process in 5 seconds…" >&2
sleep 5
done