algo/roles/wireguard/files/wireguard.sh
Jack Ivanov dbd68aa97d WireGuard BSD (#1083)
* WireGuard BSD

* Remove unneeded config option

* Enable PersistentKeepalive for NAT and Firewall Traversal Persistence

* Install dnscrypt-proxy from repositories
2018-09-27 04:18:12 -04:00

40 lines
729 B
Bash

#!/bin/sh
# PROVIDE: wireguard
# REQUIRE: LOGIN
# BEFORE: securelevel
# KEYWORD: shutdown
. /etc/rc.subr
name="wg"
rcvar=wg_enable
command="/usr/local/bin/wg-quick"
start_cmd=wg_up
stop_cmd=wg_down
status_cmd=wg_status
pidfile="/var/run/$name.pid"
load_rc_config "$name"
: ${wg_enable="NO"}
: ${wg_interface="wg0"}
wg_up() {
echo "Starting WireGuard..."
/usr/sbin/daemon -cS -p ${pidfile} ${command} up ${wg_interface}
}
wg_down() {
echo "Stopping WireGuard..."
${command} down ${wg_interface}
}
wg_status () {
not_running () {
echo "WireGuard is not running on $wg_interface" && exit 1
}
/usr/local/bin/wg show wg0 && echo "WireGuard is running on $wg_interface" || not_running
}
run_rc_command "$1"