diff options
Diffstat (limited to 'net-dialup/isdn4k-utils/files/isdn.initd')
-rw-r--r-- | net-dialup/isdn4k-utils/files/isdn.initd | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/net-dialup/isdn4k-utils/files/isdn.initd b/net-dialup/isdn4k-utils/files/isdn.initd new file mode 100644 index 0000000..9b29ee6 --- /dev/null +++ b/net-dialup/isdn4k-utils/files/isdn.initd @@ -0,0 +1,150 @@ +#!/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/isdn.initd,v 1.4 2006/02/04 21:14:17 sbriesen Exp $ + +opts="${opts} save reload makedev info" + +depend() { + use hisax + [ "$DEPEND_ON_CAPI" = "yes" ] && need capi +} + +# 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 + for IDLINE in $(/bin/head 2>/dev/null -n1 /dev/isdninfo); do + IDMAP[$((IDX-1))]=${IDLINE}; : $((IDX++)) + done + IDX=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 +} + +# gets CAPI controller name +capi_name() { # <contr> + /bin/sed -n "s:^${1} \+[^ ]\+ \+[^ ]\+ \+\([^ ]\+\) \+.\+\$:\1:p" \ + /proc/capi/controller 2>/dev/null +} + +# displays installed ISDN cards +show_cards() { # < $(card_list) + local CONTR CHAN CARD CAPI + while read CONTR CHAN CARD; do + case "${CARD}" in + capidrv-[1-9]*) + CAPI=$(capi_name ${CARD/capidrv-}) + einfo "${1}${CONTR} ${CARD} (${CAPI})" + ;; + *) + einfo "${1}${CONTR} ${CARD}" + ;; + esac + done +} + +# creates ISDN devices for static /dev and udev +makedev() { + if [ ! -e /dev/.devfsd ]; then + local CHAN + pushd /dev >/dev/null || return 1 + ebegin "Creating ISDN devices" + /bin/rm -f isdninfo isdnctrl* ippp[0-9]* isdn[0-9]* ttyI[0-9]* + for ((CHAN = 0; CHAN < ISDN_MAX_CHANNELS; CHAN++)); do + /bin/mknod -m "${ISDNDEV_MODE}" isdn${CHAN} c 45 $((CHAN)) # b + /bin/mknod -m "${ISDNDEV_MODE}" isdnctrl${CHAN} c 45 $((CHAN + 64)) # ctrl + /bin/mknod -m "${ISDNDEV_MODE}" ippp${CHAN} c 45 $((CHAN + 128)) # ppp + /bin/mknod -m "${ISDNDEV_MODE}" ttyI${CHAN} c 43 $((CHAN)) # tty + done + /bin/chgrp "${ISDNDEV_GROUP}" isdnctrl* ippp[0-9]* isdn[0-9]* ttyI[0-9]* + /bin/mknod -m 444 isdninfo c 45 255 + /bin/ln -snf isdnctrl0 isdnctrl + popd >/dev/null + eend 0 + fi +} + + +start() { + # create ISDN devices if necessary + [ -c /dev/isdninfo -a -c /dev/isdnctrl0 ] || makedev + + local LIST="$(card_list)" + + if [ -z "${LIST}" ]; then + eerror "ERROR: no ISDN cards available" + return 1 + fi + + ebegin "Loading isdnctrl configuration" + [ ! -f "${ISDNCTRL_CONFIG}" ] || /usr/sbin/isdnctrl readconf "${ISDNCTRL_CONFIG}" >/dev/null + eend $? + + if [ -n "${IPROFD_SETTINGS}" ]; then + ebegin "Starting modem-register daemon" + start-stop-daemon 2>/dev/null --start --quiet --exec /usr/sbin/iprofd -- "${IPROFD_SETTINGS}" + eend $? + fi + + einfo "Available ISDN cards:" +# show_cards " " < <(echo "${LIST}") + echo "${LIST}" | show_cards + return 0 +} + +stop() { + local RET FCNT=0 + + # if some other monitoring processes are running, kill 'em + if /bin/fuser 2>/dev/null -s /dev/isdninfo; then + ebegin "Stopping monitoring processes" + /bin/fuser -ks /dev/isdninfo; RET=$? + while [ ${RET} -eq 0 -a ${FCNT} -lt 10 ]; do + : $((FCNT++)); sleep 0.5; /bin/fuser -s /dev/isdninfo; RET=$? + done + [ $RET -ne 0 ] + eend $? + fi + + if [ -n "${IPROFD_SETTINGS}" ]; then + ebegin "Stopping modem-register daemon" + start-stop-daemon 2>/dev/null --stop --quiet --retry 5 --exec /usr/sbin/iprofd + eend $? + fi + + ebegin "Unloading isdnctrl configuration" + /usr/sbin/isdnctrl reset force &>/dev/null + eend $? + + return 0 # ignore errors +} + +save() { + ebegin "Saving isdnctrl configuration" + /usr/sbin/isdnctrl writeconf "${ISDNCTRL_CONFIG}" >/dev/null + eend $? +} + +reload() { + ebegin "Reloading isdnctrl configuration" + /usr/sbin/isdnctrl reset >/dev/null + [ ! -f "${ISDNCTRL_CONFIG}" ] || \ + /usr/sbin/isdnctrl readconf "${ISDNCTRL_CONFIG}" >/dev/null + eend $? +} + +info() { + local LIST="$(card_list)" + if [ -z "${LIST}" ]; then + eerror "ERROR: no ISDN cards available" + return 1 + fi +# show_cards < <(echo "${LIST}") + echo "${LIST}" | show_cards +} |