84 lines
1.8 KiB
Bash
Executable File
84 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
#exec > /tmp/isdn.log 2>&1
|
|
#set -x
|
|
|
|
|
|
end_dial() {
|
|
for n in $PHONE
|
|
do
|
|
/usr/sbin/isdnctrl delphone "$DIALD_DEVICE" out "$n"
|
|
done
|
|
/usr/sbin/isdnctrl eaz "$DIALD_DEVICE" "$EAZ_IN"
|
|
if [ $status -ne 0 ]; then
|
|
# You should have specified "lock" in diald's config
|
|
# otherwise if we try and dial out on a device that
|
|
# is already connected we will hang it up.
|
|
/usr/sbin/isdnctrl hangup "$DIALD_DEVICE"
|
|
fi
|
|
exit $status
|
|
}
|
|
|
|
trap 'end_dial' 0
|
|
|
|
for n in $PHONE
|
|
do
|
|
/usr/sbin/isdnctrl addphone "$DIALD_DEVICE" out "$n"
|
|
done
|
|
/usr/sbin/isdnctrl eaz "$DIALD_DEVICE" "$EAZ_OUT"
|
|
|
|
/usr/sbin/isdnctrl dial "$DIALD_DEVICE"
|
|
status=$?
|
|
|
|
if [ $status -eq 0 ]; then
|
|
status=1
|
|
while true
|
|
do
|
|
msg=`/sbin/ifconfig "$DIALD_DEVICE" 2>&1`
|
|
if echo "$msg" | grep 'P-t-P:0.0.0.0' > /dev/null 2>&1
|
|
then
|
|
# no link yet...
|
|
WAITTIME=`expr $WAITTIME - 1`
|
|
if [ $WAITTIME -ge 0 ]; then
|
|
# still waiting...
|
|
sleep 1
|
|
else
|
|
echo "Timed out" 1>&2
|
|
break
|
|
fi
|
|
elif echo "$msg" | grep 'P-t-P:\[NONE SET\]' > /dev/null 2>&1
|
|
then
|
|
# no link yet...
|
|
WAITTIME=`expr $WAITTIME - 1`
|
|
if [ $WAITTIME -ge 0 ]; then
|
|
# still waiting...
|
|
sleep 1
|
|
else
|
|
echo "Timed out" 1>&2
|
|
break
|
|
fi
|
|
elif [ -n "$REMOTEIP" ]; then
|
|
if echo "$msg" | grep "P-t-P:$REMOTEIP" > /dev/null 2>&1
|
|
then
|
|
echo "Interface up: remote host ok" 1>&2
|
|
status=0
|
|
break
|
|
fi
|
|
elif [ -z "$REMOTEIP" ]; then
|
|
# The remote has a dynamic IP so we have no way
|
|
# of knowing whether the dial succeeded or some
|
|
# incoming connection was accepted. (If diald
|
|
# is not using device locking we may even have
|
|
# dialled somewhere else!)
|
|
echo "Interface up: host indeterminate" 1>&2
|
|
status=0
|
|
break
|
|
else
|
|
# Dial failed and something else is using this link.
|
|
echo "Interface up: wrong host - not my link" 1>&2
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
exit $status
|