commit:     ca76f01b51e1fe77cbd85e0ff15892209b6624bc
Author:     Jason A. Donenfeld <zx2c4 <AT> gentoo <DOT> org>
AuthorDate: Thu Aug  6 15:19:58 2020 +0000
Commit:     Jason A. Donenfeld <zx2c4 <AT> gentoo <DOT> org>
CommitDate: Thu Aug  6 15:20:31 2020 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ca76f01b

net-vpn/wireguard-tools: add init script

Closes: https://github.com/gentoo/gentoo/pull/16794
Closes: https://bugs.gentoo.org/672582
Package-Manager: Portage-3.0.1, Repoman-2.3.23
Signed-off-by: Jason A. Donenfeld <zx2c4 <AT> gentoo.org>

 net-vpn/wireguard-tools/files/wg-quick.init        | 35 ++++++++++++++++++++++
 .../wireguard-tools-1.0.20200513.ebuild            |  1 +
 2 files changed, 36 insertions(+)

diff --git a/net-vpn/wireguard-tools/files/wg-quick.init 
b/net-vpn/wireguard-tools/files/wg-quick.init
new file mode 100644
index 00000000000..ad687410405
--- /dev/null
+++ b/net-vpn/wireguard-tools/files/wg-quick.init
@@ -0,0 +1,35 @@
+#!/sbin/openrc-run
+# Copyright 2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+name="WireGuard"
+description="WireGuard via wg-quick(8)"
+
+depend() {
+       need net
+       use dns
+}
+
+CONF="${SVCNAME#*.}"
+
+checkconfig() {
+       if [ "$CONF" = "$SVCNAME" ]; then
+               eerror "You cannot call this init script directly. You must 
create a symbolic link to it with the configuration name:"
+               eerror "    ln -s /etc/init.d/wg-quick 
/etc/init.d/wg-quick.vpn0"
+               eerror "And then call it instead:"
+               eerror "    /etc/init.d/wg-quick.vpn0 start"
+               return 1
+       fi
+}
+
+start() {
+       ebegin "Starting $description for $CONF"
+       wg-quick up "$CONF"
+       eend $? "Failed to start $description for $CONF"
+}
+
+stop() {
+       ebegin "Stopping $description for $CONF"
+       wg-quick down "$CONF"
+       eend $? "Failed to stop $description for $CONF"
+}

diff --git a/net-vpn/wireguard-tools/wireguard-tools-1.0.20200513.ebuild 
b/net-vpn/wireguard-tools/wireguard-tools-1.0.20200513.ebuild
index 05151edab94..17cfcbbb8f2 100644
--- a/net-vpn/wireguard-tools/wireguard-tools-1.0.20200513.ebuild
+++ b/net-vpn/wireguard-tools/wireguard-tools-1.0.20200513.ebuild
@@ -93,6 +93,7 @@ src_install() {
                SYSTEMDUNITDIR="$(systemd_get_systemunitdir)" \
                PREFIX="${EPREFIX}/usr" \
                -C src install
+       use wg-quick && newinitd "${FILESDIR}/wg-quick.init" wg-quick
 }
 
 pkg_postinst() {

Reply via email to