forked from bitrise-steplib/bitrise-step-open-vpn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
step.sh
85 lines (74 loc) · 1.92 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
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -eu
echo "OpenVPN (inside|app fork)"
echo "Configs:"
echo "host: $host"
echo "port: $port"
echo "proto: $proto"
echo "ca_crt: $(if [ ! -z "$ca_crt" ]; then echo "***"; fi)"
echo "client_crt: $(if [ ! -z "$client_crt" ]; then echo "***"; fi)"
echo "client_key: $(if [ ! -z "$client_key" ]; then echo "***"; fi)"
echo ""
log_path=$(mktemp)
envman add --key "OPENVPN_LOG_PATH" --value "$log_path"
echo "Log path exported (\$OPENVPN_LOG_PATH=$log_path)"
echo ""
case "$OSTYPE" in
linux*)
echo "Configuring for Ubuntu"
echo ${ca_crt} | base64 -d > /etc/openvpn/ca.crt
echo ${client_crt} | base64 -d > /etc/openvpn/client.crt
echo ${client_key} | base64 -d > /etc/openvpn/client.key
cat <<EOF > /etc/openvpn/client.conf
client
dev tun
proto ${proto}
remote ${host} ${port}
resolv-retry infinite
nobind
persist-key
persist-tun
verb 3
ca ca.crt
cert client.crt
key client.key
cipher ${cipher}
EOF
echo ""
echo "Run openvpn"
service openvpn start client > $log_path 2>&1
echo "Done"
echo ""
echo "Check status"
sleep 5
if ! ifconfig | grep tun0 > /dev/null ; then
echo "No open VPN tunnel found"
cat "$log_path"
exit 1
fi
echo "Done"
;;
darwin*)
echo "Configuring for Mac OS"
echo ${ca_crt} | base64 -D -o ca.crt
echo ${client_crt} | base64 -D -o client.crt
echo ${client_key} | base64 -D -o client.key
echo ""
echo "Run openvpn"
sudo openvpn --client --dev tun --proto ${proto} --remote ${host} ${port} --resolv-retry infinite --nobind --persist-key --persist-tun --verb 3 --cipher ${cipher} --ca ca.crt --cert client.crt --key client.key > $log_path 2>&1 &
echo "Done"
echo ""
echo "Check status"
sleep 5
if ! ps -p $! >&-; then
echo "Process exited"
cat "$log_path"
exit 1
fi
echo "Done"
;;
*)
echo "Unknown operative system: $OSTYPE, exiting"
exit 1
;;
esac