Last active
May 31, 2023 03:58
-
-
Save ProducerMatt/e10290452a7b446f86510212a9cad121 to your computer and use it in GitHub Desktop.
OpenBSD rc service script for the wg-quick WireGuard framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ksh | |
# rc script for wg-quick. one network only. | |
# if you have /etc/wireguard/wg0.conf, | |
# enable like this: | |
# pkg_scripts=wg_quick | |
# wg_quick_flags=wg0 | |
daemon="/usr/local/bin/wg-quick" | |
. /etc/rc.d/rc.subr | |
network=${daemon_flags} | |
wgbin="/usr/local/bin/wg" | |
#wgpid="/var/run/wireguard/${network}.name" | |
wgconf="/etc/wireguard/${network}.conf" | |
#pexp="/usr/local/bin/bash /usr/local/bin/wg-quick up" | |
rc_pre() { | |
# do either of these even work?? | |
# if no network specified, script can't work | |
test ! -z network || exit 1 | |
# if $wgconf can't be read, return an error | |
${daemon} strip "${wgconf}" > /dev/null 2>&1 | |
} | |
rc_start() { | |
${rcexec} ${daemon} up ${daemon_flags} | |
} | |
rc_reload() { | |
# this reloads without disrupting existing connections | |
# (unless they're directly effected by the changes) | |
${daemon} strip ${network} | ${wgbin} syncconf ${network} /dev/stdin | |
} | |
rc_stop() { | |
${rcexec} ${daemon} down ${network} | |
} | |
rc_check() { | |
# test -e "${wgpid}" | |
ifconfig | grep -q "${network}" | |
} | |
rc_cmd $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment