From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-763389-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id ECA0B138ACF
	for <garchives@archives.gentoo.org>; Fri,  9 Jan 2015 17:17:55 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id DD9C9E084E;
	Fri,  9 Jan 2015 17:17:52 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 1F910E084E
	for <gentoo-commits@lists.gentoo.org>; Fri,  9 Jan 2015 17:17:52 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 03210340719
	for <gentoo-commits@lists.gentoo.org>; Fri,  9 Jan 2015 17:17:51 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id A3F03F375
	for <gentoo-commits@lists.gentoo.org>; Fri,  9 Jan 2015 17:17:49 +0000 (UTC)
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" <robbat2@gentoo.org>
Message-ID: <1420815985.55f4303617ecd81f8729e8f45a64d14a4a0df41b.robbat2@OpenRC>
Subject: [gentoo-commits] proj/netifrc:master commit in: sh/
X-VCS-Repository: proj/netifrc
X-VCS-Files: sh/systemd-wrapper.sh.in
X-VCS-Directories: sh/
X-VCS-Committer: robbat2
X-VCS-Committer-Name: Robin H. Johnson
X-VCS-Revision: 55f4303617ecd81f8729e8f45a64d14a4a0df41b
X-VCS-Branch: master
Date: Fri,  9 Jan 2015 17:17:49 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: eb856d53-3377-464f-bd3e-03529017910b
X-Archives-Hash: 3c8e049c41a524b141250c5f74a78ea7

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