forked from kral2/docker_proxy_vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_proxy_vpn.sh.sample
executable file
·69 lines (59 loc) · 2.4 KB
/
start_proxy_vpn.sh.sample
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
#!/bin/sh
# Last update : April, 2021
# Author: cetin.ardal@oracle.com
# Description: Launch a proxy_vpn container if there is none running
script_name=$(basename "$0")
version="1.1.0"
echo "running $script_name - version $version"
TEST_URL=https://<myprivatewebsite.com> # enter an URL that should be accessible only with VPN UP
MYPORT=3233
VPN_NAME="<My Corp>" # name your vpn
CONTAINER=myvpn_corp
IMAGE=proxy_vpn:2021.12 # get the exact image name and tag from 0_build_image.sh output
LOGS_DIR=$HOME/containers_logs/squid
# start podman machine before starting the container
podman_machine_status=$(podman machine list --format '{{.LastUp}}')
if [ "$podman_machine_status" != "Currently running" ]; then
podman machine start
else
echo "podman machine is $podman_machine_status"
fi
# Create $CONTAINER if it is not RUNNING
if [ ! "$(podman ps -q -f name=$CONTAINER)" ]; then
echo "No $CONTAINER container running."
# check if there is no EXITED container named $CONTAINER. Cleanup if there is.
if [ "$(podman ps -aq -f status=exited -f name=$CONTAINER)" ]; then
echo "$CONTAINER container found in exited status -> Cleanup and recreate."
podman rm $CONTAINER
fi
echo "Launching podman container for $VPN_NAME with image $IMAGE"
podman run --name $CONTAINER --env-file $(dirname $(realpath $0))/env.list --privileged -p $MYPORT:$MYPORT -d $IMAGE #-v $LOGS_DIR:/var/log/squid
else
echo "$CONTAINER container is already running."
fi
# Test if $TEST_URL is reachable (intranet resource)
export http_proxy=localhost:$MYPORT
export https_proxy=localhost:$MYPORT
echo "Testing connection status with $TEST_URL ..."
wget -q -O - $TEST_URL >/dev/null
WGET_ERROR_CODE=$?
# Wait for 30s until $TEST_URL is reachable or exit
WAIT_TIMEOUT=0
while [ $WGET_ERROR_CODE -ne 0 ] && [ $WAIT_TIMEOUT -ne 30 ]
do
echo "Proxy_VPN not yet available. WGET Error code=$WGET_ERROR_CODE ..."
sleep 5
wget -q -O - $TEST_URL >/dev/null
WGET_ERROR_CODE=$?
WAIT_TIMEOUT=$((WAIT_TIMEOUT + 5))
done
# Evaluate status and inform user
if [ $WGET_ERROR_CODE -eq 0 ]; then
# Success: Intranet resources reachable
echo "Proxy_VPN is ready"
podman exec $CONTAINER squid -v |grep Version
podman exec $CONTAINER openconnect -V |grep version
else
# Failure: Intranet resources unreachable
echo "-> Error: $TEST_URL is unreachable. Check your $CONTAINER container entrypoint script."
fi