forked from arthepsy/pan-globalprotect-okta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-docker.sh
executable file
·72 lines (60 loc) · 1.8 KB
/
run-docker.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
DOCKER_IMAGE=${DOCKER_IMAGE:-gp-okta}
DOCKER_TAG=${DOCKER_TAG:-latest}
DOCKER_NAME=${DOCKER_NAME:-gp-okta}
CONFIG=${CONFIG:-$1}
CONFIG=${CONFIG:-gp-okta.conf}
conf_username=$(grep "^username" ${CONFIG} | awk -F \= '{print $2}' | tr -d " ")
conf_password=$(grep "^password" ${CONFIG} | awk -F \= '{print $2}' | tr -d " ")
### detect where username is filled in
if [[ "${conf_username}" ]]; then
GP_USERNAME=${conf_username}
fi
if [[ -z "${conf_username}" && -z "${GP_USERNAME}" ]]; then
read -p "Enter Okta username: " GP_USERNAME
fi
### detect where password is filled in
if [[ "${conf_password}" ]]; then
GP_PASSWORD=${conf_password}
fi
if [[ -z "${conf_password}" && -z "${GP_PASSWORD}" ]]; then
read -s -p "Enter Okta password: " GP_PASSWORD
echo
fi
# If no TOTP secrets are specified, prompt for OTP.
totp_secrets=$(grep "^totp." ${CONFIG} | awk -F \= '{print $2}' | tr -d " ")
if [[ -z "${totp_secrets}" ]]; then
read -p "Enter MFA OTP code: " totp
fi
echo
docker run \
-d \
--name=${DOCKER_NAME} \
--rm \
--privileged \
--net=host \
--cap-add=NET_ADMIN \
--device /dev/net/tun \
-e GP_USERNAME=${GP_USERNAME} \
-e GP_PASSWORD=${GP_PASSWORD} \
-e GP_TOTP_CODE=${totp} \
-e GP_EXECUTE=1 \
-e GP_OPENCONNECT_CMD=/usr/local/sbin/openconnect \
-v /etc/resolv.conf:/etc/resolv.conf \
-v $(readlink -f ${CONFIG}):/etc/gp-okta.conf \
${DOCKER_IMAGE}:${DOCKER_TAG} \
> /dev/null
# Watch output for successful, for a little while at least
( timeout 30 docker logs -f ${DOCKER_NAME} & ) | sed '/Connected as/q'
# If container is gone, something went awry
echo
echo
if [ -z "$(docker ps -q -f name=${DOCKER_NAME})" ]; then
echo
echo
echo "VPN failed to start!"
exit 1
else
echo "VPN running"
exit 0
fi