commit:     55f4303617ecd81f8729e8f45a64d14a4a0df41b
Author:     Rabi Shanker Guha <guha.rabishankar <AT> gmail <DOT> com>
AuthorDate: Fri Jan  9 15:06:25 2015 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Fri Jan  9 15:06:25 2015 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/netifrc.git;a=commit;h=55f43036

Systemd Wrapper: to be called from unit file

---
 sh/systemd-wrapper.sh.in | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/sh/systemd-wrapper.sh.in b/sh/systemd-wrapper.sh.in
new file mode 100644
index 0000000..d931200
--- /dev/null
+++ b/sh/systemd-wrapper.sh.in
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+CONFDIR="@CONFDIR@"
+LIBEXECDIR="@LIBEXECDIR@/sh"
+INITDIR="@INITDIR@"
+INIT=systemd
+
+usage() {
+  echo "netifrc systemd wrapper"
+  echo "Usage:"
+  echo "  systemd-wrapper.sh -i <interface> <command>"
+  echo "  where command is start|stop"
+}
+
+die() {
+  echo "$@"
+  exit -1
+}
+
+while getopts "i:" opt; do
+  case $opt in
+       i)
+               RC_IFACE=$OPTARG;;
+  esac
+done
+shift $((OPTIND -1))
+
+[ -z "$RC_IFACE" ] && die "Missing Parameter Interface"
+
+RC_SVCPREFIX="net"
+RC_SVCNAME="$RC_SVCPREFIX"."$RC_IFACE"
+RC_UNAME=$(uname)
+# XXX Find out the systemd way of doing this
+RC_GOINGDOWN=no
+
+# In Openrc systems this has value /run/openrc
+SVCDIR="/run/netifrc"
+# OpenRC saves values in $SVCDIR/options/$SVCNAME/$OPTION
+# In non OpenRC setting this is saved in /run/netifrc/options/$SVCNAME/$OPTION
+OPTIONSDIR="${SVCDIR}/options/${RC_SVCNAME}"
+STATEDIR="${SVCDIR}/${RC_SVCNAME}"
+
+# Source the config file
+if [ -f "$CONFDIR/$RC_SVCPREFIX" ]; then
+       . "$CONFDIR/$RC_SVCPREFIX"
+fi
+
+# Source the actual runscript
+if [ -f "$INITDIR/${RC_SVCPREFIX}.lo" ]; then
+       . "$INITDIR/${RC_SVCPREFIX}.lo"
+else
+       echo "$INITDIR/${RC_SVCPREFIX}.lo : Init file missing or invalid path"
+       exit -1
+fi
+
+netifrc_init() {
+       # Ensure OPTIONSDIR is present and writeable
+       mkdir -p "$OPTIONSDIR"
+       if [ ! -w "$OPTIONSDIR" ]; then
+               eerror "${OPTIONSDIR} does not exist or is not writeable"
+               exit -1;
+       fi
+       # Ensure STATEDIR is present and writeable
+       mkdir -p "$STATEDIR"
+       if [ ! -w "$STATEDIR" ]; then
+               eerror "${STATEDIR} does not exist or is not writeable"
+               exit -1;
+       fi
+}
+
+netifrc_cleanup() {
+       # Delete all the saved values
+       rm -f ${OPTIONSDIR}/*
+}
+
+rc=0
+case $1 in
+       start)
+               netifrc_init
+               start
+               rc=$?;;
+       stop)
+               stop
+               netifrc_cleanup
+               rc=$?;;
+       *)
+               die "Unrecognised command $1";;
+esac
+exit $rc
+
+# vi: ts=4 sw=4 noexpandtab

Reply via email to