-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
54 lines (43 loc) · 1.08 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
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# Connect to random vpn endpoint
#
# Required environment variables:
# - purevpn_username
# - purevpn_password
set -e
# verify PureVPN installed
if ! which purevpn > /dev/null; then
echo "ERROR: purevpn package is missing"
exit 2
fi
ORIG_IP=$(curl -s 'icanhazip.com')
echo "Current IP: ${ORIG_IP}"
# start purevpn service
service purevpn start
# login to purevpn
expect <<EOD
spawn purevpn --login
expect "Username:"
send "${purevpn_username}\r"
expect "Password:"
send "${purevpn_password}\r"
expect #
EOD
# get all location codes
LOCATIONS=$(purevpn --location | grep -o -E '[A-Z]{2}')
ARRAY=(${LOCATIONS//:/ })
LEN=${#ARRAY[@]}
# select random one
RANDOM_LOCATION=${ARRAY[$((RANDOM % $LEN))]}
# connect
echo "Connecting to ${RANDOM_LOCATION}..."
purevpn --connect "${RANDOM_LOCATION}"
# fix resolve
echo "nameserver 8.8.8.8" > /etc/resolv.conf
service purevpn restart
systemctl restart danted
NEW_IP=$(curl -s 'icanhazip.com')
echo "Original IP: ${ORIG_IP}"
echo "New IP (${RANDOM_LOCATION}): ${NEW_IP}"
exec "$@"