diff options
author | Dennis Freise <dennis.freise@final-frontier.org> | 2012-05-21 10:33:53 +0200 |
---|---|---|
committer | Dennis Freise <dennis.freise@final-frontier.org> | 2012-05-21 10:33:53 +0200 |
commit | 90f52755a0935c5863259ac5d6cef6712592a731 (patch) | |
tree | c62e6ddc19d9de7e8881762c0054d2af094c9688 /net-dialup/isdn4k-utils/files/isdnlog.initd | |
parent | *fcpci-0.1-r7 (26 Jan 2012) (diff) | |
download | dfreise-90f52755a0935c5863259ac5d6cef6712592a731.tar.gz dfreise-90f52755a0935c5863259ac5d6cef6712592a731.tar.bz2 dfreise-90f52755a0935c5863259ac5d6cef6712592a731.zip |
Initial commit for git based isdn4k-utils
Diffstat (limited to 'net-dialup/isdn4k-utils/files/isdnlog.initd')
-rw-r--r-- | net-dialup/isdn4k-utils/files/isdnlog.initd | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/net-dialup/isdn4k-utils/files/isdnlog.initd b/net-dialup/isdn4k-utils/files/isdnlog.initd new file mode 100644 index 0000000..c453cff --- /dev/null +++ b/net-dialup/isdn4k-utils/files/isdnlog.initd @@ -0,0 +1,84 @@ +#!/sbin/runscript +# Copyright 1999-2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/net-dialup/isdn4k-utils/files/isdnlog.initd,v 1.4 2006/02/04 21:14:17 sbriesen Exp $ + +depend() { + need isdn +} + +# gets list of installed cards +card_list() { # output: <contr> <chan> <card> + local IDMAP=() IDX=1 CONTR=0 LAST='-' CARD='' + read -a IDMAP < <(/bin/head 2>/dev/null -n1 /dev/isdninfo) || return 1 + while [ ${IDX} -lt ${#IDMAP[*]} ]; do + CARD=${IDMAP[$IDX]} + if [ "${CARD}" != "-" -a "${CARD}" != "${LAST}" ]; then + echo "${CONTR} $((IDX-1)) ${CARD}"; : $((CONTR++)) + fi + LAST="${CARD}"; : $((IDX++)) + done +} + +# get info by contr, chan or card +card_info() { + local MASK + case "${1}" in + contr[0-9]*) + MASK="^${1#contr*} [0-9]\+ .*\$" + ;; + isdnctrl[0-9]*) + MASK="^[0-9]\+ ${1#isdnctrl*} .*\$" + ;; + *) + MASK="^[0-9]\+ [0-9]\+ ${1}\$" + ;; + esac + /bin/grep "${MASK}" <(card_list) +} + +start() { + local CONTR CHAN CARD TYPE="${myservice#*.*}" + read CONTR CHAN CARD < <(card_info "${TYPE}") + + if [ -z "${CARD}" ]; then + eerror "ISDNLOG: Selected controller not available (${TYPE})" + return 1 + fi + + # try to find a configuration file + local CONFIG="/etc/isdn/isdnlog.isdnctrl${CHAN}.options" + [ -f "${CONFIG}" ] || CONFIG="/etc/isdn/isdnlog.options.contr${CONTR}" + [ -f "${CONFIG}" ] || CONFIG="/etc/isdn/isdnlog.options.isdnctrl${CHAN}" + [ -f "${CONFIG}" ] || CONFIG="/etc/isdn/isdnlog.options.${CARD}" + + if [ ! -f "${CONFIG}" ]; then + eerror "ISDNLOG: You're missing /etc/isdn/isdnlog.options.${TYPE}" + return 1 + fi + + rm -f "/var/run/${myservice}" # cleanup + + ebegin "Starting ISDNLOG for controller #${CONTR} (${CARD})" + start-stop-daemon --start --quiet --pidfile "/var/run/isdnlog.isdnctrl${CHAN}.pid" \ + --exec /usr/sbin/isdnlog -- ${ISDNLOG_OPTIONS} -f "${CONFIG}" "/dev/isdnctrl${CHAN}" && \ + echo "${CONTR} ${CHAN} ${CARD} ${CONFIG##*/}" > "/var/run/${myservice}" + eend $? +} + +stop() { + if [ ! -f "/var/run/${myservice}" ]; then + eerror "ISDNLOG: Controller setup not found (${myservice#*.*})" + return 1 + fi + + local CONTR CHAN CARD CONF + read CONTR CHAN CARD CONF < "/var/run/${myservice}" + + ebegin "Stopping ISDNLOG for controller #${CONTR} (${CARD})" + start-stop-daemon --stop --quiet --retry 5 --pidfile "/var/run/isdnlog.isdnctrl${CHAN}.pid" + eend $? + + rm -f "/var/run/${myservice}" + return 0 # ignore errors +} |