home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / xkernel / genrom2.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1996-01-23  |  4KB  |  215 lines

  1. #!/bin/csh -f
  2.  
  3. if ( $#argv < 4 ) then
  4.     echo need two files and two hostnames
  5.     exit 1
  6. endif
  7.  
  8. set fn1 = $1
  9. set fn2 = $2
  10. if ( ( ! -e $fn1 ) || ( ! -r $fn1 ) ) then
  11.     echo Cannot read file $fn1
  12.     exit 1
  13. endif
  14. if ( ( ! -e $fn2 ) || ( ! -r $fn2 ) ) then
  15.     echo Cannot read file $fn2
  16.     exit 1
  17. endif
  18.  
  19. if ( $#argv > 3 ) then
  20.   set hl = ( $argv[3-] )
  21.   @ nh = $#hl
  22. else
  23.   set hl = ( `lchost` `lchost` )
  24.   set nh = 2
  25. endif
  26.  
  27. if ( $nh > 16 ) then
  28.   echo Too many hosts"," cannot handle $nh hosts
  29. endif
  30.  
  31. if ( -e /usr/etc/ping ) then
  32. set PING=/usr/etc/ping
  33. else
  34. if  ( -e /etc/ping_ultrix ) then
  35. set PING=/etc/ping_ultrix
  36. else
  37. if ( -e /usr/sbin/ping ) then
  38. # some systems may need to change this
  39. # set PING='/usr/sbin/ping -c 1'
  40. set PING='/usr/sbin/ping'
  41. else
  42. set PING=ping
  43. endif
  44. endif
  45. endif
  46.  
  47. if ( -e /usr/etc/arp ) then
  48. set ARP=/usr/etc/arp
  49. else
  50. if ( -e /etc/arp ) then
  51. set ARP=/etc/arp
  52. else
  53. if ( -e /usr/sbin/arp ) then
  54. set ARP=/usr/sbin/arp
  55. else
  56. set ARP=arp
  57. endif
  58. endif
  59. endif
  60.  
  61. set hostp =  ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  62. set hoste =  ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  63. set hostfe = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  64. set hostn =  ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  65. set hostsn = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  66. set hostun = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
  67.  
  68. if ( $?ROMGEN_BASE_PORT) then
  69.   set base = $ROMGEN_BASE_PORT
  70. else
  71.   set base = `random_int 10000`
  72.   if ( $base < 1024 ) @ base += 1024
  73. endif
  74.  
  75. if ( $?ROMGEN_FAKE_IP_BASE ) then
  76.     set fakeipbase = $ROMGEN_FAKE_IP_BASE
  77. else
  78.    set fakeipbase = 1
  79. endif
  80.  
  81. set thishost = `lchost`
  82. set netnum = `pnetnum $thishost`
  83. if ( $?ROMGEN_HOST ) then
  84.     set arphost = $ROMGEN_HOST
  85. else
  86.     set arphost = cheltenham
  87. endif
  88.  
  89. set i = 1
  90. foreach host ( $hl )
  91.   set hostp[$i] = $base
  92.   set hostn[$i] = `phostnumber $host`
  93.   set j = 1
  94.   set hcount = 0
  95.   while ( $j < $i )
  96.      if ( $hl[$j] == $host ) @ hcount += 1
  97.      @ j += 1
  98.   end
  99.   if ( $hcount > 0 ) then
  100.       set hostsn[$i] = $netnum.$fakeipbase
  101.       @ fakeipbase += 1
  102.   else
  103.       set hostsn[$i] = $hostn[$i]
  104.   endif
  105.   $PING $host
  106.   set hosteth = `$ARP $host`
  107.   if ( $#hosteth > 3 &&  $hosteth[4] != no ) then
  108.     set hoste[$i] = $hosteth[4]
  109.   else
  110.         if ( $#hosteth <= 3) then
  111.         set hoste[$i] = '01:02:03:04:05:06'
  112.     else
  113.           set hosteth = `rsh $arphost /usr/etc/arp $host`
  114.       if ( $#hosteth > 3 ) then
  115.         if ( $hosteth[4] != no ) then
  116.           set hoste[$i] = $hosteth[4]
  117.         endif
  118.       else
  119.         set hosteth = `rsh $arphost /etc/arp $host`
  120.         if ( $#hosteth > 3 ) then
  121.           if ( $hosteth[4] != no ) then
  122.         set hoste[$i] = $hosteth[4]
  123.           endif
  124.         else
  125.         set hosteth = `rsh $arphost /usr/sbin/arp $host`
  126.         if ( $#hosteth > 3 ) then
  127.            if ( $hosteth[4] != no ) then
  128.              set hoste[$i] = $hosteth[4]
  129.            endif
  130.         else
  131.           set hoste[$i] = '01:02:03:04:05:06'
  132.             endif
  133.             endif
  134.       endif
  135.     endif
  136.   endif
  137.   set hostfe[$i] = `pfakeether "$hostsn[$i]" $base`
  138.   set hostun[$i] = $host
  139.   @ imo = $i - 1
  140.   if ( $i > 1 && $hostun[$i] == $hostun[$imo] ) set hostun[$i] = $hostun[$i]$i
  141.   @ base += 1
  142.   @ i += 1
  143. end
  144.  
  145. set i = 1
  146. set style = ipeth
  147. set fn = $fn1
  148. foreach host ( $hl )
  149.   set linen = 0
  150.   set file = rom.$host.$i
  151.   if ( -e $file ) rm $file
  152.   set line = `promfile $fn $linen`
  153.   set lline = ( $line )
  154.   while ( $#lline > 0 )
  155.     switch ( $lline[1] )
  156.     case simeth:
  157.       echo simeth $hostp[$i] >> $file
  158.       set style = simeth
  159.       breaksw
  160.  
  161.     case simsimeth:
  162.       echo simsimeth $hostp[$i] >> $file
  163.       set style = simsimeth
  164.       breaksw
  165.  
  166.     case dns:
  167.       set j = 1
  168.       foreach host ( $hl )
  169.          if ( $style == ipeth ) then
  170.              echo dns $hostun[$j] $hostn[$j] >> $file
  171.          else
  172.              echo dns $hostun[$j] $hostsn[$j] >> $file
  173.          endif
  174.          @ j += 1
  175.           end
  176.       breaksw
  177.  
  178.     default:
  179.       set arp = `echo $line | awk '$1 ~ /arp\// { print $1 } $1 ~ /^arp$/ { print $1 }'`
  180.       if ( a$arp != a ) then
  181.         set j = 1
  182.         switch ( $style )
  183.         case ipeth :
  184.           foreach host ( $hl )
  185.             echo $arp $hostn[$j] $hoste[$j] >> $file
  186.             @ j += 1
  187.           end
  188.           breaksw
  189.         case simeth:
  190.            foreach host ( $hl )
  191.              echo $arp $hostsn[$j] $hostn[$j] $hostp[$j] >> $file
  192.              @ j += 1
  193.            end
  194.            breaksw
  195.          case simsimeth:
  196.            foreach host ( $hl )
  197.          echo $arp $hostn[$j] $hostfe[$j] >> $file
  198.              @ j += 1
  199.            end
  200.            breaksw 
  201.          endsw
  202.       else
  203.         echo $line >> $file
  204.       endif
  205.       breaksw
  206.     endsw
  207.     @ linen += 1
  208.     set line = `promfile $fn $linen`
  209.         set lline = ( $line )
  210.   end
  211.   @ i += 1
  212.   set fn = $fn2
  213.   set style=ipeth
  214. end
  215.