#! /bin/sh #% #% ifplumb - "plumb" and establish the IP addresses for IVES netras #% #% usage: ifplumb hosts -- dumps a hosts file to be used from the outside #% ifplumb log -- show the log for this machine #% ifplumb [-v] -- plumbs the interfaces #% #% where: #% -v : optional verbose mode #% : controls the VIRTUAL set of IPs: primary, secondary, or none #% NB. live sites run only on the primary machine, test on the secondary #% We are no longer using live and test to designate machines, rather primary and secondary #% <-nostick/-restore> #% -nostick if being run from startup, -restore is command line and want appropriate database restore #% #% #% history: #% Feb 2001 : keef created #% if [ $# -lt 1 ]; then awk '/^#%/ {print substr($0,3)}' $0 exit 0 fi LOG="/etc/ifplumb.log" BAR="-----------------------------------------------------------------------------" PATH="/usr/ucb:/bin:/usr/bin:/usr/sbin"; export PATH MacAddr=`ifconfig -a | awk '($1=="ether"){print $2; exit(0)}'` VerboseMode=0 if [ "$1" = "-v" ]; then VerboseMode=1 shift fi mode="$1" nostick="$2" box="" #---------------------------------------------------------------------- VERB() #---------------------------------------------------------------------- { if [ $VerboseMode -eq 1 ]; then if [ "$1" = "-n" ]; then shift echo -n "$*" else echo "$*" fi fi } # VERB #---------------------------------------------------------------------- # DETERMINE WHAT PHYSICAL MACHINE THIS IS: #---------------------------------------------------------------------- # Note: this method does NOT work because if you UNPLUMB all the NICs, # then you no longer can get the MacAddr from ifconfig -a #case "$MacAddr" in # "0:3:ba:b:ec:93") box="ives1";; # <-- IVES 1st Netra T1 # "0:3:ba:f:40:e7") box="ives2";; # <-- IVES 2nd Netra T1 #esac boxtmp="/tmp/ifplumb$$" find /etc -name 'ifplumb.ives*' -print | while read file do if [ "$box" = "" ]; then box=`echo $file | awk -F. '{print $2}'` echo "$box" > $boxtmp # <-- we need to pass this back from the while loop else echo "ifplumb: too many identity file (schisophrenia):" find /etc -name 'ifplumb.ives*' -print | awk '{print " ---> ", $0}' echo "" exit 1 fi done [ $? -ne 0 ] && exit 1 if [ ! -f $boxtmp ]; then echo "ifplumb: missing identity file: /etc/ifplumb.ives???" exit 1 fi box=`cat $boxtmp` VERB "box = $box" #---------------------------------------------------------------------- # HARDCODED SECTION: #---------------------------------------------------------------------- EXTBASE="216.129.137" # <-- given to us by lightband EXTBROAD="216.129.137.63" # <-- given to us by lightband EXTMASK="255.255.255.240" # <-- given to us by lightband # FYI: lightband has given us .49 through .62 inclusive EXTIVES1="49"; EXTIVES2="50" # this bank is assigned to us from lightband: ACMELIVE="55"; ACMETEST="56" LCDLIVE="59"; LCDTEST="51" RIDGELIVE="60"; RIDGETEST="52" VHOSTSLIVE="61"; VHOSTSTEST="53" IVESSSLLIVE="62"; IVESSSLTEST="54" # Note: # 57 is the netopia router # 58 goes to our linksys # this bank is arbitrated by Ted: INTBASE="192.168.1" # <-- local area network in Manchaug INTMASK="255.255.255.0" # <-- local area network in Manchaug INTIVES1="18" INTIVES2="19" if [ "$mode" = "hosts" ]; then cat <<-EOF # - - - - - - - - - - - - - - - - - - - - - - - - # IVES @ MANCHAUG (generated by /etc/ifplumb) # - - - - - - - - - - - - - - - - - - - - - - - - # static addresses to each physical machine for ssh connections: $EXTBASE.58 linksys server1 $EXTBASE.$EXTIVES1 ives1 ives1ext ives1.ivesinc.com $EXTBASE.$EXTIVES2 ives2 ives2ext ives2.ivesinc.com # alternate addresses to each box (will only work within manchaug lan): $INTBASE.$INTIVES1 ives1int $INTBASE.$INTIVES2 ives2int # virtual IP addresses for browsers and testing: $EXTBASE.$LCDLIVE legalcasedocs lcd $EXTBASE.$VHOSTSLIVE trivium triviumschool aworks accountabilityworks bot54 stats amal accmal accountingmalpractice execrunner dirmal directormalpractice cparunner jdrunner taxsearcher jdmal jdmalpractice sitemon $EXTBASE.$IVESSSLLIVE ivesinc ssl $EXTBASE.$LCDTEST test.legalcasedocs test.lcd $EXTBASE.$VHOSTSTEST test.trivium test.triviumschool test.aworks test.accountabilityworks test.bot54 test.stats test.amal test.accmal test.accountingmalpractice test.execrunner test.dirmal test.directormalpractice test.cparunner test.jdrunner test.taxsearcher test.jdmal test.jdmalpractice test.sitemon $EXTBASE.$IVESSSLTEST test.ivesinc testssl EOF exit 0 elif [ "$box" = "log" ]; then cat /etc/ifplumb.log exit 0 fi #---------------------------------------------------------------------- Log() #---------------------------------------------------------------------- { Interface="$1" IPAddress="$2" Hostname="$3" Message="$4" Now=`date "+%a %m/%d/%Y %T"` echo "$Now|$Interface|$IPAddress|$Hostname|$Message" | nawk -F'|' \ '{ Now = $1 Interface = $2 IPAddress = $3 Hostname = $4 Message = $5 printf ("%s | %-7s | %-15.15s | %-16.16s| %s\n", Now, Interface, IPAddress, Hostname, Message) }' >> $LOG } # Log #---------------------------------------------------------------------- PlumbIt() # generic routine to plumb an interface on a Sun #---------------------------------------------------------------------- { Interface="$1" IPAddress="$2" Broadcast="$3" Hostname="$4" Netmask="$5" VERB "$BAR" echo "plumbing $Interface for $Hostname..." VERB "$BAR" VERB -n " bringing down interface $Interface ... " sh -c "ifconfig $Interface down 2>&1" 2>&1 > /dev/null VERB "" Log $Interface $IPAddress $Hostname "brought interface down" VERB -n " making sure no one is responding to $IPAddress yet ... " /usr/sbin/ping $IPAddress 1 1>&2 > /dev/null if [ $? -eq 0 ]; then VERB "ERROR!" echo " ERROR: $IPAddress is ALREADY IN USE." echo " --> leaving interface $Interface DOWN -- $Hostname questionable" Log $Interface $IPAddress $Hostname "ALREADY IN USE" return; else VERB "good (no answer)." fi VERB " plumbing the interface ... " ifconfig $Interface plumb VERB " --> ifconfig $Interface inet $IPAddress netmask $Netmask broadcast $Broadcast up" ifconfig $Interface inet $IPAddress netmask $Netmask broadcast $Broadcast up VERB -n " making sure the interface is up on $IPAddress ... " /usr/sbin/ping $IPAddress 1 1>&2 > /dev/null if [ $? -ne 0 ]; then VERB "ERROR!" echo " ERROR: failed to get interface $Interface to respond to $IPAddress" echo " --> $Hostname is BROKEN." Log $Interface $IPAddress $Hostname "FAILED TO COME UP" return; else VERB "good (we got a response)." fi VERB -n " making this config 'stick' after reboot ... " echo "$Hostname" > /etc/hostname.$Interface if [ $? -ne 0 ]; then VERB "ERROR!" Log $Interface $IPAddress $Hostname "could not write 'hostname.$Interface'" else VERB "done" fi Log $Interface $IPAddress $Hostname "interface is up" VERB "" } # PlumbIt #---------------------------------------------------------------------- # MAIN #---------------------------------------------------------------------- cat <<-EOF >> $LOG +-$BAR | ifplumb $* ... +-$BAR EOF case "$box" in ives1) # --------- -------------------- ------------- --------------------- ---------- # INTERFACE IP-ADDRESS BROADCAST CANONICAL-HOSTNAME NETMASK # --------- -------------------- ------------- --------------------- ---------- PlumbIt dmfe0 $EXTBASE.$EXTIVES1 $EXTBROAD ives1.ivesinc.com $EXTMASK PlumbIt dmfe1 $INTBASE.$INTIVES1 $INTBASE.255 ives1int $INTMASK # --------- -------------------- ------------- --------------------- ---------- hostname ives1.ivesinc.com ;; ives2) # --------- -------------------- ------------- --------------------- ---------- # INTERFACE IP-ADDRESS BROADCAST CANONICAL-HOSTNAME NETMASK # --------- -------------------- ------------- --------------------- ---------- PlumbIt dmfe0 $EXTBASE.$EXTIVES2 $EXTBROAD ives2.ivesinc.com $EXTMASK PlumbIt dmfe1 $INTBASE.$INTIVES2 $INTBASE.255 ives2int $INTMASK # --------- -------------------- ------------- --------------------- ---------- hostname ives2.ivesinc.com ;; *) echo "ifplumb: invalid box '$box'." awk '/^#%/ {print substr($0,3)}' $0 exit 0 ;; esac case "$mode" in primary) touch /etc/ifplumb.i_THIS_MACHINE_IS_PRIMARY sh -c "rm /etc/ifplumb.i_THIS_MACHINE_IS_SECONDARY 2>&1" 2>&1 > /dev/null sh -c "rm /etc/ifplumb.i_THIS_MACHINE_IS_OFFLINE 2>&1" 2>&1 > /dev/null # --------- -------------------- ------------- --------------------- ---------- # INTERFACE IP-ADDRESS BROADCAST CANONICAL-HOSTNAME NETMASK # --------- -------------------- ------------- --------------------- ---------- PlumbIt dmfe0:1 $EXTBASE.$LCDLIVE $EXTBROAD www.legalcasedocs.com $EXTMASK PlumbIt dmfe0:2 $EXTBASE.$RIDGELIVE $EXTBROAD www.ridgeware.com $EXTMASK PlumbIt dmfe0:3 $EXTBASE.$VHOSTSLIVE $EXTBROAD vhostslive $EXTMASK PlumbIt dmfe0:4 $EXTBASE.$IVESSSLLIVE $EXTBROAD www.ivesinc.com $EXTMASK PlumbIt dmfe0:5 $EXTBASE.$ACMELIVE $EXTBROAD www.acmemarble.com $EXTMASK # --------- -------------------- ------------- --------------------- ;; secondary) touch /etc/ifplumb.i_THIS_MACHINE_IS_SECONDARY sh -c "rm /etc/ifplumb.i_THIS_MACHINE_IS_PRIMARY 2>&1" 2>&1 > /dev/null sh -c "rm /etc/ifplumb.i_THIS_MACHINE_IS_OFFLINE 2>&1" 2>&1 > /dev/null # --------- -------------------- ------------- --------------------- --------- # INTERFACE IP-ADDRESS BROADCAST CANONICAL-HOSTNAME NETMASK # --------- -------------------- ------------- --------------------- --------- PlumbIt dmfe0:1 $EXTBASE.$LCDTEST $EXTBROAD test.legalcasedocs.com $EXTMASK PlumbIt dmfe0:2 $EXTBASE.$RIDGETEST $EXTBROAD test.ridgeware.com $EXTMASK PlumbIt dmfe0:3 $EXTBASE.$VHOSTSTEST $EXTBROAD vhoststest $EXTMASK PlumbIt dmfe0:4 $EXTBASE.$IVESSSLTEST $EXTBROAD test.ivesinc.com $EXTMASK PlumbIt dmfe0:5 $EXTBASE.$ACMETEST $EXTBROAD test.acmemarble.com $EXTMASK # --------- -------------------- ------------- --------------------- ;; none) touch /etc/ifplumb.i_THIS_MACHINE_IS_OFFLINE sh -c "rm /etc/ifplumb.i_THIS_MACHINE_IS_PRIMARY 2>&1" 2>&1 > /dev/null sh -c "rm /etc/ifplumb.i_THIS_MACHINE_IS_SECONDARY 2>&1" 2>&1 > /dev/null ifconfig dmfe0:1 down; Log dmfe0:1 "" "" "brought interface down" ifconfig dmfe0:2 down; Log dmfe0:2 "" "" "brought interface down" ifconfig dmfe0:3 down; Log dmfe0:3 "" "" "brought interface down" ifconfig dmfe0:4 down; Log dmfe0:4 "" "" "brought interface down" ;; *) echo "ifplumb: invalid mode '$mode'." awk '/^#%/ {print substr($0,3)}' $0 exit 0 ;; esac # cmdline only: this section gets skipped if its being called during bootstrap: if [ "$nostick" != "-nostick" ]; then Log "dmfe0:*" $EXTBASE.* "" "/etc/rc*.d/S02ifplumb..." VERB "$BAR" echo "[re]creating SysV startup scripts in /etc/rc*.d..." VERB "$BAR" VERB " giving runmode 1 $box's physical addresses..." cat <<-EOF > /etc/rc1.d/S02ifplumb #! /bin/sh /etc/ifplumb none -nostick EOF chmod a+rx /etc/rc1.d/S02ifplumb VERB " giving runmode 2&3 the virtual identity '$mode'..." cat <<-EOF > /etc/rc2.d/S02ifplumb #! /bin/sh /etc/ifplumb $mode -nostick EOF chmod a+rx /etc/rc2.d/S02ifplumb VERB " ok: this network identity should stick in case the machine bounces." VERB "" fi if [ "$nostick" = "-restore" ]; then /etc/restoredbs -run tturner@ivesinc.com,mnohrden@ivesinc.com,joe@ridgeware.com,esturner3@attbi.com fi if [ $VerboseMode -eq 1 ]; then echo "% ives ..." /usr/local/bin/ives fi