-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpia-launch.sh
executable file
·70 lines (52 loc) · 1.33 KB
/
pia-launch.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
#!/bin/sh
# Check for root
if [[ "$EUID" != 0 ]]; then
echo "Please run as root"
exit
fi
# Check for required files/directories
dir="/etc/openvpn/privateinternetaccess/"
if [[ -d $dir ]]; then
cd $dir
else
echo "$dir does not exist"
exit
fi
if [[ ! -f "$dir/resolv.conf" ]]; then
echo "Missing resolv.conf file"
exit
fi
if [[ ! -f "$dir/ca.rsa.2048.crt" || ! -f "$dir/crl.rsa.2048.pem" ]]; then
echo "Missing ca.rsa.2048.crt and crl.rsa.2048.pem file"
exit
fi
if [[ ! -f "$dir/auth/auth.ovpn" || ! -f "$dir/auth/credentials.txt" ]]; then
echo "Please create auth/auth.ovpn and auth/credentials.txt"
exit
fi
# Present user with list to choose from
i=1
for file in *.ovpn; do
if [[ $file == "*.ovpn" ]]; then #No .ovpn files
echo "Please place .ovpn files in $dir"
exit
fi
menu[$i]="$i) ${file%.*}"$'\n'
servers[$i]="$file"
(( i++ ))
done
while true; do
echo " ${menu[@]}" | column
read -p "Choose a server to connect to: " selection
server=${servers[$selection]}
if [[ $server != '' ]]; then
break
fi
done
# Setup DNS
mv /etc/resolv.conf /etc/resolv.conf.bak
cp ./resolv.conf /etc/resolv.conf
# Run OpenVPN
openvpn --config "$server" --config "auth/auth.ovpn"
# Reset DNS once VPN connection closed
mv /etc/resolv.conf.bak /etc/resolv.conf