~fkooman/vpn-maint-scripts

ref: c4291d418191c4ac07d3f90a3fe9f354c28ea6d3 vpn-maint-scripts/bin/vpn-maint-apply-changes -rwxr-xr-x 1.4 KiB
c4291d41François Kooman remove some old CentOS stuff 6 months ago
                                                                                
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
#!/bin/sh

if ! [ "root" = "$(id -u -n)" ]; then
    echo "ERROR: ${0} must be run as root!"; exit 1
fi

# Disable & Stop OpenVPN
for CONFIG_NAME in $(systemctl list-units "openvpn-server@*" --no-legend | awk '{print $1}')
do
    systemctl disable --now "${CONFIG_NAME}"
done

# Disable & Stop WireGuard
for CONFIG_NAME in $(systemctl list-units "wg-quick@*" --no-legend | awk '{print $1}')
do
    systemctl disable --now "${CONFIG_NAME}"
done

# Delete OpenVPN Configuration
rm -rf /etc/openvpn/server/* 
rm -rf /etc/wireguard/*

if ! /usr/libexec/vpn-server-node/server-config; then
    exit 1
fi

# Enable & Start OpenVPN
for F in /etc/openvpn/server/*.conf
do
    case ${F} in
        *.conf)
            CONFIG_NAME=$(basename "${F}" .conf)
            systemctl enable --now "openvpn-server@${CONFIG_NAME}"
        ;;
    esac
done

# Enable & Start WireGuard
for F in /etc/wireguard/*.conf
do
    case ${F} in
        *.conf)
            CONFIG_NAME=$(basename "${F}" .conf)
            systemctl enable --now "wg-quick@${CONFIG_NAME}"
        ;;
    esac
done

# sync with vpn-daemon, no need to wait for the cron, but *ONLY* do this when
# this is a machine with vpn-user-portal installed
if [ -d /etc/vpn-user-portal ]; then
    if [ -f /etc/redhat-release ]; then
        sudo -u apache /usr/libexec/vpn-user-portal/daemon-sync
    fi
    if [ -f /etc/debian_version ]; then
        sudo -u www-data /usr/libexec/vpn-user-portal/daemon-sync
    fi
fi