Skip to content

Commit 7abd8ae

Browse files
committed
provision changes for parse ovpn file
1 parent 2cf5a34 commit 7abd8ae

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

config/pia/default/default.ovpn

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
client
2+
dev tun
3+
proto udp
4+
remote nl.privateinternetaccess.com 1198
25
resolv-retry infinite
36
nobind
47
persist-key

config/pia/strong/strong.ovpn

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
client
2+
dev tun
3+
proto udp
4+
remote nl.privateinternetaccess.com 1197
25
resolv-retry infinite
36
nobind
47
persist-key

setup/root/start.sh

+12-19
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ else
2424
# if ovpn filename is not custom.ovpn and the provider is pia then copy included ovpn and certs
2525
if [[ "${VPN_CONFIG}" != "/config/openvpn/custom.ovpn" && "${VPN_PROV}" == "pia" ]]; then
2626

27-
# remove previous certs and ovpn files, user may of switched to strong
28-
rm -f /config/openvpn/*
29-
3027
if [[ "${STRONG_CERTS}" == "yes" ]]; then
3128

3229
echo "[info] VPN strong certs defined, copying to /config/openvpn/..."
3330

34-
# copy strong encrption ovpn and certs
31+
# copy strong encryption ovpn and certs
3532
cp -f /home/nobody/certs/strong/*.crt /config/openvpn/
3633
cp -f /home/nobody/certs/strong/*.pem /config/openvpn/
3734
cp -f "/home/nobody/certs/strong/strong.ovpn" "/config/openvpn/openvpn.ovpn"
@@ -40,7 +37,7 @@ else
4037

4138
echo "[info] VPN default certs defined, copying to /config/openvpn/..."
4239

43-
# copy default encrption ovpn and certs
40+
# copy default encryption ovpn and certs
4441
cp -f /home/nobody/certs/default/*.crt /config/openvpn/
4542
cp -f /home/nobody/certs/default/*.pem /config/openvpn/
4643
cp -f "/home/nobody/certs/default/default.ovpn" "/config/openvpn/openvpn.ovpn"
@@ -68,7 +65,7 @@ else
6865
/usr/bin/dos2unix "${VPN_CONFIG}"
6966

7067
if [[ "${VPN_PROV}" == "pia" ]]; then
71-
68+
7269
if [[ "${VPN_PROTOCOL}" == "udp" && "${VPN_PORT}" != "1198" && "${STRONG_CERTS}" != "yes" ]]; then
7370
echo "[warn] VPN provider remote port incorrect, overriding to 1198"
7471
VPN_PORT="1198"
@@ -77,20 +74,18 @@ else
7774
echo "[warn] VPN provider remote port incorrect, overriding to 1197"
7875
VPN_PORT="1197"
7976

80-
8177
elif [[ "${VPN_PROTOCOL}" == "tcp" && "${VPN_PORT}" != "502" && "${STRONG_CERTS}" != "yes" ]]; then
8278
echo "[warn] VPN provider remote port incorrect, overriding to 502"
8379
VPN_PORT="502"
8480

85-
8681
elif [[ "${VPN_PROTOCOL}" == "tcp" && "${VPN_PORT}" != "501" && "${STRONG_CERTS}" == "yes" ]]; then
8782
echo "[warn] VPN provider remote port incorrect, overriding to 501"
8883
VPN_PORT="501"
8984
fi
9085
fi
9186

92-
# if vpn provider not airvpn then write credentials to file (airvpn uses certs for authentication)
93-
if [[ "${VPN_PROV}" != "airvpn" ]]; then
87+
# if vpn username and password specified then write credentials to file (authentication maybe via keypair)
88+
if [[ ! -z "${VPN_USER}" && ! -z "${VPN_PASS}" ]]; then
9489

9590
# store credentials in separate file for authentication
9691
if ! $(grep -Fq "auth-user-pass credentials.conf" "${VPN_CONFIG}"); then
@@ -130,19 +125,17 @@ else
130125
sed -i '/reneg-sec.*/d' "${VPN_CONFIG}"
131126
fi
132127

133-
# disable proto from ovpn file if present, defined via env variable and passed to openvpn via command line argument
134-
if $(grep -Fq "proto" "${VPN_CONFIG}"); then
135-
sed -i -e 's~^proto\s~# Disabled, as we pass this value via env var\n;proto ~g' "${VPN_CONFIG}"
128+
# write env vars to ovpn file (used as phased approach to parse ovpn file)
129+
if [[ ! -z "${VPN_PROTOCOL}" ]]; then
130+
sed -i -r "s~^;?proto\s.*~proto ${VPN_PROTOCOL}~g" "${VPN_CONFIG}"
136131
fi
137132

138-
# disable remote from ovpn file if present, defined via env variable and passed to openvpn via command line argument
139-
if $(grep -Fq "remote" "${VPN_CONFIG}"); then
140-
sed -i -e 's~^remote\s~# Disabled, as we pass this value via env var\n;remote ~g' "${VPN_CONFIG}"
133+
if [[ ! -z "${VPN_REMOTE}" && ! -z "${VPN_PORT}" ]]; then
134+
sed -i -r "s~^;?remote\s.*~remote ${VPN_REMOTE} ${VPN_PORT}~g" "${VPN_CONFIG}"
141135
fi
142136

143-
# disable dev from ovpn file if present, defined via env variable and passed to openvpn via command line argument
144-
if $(grep -Fq "dev" "${VPN_CONFIG}"); then
145-
sed -i -e 's~^dev\s~# Disabled, as we pass this value via env var\n;dev ~g' "${VPN_CONFIG}"
137+
if [[ ! -z "${VPN_DEVICE_TYPE}" ]]; then
138+
sed -i -r "s~^;?dev\s.*~dev ${VPN_DEVICE_TYPE}~g" "${VPN_CONFIG}"
146139
fi
147140

148141
# create the tunnel device

0 commit comments

Comments
 (0)