Sophie

Sophie

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

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

#!/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_DEVICE='/etc/diald/device.conf'
CFG_LINK="/etc/diald/$DIALD_LINK/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=0
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=
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`
		if [ $seq -eq 0 ]; then
			passes=0
			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

exit 1