#! /bin/sh
#
# |-----------------------------------------------------------|
# | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
# | All Rights Reserved                                       |
# |-----------------------------------------------------------|
# |          Restricted Rights Legend                         |
# | Use, duplication, or disclosure by the Government is      |
# | subject to restrictions as set forth in                   |
# | subparagraph (c)(1)(ii) of the Rights in Technical        |
# | Data and Computer Software Clause of DFARS 252.227-7013.  |
# |         MIPS Computer Systems, Inc.                       |
# |         950 DeGuigne Avenue                               |
# |         Sunnyvale, California 94088-3650, USA             |
# |-----------------------------------------------------------|
#
# $Header: dlpi,v 1.2.1.1 92/06/24 13:34:59 marker Exp $
#
# Initialize/Shutdown the dlpi software.
#

PATH=/net:/bin:/etc:/usr/bin:/usr/etc:/usr/ucb:

USAGE="usage: /etc/init.d/dlpi {start|stop}" ;

not() {
	eval ${1+"$@"} && return 1 || return 0
}

main() {
	case $1 in
	start)	dlpi_start ${1+"$@"} 
		;;
	stop)	dlpi_stop ${1+"$@"} 
		;;
	*)	echo "$USAGE"; 
		exit 1 
		;;
	esac
}

dlpi_start()
{
	#
	# Have they set the hostname yet?  If not, don't start the network.
	#
	# CPU-specific items.  The interface for the M/120 is called 'la0', and
	# the M/120 should be run with -trailers unless otherwise specified in
	# the /etc/local_hostname file.
	#
	case "`uname -t`" in
	m2000-25|m2000-33|R[CS]3[23]30|RC3240|r[cs]2030|m120|m120-*)
		Interface="la0"
		;;
	m2000|m2000-*|RC62*|RC63*)
		if (ifconfig "egl0" > /dev/null 2>&1)
		then
			Interface="egl0"
		else
			Interface="enp0"
		fi
		;;
	*4030*)
		Interface="snc0"
		;;
	*)
                ## old version assumed "enp0", let's try enp0
                if (ifconfig "enp0" > /dev/null 2>&1)
                then
                  Interface="enp0"
                else
                  ## try egl0
                  if (ifconfig "egl0" > /dev/null 2>&1)
                  then
                    Interface="egl0"
                  else
                    ## try la0
                    if (ifconfig "la0" > /dev/null 2>&1)
                    then
                     Interface="la0"
                    else
                     ## can't determine the Interface
                     echo "WARNING: Can't determine the Network Interface.  DLPI not configured."
                     exit 0
                    fi
                  fi
                fi
		;;	
	esac

	if (test -x /etc/havetcp  && havetcp) then 
	   	 dlconfig /dev/dlpi 1 "$Interface" > /dev/null
	fi


	#   change and install the following line for gatewaying
	#   ifconfig ex1 inet other-hostname

	dlconfig /dev/dlpi 0 lo0 > /dev/null

	#   add any additional dlpi ppa's here.
}

dlpi_stop() 
{
	:
}

main ${1+"$@"}
exit 0
