forked from hermanolsson/bitrise-step-open-vpn
-
Notifications
You must be signed in to change notification settings - Fork 2
/
step.sh
76 lines (65 loc) · 1.8 KB
/
step.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
73
74
75
76
#!/bin/bash
set -eu
cat <<EOF > client.ovpn
client
dev tun
route-nopull
route ${subnet1} 255.255.224.0
route ${subnet2} 255.255.224.0
proto ${proto}
remote ${host} ${port}
remote-random-hostname
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
verb 3
ca ca.crt
auth-user-pass login.conf
reneg-sec 0
status /var/log/openvpn-status.log
log /var/log/openvpn.log
EOF
case "$OSTYPE" in
linux*)
echo "Configuring for Ubuntu"
export APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1
curl -s https://swupdate.openvpn.net/repos/repo-public.gpg | apt-key add
# Remove nodesource from the repo list since it was causing some cert errors and not needed anyway.
mv /etc/apt/sources.list.d/nodesource.list /etc/apt/sources.list.d/nodesource.list.disabled || true
echo "deb http://build.openvpn.net/debian/openvpn/stable focal main" > /etc/apt/sources.list.d/openvpn-aptrepo.list
apt update -y
apt install -y net-tools dnsutils openvpn
echo ${ca_crt} | base64 -d > /etc/openvpn/ca.crt
echo ${user_pass} | base64 -d > /etc/openvpn/login.conf
cp client.ovpn /etc/openvpn/client.conf
service openvpn start client > /dev/null 2>&1
sleep 10
if ifconfig | grep tun0 > /dev/null
then
echo "VPN connection succeeded"
else
echo "VPN connection failed!"
exit 1
fi
;;
darwin*)
echo "Configuring for Mac OS"
echo ${ca_crt} | base64 -D -o ca.crt > /dev/null 2>&1
echo ${user_pass} | base64 -D -o login.conf > /dev/null 2>&1
sudo openvpn --config client.ovpn > /dev/null 2>&1 &
sleep 5
if ifconfig -l | grep utun0 > /dev/null
then
echo "VPN connection succeeded"
else
echo "VPN connection failed!"
exit 1
fi
;;
*)
echo "Unknown operative system: $OSTYPE, exiting"
exit 1
;;
esac