-
Notifications
You must be signed in to change notification settings - Fork 21
/
run
executable file
·79 lines (59 loc) · 2.14 KB
/
run
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
#!/usr/bin/env bash
# shellcheck disable=SC2034,SC2154
# SC2034: foo appears unused. Verify it or export it.
# SC2154: var is referenced but not assigned.
set -eu
INSTALLER=/etc/.pivpn/auto_install/install.sh
# Skip execution when sourcing the INSTALLER
PIVPN_TEST=true
# shellcheck disable=SC1090
source "${INSTALLER}"
# main procedural
{
# Variables are needed in the functions call later.
useUpdateVars=true
PLAT=Ubuntu
SUDO=
SUDOE=
# shellcheck disable=SC1091
source /etc/pivpn/setupVars.conf
PROTO=$pivpnProto
# The right way to test if a variable is unset or not.
# See https://stackoverflow.com/a/13864829
if [ -z ${IPv4dns+x} ]; then
IPv4dns=$(nslookup 127.0.0.1 | grep Server: | awk '{print $2}')
fi
if [ -z ${PUBLICDNS+x} ]; then
if ! PUBLICDNS=$(dig +short myip.opendns.com @resolver1.opendns.com)
then
echo "dig failed, now trying to curl eth0.me"
if ! PUBLICDNS=$(curl eth0.me)
then
echo "eth0.me failed, please check your internet connection/DNS"
exit $?
fi
fi
fi
keys=(pivpnInterface IPv4addr IPv4gw IPv4dns)
for k in "${keys[@]}"; do
sed -i "s/#${k}#/${!k}/g" "${dhcpcdFile}"
done
# This variable is initialized in confOpenVPN but also used in confOVPN.
# We make it globalized so as to transit to the second function.
SERVER_NAME=
# Call functions in the INSTALLER
confOpenVPN
confNetwork
confOVPN
sed -i '0,/\(dhcp-option DNS \)/ s/\(dhcp-option DNS \).*/\1'${OVPNDNS1}'\"/' /etc/openvpn/server.conf
sed -i '0,/\(dhcp-option DNS \)/! s/\(dhcp-option DNS \).*/\1'${OVPNDNS2}'\"/' /etc/openvpn/server.conf
finalExports
printf "\\n::: Clean up ovpn profile folder\\n"
rm -rf /home/"${pivpnUser}"/ovpns/*
printf "\\n::: Installation Complete!\\n\\n"
# Generate the client ovpn profile
# pivpn with exit code 1 even on success
pivpn -a -n "${CLIENT_NAME}" -p "${CLIENT_PASS}" || true
printf "\\n\\n::: PiVPN Service Started\\n"
openvpn --config /etc/openvpn/server.conf
} 2>&1 | tee "${instalLogLoc}"