summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--COPYING14
-rw-r--r--[l---------]Makefile26
-rwxr-xr-xnetctl-hook3
-rwxr-xr-xnetwork-online51
-rw-r--r--network-online@.service7
5 files changed, 100 insertions, 1 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..ee7d6a5
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/Makefile b/Makefile
index 4ecdba5..215a0ba 120000..100644
--- a/Makefile
+++ b/Makefile
@@ -1 +1,25 @@
-build-aux/Makefile.README.mk \ No newline at end of file
+# Copyright © 2015 Luke Shumaker <lukeshu@sbcglobal.net>
+# This work is free. You can redistribute it and/or modify it under the
+# terms of the Do What The Fuck You Want To Public License, Version 2,
+# as published by Sam Hocevar. See the COPYING file for more details.
+
+PACKAGE = netctl-network-online
+VERSION = 20160101
+
+topsrcdir ?= .
+topoutdir ?= .
+include $(topsrcdir)/build-aux/Makefile.head.mk
+
+files.sys.all = \
+ $(sysconfdir)/netctl/hooks/network-online \
+ $(prefix)/lib/systemd/system/network-online@.service \
+ $(prefix)/lib/network/network-online
+
+$(DESTDIR)$(sysconfdir)/netctl/hooks/network-online: netctl-hook
+ install -Dm755 $< $@
+$(DESTDIR)$(prefix)/lib/systemd/system/network-online@.service: network-online@.service
+ install -Dm644 $< $@
+$(DESTDIR)$(prefix)/lib/network/network-online: network-online
+ install -Dm755 $< $@
+
+include $(topsrcdir)/build-aux/Makefile.tail.mk
diff --git a/netctl-hook b/netctl-hook
new file mode 100755
index 0000000..01f8619
--- /dev/null
+++ b/netctl-hook
@@ -0,0 +1,3 @@
+#!/hint/bash
+printf -v ExecUpPost "systemctl start network-online@%q.service" "$(systemd-escape -- "$Profile")"
+printf -v ExecDownPre "systemctl stop network-online@%q.service" "$(systemd-escape -- "$Profile")"
diff --git a/network-online b/network-online
new file mode 100755
index 0000000..e04eee9
--- /dev/null
+++ b/network-online
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# Copyright © 2015-2016 Luke Shumaker <lukeshu@sbcglobal.net>
+# This work is free. You can redistribute it and/or modify it under the
+# terms of the Do What The Fuck You Want To Public License, Version 2,
+# as published by Sam Hocevar. See the COPYING file for more details.
+
+# Usage: network-online [start|stop] NETWORK_NAME
+mode="$1"
+lock=/run/network-online/lock
+fifo=/run/network-online/"$2"
+PS4="$mode: "
+
+# Use a named pipe (fifo) as an inter-process synchronization
+# mechanism; a call to block_{a,b} blocks until its counterpart is
+# run.
+block_a() {
+ cat "$fifo" >/dev/null
+}
+block_b() {
+ echo foo >> "$fifo"
+}
+
+# Because of restrictions put in place by systemd, the ExecStart
+# process can't run `systemctl stop network-online.target`, but the
+# ExecStop process can.
+case "$mode" in
+ start)
+ trap 'rm -f -- "$fifo"' EXIT
+ set -x
+ mkdir -p /run/network-online || exit $?
+ exec 8>"$lock" || exit $?
+ flock -s 8 || exit $?
+ systemctl start network-online.target || exit $?
+ mkfifo "$fifo" || exit $?
+
+ block_a # wait for 'stop' to be called
+ exec 8>&-
+ block_a # signal to 'stop' that we've unlocked
+ ;;
+ stop)
+ set -x
+ exec 8>"$lock" || exit $?
+ flock -s 8 || exit $?
+ block_b # signal 'start' to stop
+ block_b # wait for 'start' to unlock
+ if flock -x -n 8; then
+ systemctl stop network-online.target
+ rm -rf /run/network-online
+ fi
+ ;;
+esac
diff --git a/network-online@.service b/network-online@.service
new file mode 100644
index 0000000..90195f9
--- /dev/null
+++ b/network-online@.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Network %I is online
+
+[Service]
+Type=simple
+ExecStart=/lib/network/network-online start %I
+ExecStop=/lib/network/network-online stop %I