#!/bin/bash
#
# Copyright (c) 2002 SuSE Linux AG, Nuernberg, Germany.
#
# Author: Christian Zoz <zoz@suse.de>
#

test -d /etc/sysconfig/network || exit 1
cd /etc/sysconfig/network

# find all interface configuration files. These files start with ifcfg- and do
# not contain a '.' or '~'. If they contain a ':' it's a configuration of an
# alias.
CONFFILES=""
for a in ifcfg-*; do 
	case $a in 
		*~*|*.*) 
			# drop backup files, rpm{save,new,orig}
			;; 
#		*:*)
#			# should we drop aliases, too?
#			;;
		ifcfg-ippp*|ifcfg-isdn*)
			if [ "$1" != stop ] ; then
				CONFFILES="$CONFFILES $a"
			else
				CONFFILES="$a $CONFFILES"
			fi
			;;
	esac
done

RET=0
case "$ACTION" in
	add)
		/etc/sysconfig/isdn/scripts/hotplug_usb start $PRODUCT $DEVICE
		if [ -z "$CONFFILES" ] ; then
			echo "$0: No ISDN interfaces configured."
			exit 0
		fi
		set $CONFFILES
		for CONF in ${@#ifcfg-}; do
			/sbin/ifup $CONF -o hotplug || RET=$?
		done
		;;
	remove)
		if [ -n "$CONFFILES" ] ; then
			set $CONFFILES
			for CONF in ${@#ifcfg-}; do
				/sbin/ifdown $CONF -o hotplug || RET=$?
			done
		else
			# I'm not sure if that is a good idea. At least, because
			# rcnetwork -o type=x,y does not work properly currently;
			# but it does not harm also.
			/sbin/rcnetwork stop -o type=ippp,isdn
		fi
		/etc/sysconfig/isdn/scripts/hotplug_usb stop $PRODUCT $DEVICE
		;;
esac
exit 0
