Sophie

Sophie

distrib > Mandriva > 2010.0 > x86_64 > by-pkgid > 4aadd45f221424a24a93e5fc1e8faba3 > files > 81

diald-1.0-12mdv2010.0.x86_64.rpm

#!/bin/sh
#exec > /tmp/isdn.log 2>&1
#set -x


end_dial() {
	for n in $PHONE
	do
		/sbin/isdnctrl delphone "$DIALD_DEVICE" out "$n"
	done
	/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.
		/sbin/isdnctrl hangup "$DIALD_DEVICE"
	fi
	exit $status
}

trap 'end_dial' 0

for n in $PHONE
do
	/sbin/isdnctrl addphone "$DIALD_DEVICE" out "$n"
done
/sbin/isdnctrl eaz "$DIALD_DEVICE" "$EAZ_OUT"

/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