From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id A925A138AD0 for ; Fri, 9 Jan 2015 17:17:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 608AEE085E; Fri, 9 Jan 2015 17:17:53 +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 3AD91E085D for ; 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 E61DF3406E3 for ; Fri, 9 Jan 2015 17:17:50 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 92440F36C for ; Fri, 9 Jan 2015 17:17:49 +0000 (UTC) From: "Robin H. Johnson" 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" Message-ID: <1420815748.a3444e9abf16ecb6145e95a891433b3a79800170.robbat2@OpenRC> Subject: [gentoo-commits] proj/netifrc:master commit in: sh/ X-VCS-Repository: proj/netifrc X-VCS-Files: sh/functions.sh X-VCS-Directories: sh/ X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: a3444e9abf16ecb6145e95a891433b3a79800170 X-VCS-Branch: master Date: Fri, 9 Jan 2015 17:17:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 10d05d9a-d3c2-4547-9ef9-f22107d7040f X-Archives-Hash: 3b80950db49d5e003669dd4cad5515bb commit: a3444e9abf16ecb6145e95a891433b3a79800170 Author: Rabi Shanker Guha gmail com> AuthorDate: Fri Jan 9 15:02:28 2015 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Fri Jan 9 15:02:28 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/netifrc.git;a=commit;h=a3444e9a Compatibility layer for multiple init systems --- sh/functions.sh | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/sh/functions.sh b/sh/functions.sh new file mode 100644 index 0000000..368bb73 --- /dev/null +++ b/sh/functions.sh @@ -0,0 +1,126 @@ +# Compatibility layer for netifrc to work with multiple init +# systems. + +# First check whether e* commands are present in the environment +# XXX [[-n RC_GOT_FUNCTIONS]] ?? +if [ -n "$(command -v ebegin >/dev/null 2>&1)" ]; then + : + +# Then check for the presence of functions.sh +elif [ -f /lib/gentoo/functions.sh ]; then + . /lib/gentoo/functions.sh + +else + echo "/lib/gentoo/functions.sh not found. Exiting" + exit -1 +fi + +# runscript functions +if [ -z "$(command -v service_set_value >/dev/null 2>&1)" ]; then + + # OpenRC functions used in depend + after() { + : + } + before() { + : + } + program() { + : + } + need() { + : + } + + shell_var() { + local output=$1 sanitized_arg= + shift 1 + for arg; do + sanitized_arg="${arg//[^a-zA-Z0-9_]/_}" + output="$output $arg" + done + echo "$output" + } + + net_fs_list="afs ceph cifs coda davfs fuse fuse.sshfs gfs glusterfs lustre ncpfs nfs nfs4 ocfs2 shfs smbfs" + is_net_fs() + { + [ -z "$1" ] && return 1 + + local fs=$(mount | grep " on $1 " | cut -f 5 -d ' ') + for x in $fs; do + for y in $net_fs_list; do + [ "$x" = "$y" ] && return 0 + done + done + return 1 + } + + service_set_value() { + local OPTION="$1" VALUE="$2" + if [ -z "$OPTION" ]; then + eerror "service_set_value requires parameter KEY" + return + fi + local file="$OPTIONSDIR/${OPTION}" + echo "$VALUE" > $file + } + service_get_value() { + local OPTION="$1" + if [ -z "$OPTION" ]; then + eerror "service_get_value requires parameter KEY" + return + fi + local file="$OPTIONSDIR/${OPTION}" + cat $file 2>/dev/null + } + STATEFILE="${STATEDIR}/state" + # Internal Function + # Stores the state of netifrc in ${SVCDIR}/${SVCNAME}/state file + _mark_service() { + local state=$1 + echo $state > $STATEFILE + } + #Internal Function + # Checks whether the state of netifrc is same as $1 + _service_state() { + state=$(cat $STATEFILE 2>/dev/null) + if [ state = $1 ]; then + return 1 + fi + return 0 + } + + mark_service_started() { + _mark_service started + } + mark_service_inactive() { + _mark_service inactive + } + mark_service_stopped() { + _mark_service stopped + } + service_started() { + _service_state started + return $? + } + service_inactive() { + _service_state inactive + return $? + } +fi + +# Extracts the interface for the current invocation +get_interface() { + case $INIT in + openrc) + printf ${RC_SVCNAME#*.};; + systemd) + printf ${RC_IFACE};; + *) + eerror "Init system not supported. Aborting" + exit -1;; + esac +} + +# vim: ts=4 sw=4 noexpandtab