diff options
Diffstat (limited to 'files/wireguard')
-rwxr-xr-x | files/wireguard/mwg.init | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/files/wireguard/mwg.init b/files/wireguard/mwg.init new file mode 100755 index 0000000..4e9d45d --- /dev/null +++ b/files/wireguard/mwg.init @@ -0,0 +1,39 @@ +#!/sbin/openrc-run +# Copyright 1999-2018 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +depend() { + use logger +} + +reload() { + if [ -z "$IP" ]; then + eerror "Variable IP has to be defined in service config file" + exit 1 + fi + + ip link set down dev mwg + + ip addr flush mwg + ip addr add "$IP/24" dev mwg + + wg setconf mwg "/etc/mwg/config" + + ip link set up dev mwg +} + +start() { + # Add wireguard interface + if ! ip link list mwg 2>/dev/null >&2; then + ip link add dev mwg type wireguard + fi + # Reload/Load + reload + + mark_service_started +} + +stop() { + # Remove wireguard interface + ip link del dev mwg || true +} |