-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_config.sh
executable file
·68 lines (56 loc) · 2.38 KB
/
update_config.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
#!/bin/bash
set -o allexport
source .env
set +o allexport
if [ $(id -u) -gt 0 ] ; then
echo "Please run this script as root or via sudo"
exit 1
fi
echo "Using configuration from '$WIREGUARD_STAGING_CONFIG_DIRECTORY'"
mkdir -p /etc/wireguard-web
for interface in $(cat "${WIREGUARD_STAGING_CONFIG_DIRECTORY}"/interfaces.conf) ; do
file="${WIREGUARD_STAGING_CONFIG_DIRECTORY}/wg-quick/${interface}.conf"
dnsmasq_config="${WIREGUARD_STAGING_CONFIG_DIRECTORY}/dnsmasq/dnsmasq-${interface}.conf"
echo "Copying configuration for interface ${interface}..."
echo " - wg-quick"
install -o root -g root -m 0640 "${file}" "/etc/wireguard-web/${interface}.conf"
if [ -f "${dnsmasq_config}" ] ; then
echo " - dnsmasq"
install -o root -g root -m 0640 "${dnsmasq_config}" "/etc/wireguard-web/dnsmasq-${interface}.conf"
fi
echo "Checking if services are enabled for ${interface}..."
if [ "$(systemctl is-enabled wireguard-web-wg-quick@${interface})" = "disabled" ] ; then
echo " - enabling wg-quick service now"
systemctl enable --now wireguard-web-wg-quick@${interface}
else
echo " - reloading wg-quick"
systemctl reload "wireguard-web-wg-quick@${interface}"
fi
if [ -f "${dnsmasq_config}" ] ; then
if [ "$(systemctl is-enabled wireguard-web-dnsmasq@${interface})" = "disabled" ] ; then
echo " - enabling dnsmasq service now"
systemctl enable --now wireguard-web-dnsmasq@${interface}
else
echo " - restarting dnsmasq"
systemctl restart "wireguard-web-dnsmasq@${interface}"
fi
fi
done
# disable services not in use anymore
disable=$(
(
cat "${WIREGUARD_STAGING_CONFIG_DIRECTORY}"/interfaces.conf
LC_ALL=C systemctl list-units|grep wireguard-web-wg-quick|sed -e '/.slice/d' -e 's/\**\s*wireguard-web-wg-quick@\([^.]*\).service.*/\1/'
) | sort | uniq -u
)
echo "Disabling services not in use anymore..."
for interface in ${disable} ; do
echo " - wg-quick ${interface}"
systemctl disable --now wireguard-web-wg-quick@${interface}
rm -f "/etc/wireguard-web/${interface}.conf"
if [ -f "/etc/wireguard-web/dnsmasq-${interface}.conf" ] ; then
echo " - dnsmasq ${interface}"
systemctl disable --now wireguard-web-dnsmasq@${interface}
rm -f "/etc/wireguard-web/dnsmasq-${interface}.conf"
fi
done