Skip to content

Instantly share code, notes, and snippets.

@ProducerMatt
Last active May 31, 2023 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProducerMatt/e10290452a7b446f86510212a9cad121 to your computer and use it in GitHub Desktop.
Save ProducerMatt/e10290452a7b446f86510212a9cad121 to your computer and use it in GitHub Desktop.
OpenBSD rc service script for the wg-quick WireGuard framework
#!/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