#!/bin/sh
# This is the file /etc/r2d2/net.d/ip-interfaces used to bring up the network.
# (C) 1996,1997 W. Trmper

  # name of the configuration file
IF_CFG="/etc/net/ip/interfaces.conf"

function interfaces () {
    local action id
    action="$1"
    id="$2"

      # read every line of the configuration file
    while read  IF IP BCAST NETMASK ID EXTRA_OPTIONS
    do
	# ignore comments and blank lines
	case "$IF" in
	    \#* | "") continue ;;
	esac
	[ "$ID" = "$id" -o "$ID" = "*" ] || continue
	
	  # determine the basename of the interface (strip numbers)
	IF_TYPE=${IF%%[0-9]*}
	
	  # call the appropriate sub-script
	CMD="/etc/r2d2/net.d/ifconfig_$IF_TYPE"
	if [ -x "$CMD" ]
	then 
	    $CMD "$IF" "$IP" broadcast "$BCAST" netmask "$NETMASK" $EXTRA_OPTIONS "$action"
	else
	    echo "$0: $CMD not executable (while parsing $IF_CFG)"
	fi
    done < $IF_CFG
}

case $1 in
    start)
	interfaces up "$2";;
    stop)
	interfaces down "$2";;
    *)
	echo "Usage: $0 start|stop"
	exit 1
esac
