#!/bin/sh -
#
# pccard_ether interfacename [ifconfig option]
#
# example: pccard_ether ep0 link1
#
# $Id: pccard_ether,v 1.3 1999/09/22 13:58:02 toshi Exp $
# HOSOKAWA, Tatsumi <hosokawa@jp.FreeBSD.org>
#

# Suck in the configuration variables
if [ -f /etc/defaults/rc.conf ]; then
	. /etc/defaults/rc.conf
elif [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

interface=$1
shift

if expr "$pccard_ether" : ".*${interface}.*" > /dev/null; then
	eval ifconfig_args=\$ifconfig_${interface}
	if [ "x$ifconfig_args" = "xDHCP" ]; then
		# Stop the DHCP client for this interface
		if [ -s /var/run/dhclient.pid ]; then
			kill `cat /var/run/dhclient.pid`
			rm -f /var/run/dhclient.pid
		elif [ -s /var/run/dhcpc.$interface.pid ]; then
			kill `cat /var/run/dhcpc.$interface.pid`
			rm -f /var/run/dhcpc.$interface.pid
		fi
		# Start up the DHCP client program
		if [ -x "$dhcp_program" ]; then
			$dhcp_program $dhcp_flags $interface
		else
			echo "$dhcp_program: DHCP client software not available"
		fi
	elif [ -n "$ifconfig_args" ]; then
		# Do the primary ifconfig if specified
		if [ "x$ifconfig_args" != "xNO" ]; then
			ifconfig $interface $ifconfig_args $*
		fi
		# Check to see if aliases need to be added
		alias=0
		while :
		do
			eval ifx_args=\$ifconfig_${interface}_alias${alias}
			if [ -n "$ifx_args" ]; then
				ifconfig $interface $ifx_args alias
				alias=`expr ${alias} + 1`
			else
				break;
			fi
		done
		# Do ipx address if specified
		eval ifx_args=\$ifconfig_${interface}_ipx
		if [ -n "$ifx_args" ]; then
			ifconfig $interface $ifx_args
		fi
		# Add to static route if specified
		eval ifx_routes=\$static_routes_${interface}
		if [ -n "$ifx_routes" ]; then
			for i in ${ifx_routes}; do
				eval route_args=\$route_${i}
				route add ${route_args}
			done
		fi
		# Add default route to $static_routes if specified
		if [ -n "$defaultrouter" -a "x$defaultrouter" != "xNO" ]; then
			static_routes="default ${static_routes}"
			route_default="default ${defaultrouter}"
		fi
		# Set up any static routes if specified
		if [ -n "${static_routes}" ]; then
			route -n flush
			for i in ${static_routes}; do
				eval route_args=\$route_${i}
				route add ${route_args}
			done
		fi
	fi
fi
