#!/bin/sh #Copyright (c) 2001, University of Washington, UW/EE # do we want to put the bunch in /var/nikola/bunch too? if [ "x$1" = "x-bunch" ] then dobunch=true else dobunch=false fi # # Loop through each interface on the host, matching them against # the hostmap list. If we find a match, create the hosts, network, # and ifcfg-$interface files. This allows multi-homed hosts to # be configured easily. The last match will win for the # /etc/sysconfig/network file, so that will be the one that determines # the host's name and NIS domain. # # We use the tr to force everything to be in lower case, just in case. # for interface in `./pullmac.sh | cut -d" " -f1` do bunch="" # make sure it's empty going in mac=`./pullmac.sh | grep -i $interface | tr [A-Z] [a-z] | \ cut -d' ' -f2` IP=`grep -i "^$mac" hostmap | awk '{print $2}'` HN=`grep -i "^$mac" hostmap | awk '{print $3}' | \ tr [A-Z] [a-z]` Short_HN=`grep -i "^$mac" hostmap | awk '{print $4}' | \ tr [A-Z] [a-z]` bunch=`grep -i "^$mac" hostmap | awk '{print $5}' | \ tr [A-Z] [a-z]` # # if we have a bunchname, set the NIS domain. Since RCS # (and possibly others) don't use the same bunch as their # NIS domain, we can't just do a direct write. This case # statement lets us intercept and set if it needs to be # different. The default case is to use the bunchname for # the NIS domain as well. # if [ "x$bunch" != "x" ] then # we have a bunch name, that will determine the NIS domain. case $bunch in "rcs" ) NISDOMAIN="rcsnet" ;; * ) NISDOMAIN=$bunch ;; esac fi # we know the host's IP, lets extrapolate the network, # broadcast, and gateway network=`echo $IP | cut -d"." -f1,2,3` NETWORK="${network}.0" GATEWAY="${network}.100" BROADCAST="${network}.255" # # we have data, lets spit out the files. # if [ "x$HN" != "x" ] then cat > /etc/sysconfig/network << EOF NETWORKING=yes HOSTNAME=$HN GATEWAY=$GATEWAY NISDOMAIN=$NISDOMAIN EOF cat >> /etc/hosts << EOF $IP $HN $Short_HN EOF cat > /etc/sysconfig/network-scripts/ifcfg-$interface << EOF DEVICE=$interface ONBOOT=yes BOOTPROTO=none BROADCAST=$BROADCAST NETWORK=$NETWORK NETMASK=255.255.255.0 IPADDR=$IP USERCTL=no EOF fi # # clear all the variables to make sure we don't pick up old # values on the next cycle. We can't reset bunch, since we # use it outside of the loop. # mac="" IP="" HN="" Short_HN="" network="" NETWORK="" GATEWAY="" NISDOMAIN="" BROADCAST="" done # # To set the host's bunch name, use only the last entry, if we have a bunch # and were told to do it. # if [ "x$dobunch" = "xtrue" -a "x$bunch" != "x" ] then echo $bunch > /var/nikola/bunch fi