home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXTSTEP 3.3.4.17 [SPARC, PA-RISC]
/
nextstep33_risc.iso
/
private
/
etc
/
rc.net
< prev
next >
Wrap
Text File
|
1993-04-08
|
4KB
|
154 lines
#!/bin/sh
#
# /etc/rc.net
#
# Configure all known interfaces according to the rules in /etc/iftab
#
# Copyright (C) 1992 by NeXT Computer, Inc. All rights reserved.
#
# Usage: rc.net [-d] [-h] [interface...]
#
iftab=/etc/iftab
#
# Let ^C's interrupt the commands run hereunder (eg, ifconfig), not
# the shell script itself.
#
trap "true" 2
#
# Handle command options
#
while [ -n "$1" ]; do
case "$1" in
-d) DEBUG=-YES-; shift;;
-h) SETHOSTNAME=-YES-; shift;;
*) iflist="$*"; break;;
esac
done
#
# Debug versions of actual configuration commands
#
docmd() {
if [ "$DEBUG" = -YES- ]; then
echo "#" "$@"
else
"$@"
fi
}
#
# A procedure to use /etc/hostconfig to configure a given interface
#
# Usage: hostconfig <interface>
#
hostconfig() {
if [ -n "$INETADDR" -a "$INETADDR" != -NO- ]; then
cmd="ifconfig $1 inet $INETADDR"
if [ -n "$IPNETMASK" ]; then
cmd="$cmd netmask $IPNETMASK"
fi
if [ -n "$IPBROADCAST" -a "$IPBROADCAST" != -AUTOMATIC- ]; then
cmd="$cmd broadcast $IPBROADCAST"
fi
cmd="$cmd -trailers up"
docmd $cmd
fi
}
#
# Read /etc/hostconfig for backwards compatibility
#
if [ -f /etc/hostconfig ]; then
. /etc/hostconfig
fi
#
# Ask ifconfig for all available interface names if none were given
# on the command line.
#
if [ -z "$iflist" ]; then
iflist="`ifconfig -a | awk -F: '/^[a-z]/ {print $1}'`"
fi
#
# Make sure that lo0 is done last, so that it never becomes the
# primary interface (unless it is the only one we have)
#
iflist=`echo $iflist | awk '{
for (i = 1; i <= NF; i++)
if ($i == "lo0")
lo0="lo0";
else
print $i;
print lo0;}'`
primif=`echo $iflist | awk '{print $1}'`
#
# Go for it -- configure each interface in our list
#
if [ -s $iftab ]; then
# Look for matching config information in /etc/iftab
for if in $iflist; do
(while read name af args; do
# Special hack for primary interface
if [ "X$name" = "X-1-" -a $if = $primif ]; then
name=$if
fi
# Skip '#' comments while trying to match on each device pattern
case $if in
\#*) ;;
$name)
# Found a matching interface; have we done this address
# family before? (Check by inspecting a shell variable
# formed by the device name and the address family, for
# example: $en0_inet)
eval done=\${$if\_$af}
if [ -z "$done" ]; then
# A "!" escape will allow us to put any configuration
# command in iftab. The config command may make use
# of the shell variables $if and $af to get the name
# of the current interface and address family.
case "$args" in
-HOSTCONFIG-) hostconfig $if;;
!*) eval docmd `echo $args | sed 's/^!//'`;;
*) docmd ifconfig $if $af $args;;
esac
eval $if\_$af=DONE
fi;;
esac
done) < $iftab
done
else
# More backwards compatibility -- if we don't have an /etc/iftab,
# try using the stuff in /etc/hostconfig instead.
hostconfig en0
# Make sure that the loopback interface gets initialized
docmd ifconfig lo0 inet -AUTOMATIC- netmask -AUTOMATIC-
fi
#
# Set the hostname if we're asked to do so.
#
if [ "$SETHOSTNAME" = -YES- ]; then
if [ -z "$HOSTNAME" ]; then
HOSTNAME=-AUTOMATIC-
fi
if [ "$HOSTNAME" != -NO- ]; then
echo "Setting hostname to $HOSTNAME"
docmd hostname $HOSTNAME
fi
fi
#
# Finally, let nmserver know the fruits of our network configuration endeavor.
#
pid=`ps cax | egrep nmserver | awk '{print $1;}'`
if [ -n "$pid" ]; then
echo "Reinitializing nmserver's network portion"
docmd kill -USR2 $pid
fi