-
Notifications
You must be signed in to change notification settings - Fork 6
/
orb.yml
82 lines (79 loc) · 2.6 KB
/
orb.yml
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
version: 2.1
description: OpenVPN client Orb
executors:
default:
description: |
"Tested only on the CircleCI machine executor, but should work
on most debian/ubuntu based images as well"
machine: true
commands:
install:
description: "Install OpenVPN client"
steps:
- run:
name: Install OpenVPN
command: |
# There seems to be a bug with the openvpn aptrepo sources
sudo apt-get update # for apt-get to recognise openvpn
sudo apt-get remove openvpn # remove ubuntu aptrepo source
sudo apt-get update
sudo apt-get install openvpn -y
connect:
description: "Connect to OpenVPN"
parameters:
config:
description: |
"ENV var name containing OpenVPN client .ovpn config file content base64 encoded"
type: env_var_name
default: VPN_CONFIG
login:
description: |
"ENV var name containing OpenVPN newline separated username and password base64 encoded"
type: env_var_name
default: VPN_LOGIN
steps:
- run:
name: Init VPN
command: |
echo ${<<parameters.config>>:?} | base64 --decode >> config.ovpn
echo ${<<parameters.login>>:?} | base64 --decode >> vpn.login
- run:
name: Connect to VPN
command: |
wget -qO- http://checkip.amazonaws.com | tee initial.ip
sudo openvpn --config config.ovpn --auth-user-pass vpn.login > openvpn.log 2>&1 &
while [ -n "$(ip addr show tun0 2>&1 > /dev/null)" ]; do
sleep 0.1;
done
cat openvpn.log
wget -qO- http://checkip.amazonaws.com | tee final.ip
if [ "$(cat initial.ip)" == "$(cat final.ip)" ]
then
echo "This computer's apparent public IP address was not different after connecting"
echo "This may mean that your VPN is not configured correctly."
exit 1
fi
disconnect:
description: "Disconnect from OpenVPN"
steps:
- run:
name: Disconnect from VPN
command: sudo killall openvpn || true
- run:
name: remove OpenVPN config
command: sudo rm config.ovpn
example:
secure-ping:
description: "Establish VPN connection and execute a command within it"
usage:
version: 2.1
orbs:
vpn: titel-media/openvpn@0.0.1
jobs:
ping:
executor: vpn/default
steps:
- vpn/install
- vpn/connect
- run: ping -c 5 192.0.2.1
- vpn/disconnect