#!/bin/sh # $DIALD_LINK is the name of the link we are disconnecting. # $DIALD_DEVICE is the device we are called out on. #CFG_SCRIPTS='/usr/share/diald' CFG_SCRIPTS='/etc/diald/scripts' CFG_DEVICE='/etc/diald/device.conf' CFG_LINK="/etc/diald/link" CFG_SEQ='/var/run' # $DIALD_DEVTYPE is a sanitized version of $DIALD_DEVICE. case "$DIALD_DEVICE" in ippp*) DIALD_DEVTYPE='isdn' ;; isdn*) DIALD_DEVTYPE='isdn' ;; *) DIALD_DEVTYPE='modem' ;; esac disconnect() { status=0 # If this device has a hangup script we use it to hang up # the physical link. if [ -n "$dial_script" -a "$dial_script" != '-' \ -a -x "$CFG_SCRIPTS/$dial_script.hangup" ]; then "$CFG_SCRIPTS/$dial_script.hangup" status=$? if [ $status -ne 0 ]; then exit $status fi fi exit $status } # Save stdin, we need it later if we are dialling a modem. exec 9<&0 # Find out what dial script to use on this device. exec < "$CFG_DEVICE" gotdev= while read dev dial_script dial_args do # Ignore blank lines and comments. case "$dev" in '#'*|'') continue ;; esac if [ "$dev" = "$DIALD_DEVICE" -o "$dev" = "$DIALD_DEVTYPE" ]; then gotdev=1 break fi done if [ -z "$gotdev" ]; then echo "<3>No entry for $DIALD_DEVICE, type $DIALD_DEVTYPE in $CFG_DEVICE" exit 1 fi seq=1 if [ -r "$CFG_SEQ/dialdseq.$DIALD_LINK" ]; then seq=`cat "$CFG_SEQ/dialdseq.$DIALD_LINK"` fi exec < "$CFG_LINK" dev_type= link_params= base_params= counted=0 while read dev_type link_params do # Ignore blank lines and comments. case "$dev_type" in '#'*|'') continue ;; esac if [ "$dev_type" = '=' ]; then base_params="$link_params" elif [ "$dev_type" = '+' ]; then base_params="$base_params $link_params" elif [ "$dev_type" = "$DIALD_DEVICE" \ -o "$dev_type" = "$DIALD_DEVTYPE" ]; then seq=`expr $seq - 1` counted=`expr $counted + 1` if [ $seq -eq 0 ]; then exec 0<&9 eval "$dial_args $base_params $link_params disconnect" exit $? fi fi done # If no entries match there is a problem if [ $counted -eq 0 ]; then echo "<3>No entry for $DIALD_DEVICE, type $DIALD_DEVTYPE in $CFG_LINK" exit 1 fi echo "<3>Did not find entry matching sequence number $seq for $DIALD_DEVICE, type $DIALD_DEVTYPE in $CFG_LINK" exit 1