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 >
Wrap
Linux/UNIX/POSIX Shell Script
|
1996-01-23
|
4KB
|
215 lines
#!/bin/csh -f
if ( $#argv < 4 ) then
echo need two files and two hostnames
exit 1
endif
set fn1 = $1
set fn2 = $2
if ( ( ! -e $fn1 ) || ( ! -r $fn1 ) ) then
echo Cannot read file $fn1
exit 1
endif
if ( ( ! -e $fn2 ) || ( ! -r $fn2 ) ) then
echo Cannot read file $fn2
exit 1
endif
if ( $#argv > 3 ) then
set hl = ( $argv[3-] )
@ nh = $#hl
else
set hl = ( `lchost` `lchost` )
set nh = 2
endif
if ( $nh > 16 ) then
echo Too many hosts"," cannot handle $nh hosts
endif
if ( -e /usr/etc/ping ) then
set PING=/usr/etc/ping
else
if ( -e /etc/ping_ultrix ) then
set PING=/etc/ping_ultrix
else
if ( -e /usr/sbin/ping ) then
# some systems may need to change this
# set PING='/usr/sbin/ping -c 1'
set PING='/usr/sbin/ping'
else
set PING=ping
endif
endif
endif
if ( -e /usr/etc/arp ) then
set ARP=/usr/etc/arp
else
if ( -e /etc/arp ) then
set ARP=/etc/arp
else
if ( -e /usr/sbin/arp ) then
set ARP=/usr/sbin/arp
else
set ARP=arp
endif
endif
endif
set hostp = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
set hoste = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
set hostfe = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
set hostn = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
set hostsn = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
set hostun = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
if ( $?ROMGEN_BASE_PORT) then
set base = $ROMGEN_BASE_PORT
else
set base = `random_int 10000`
if ( $base < 1024 ) @ base += 1024
endif
if ( $?ROMGEN_FAKE_IP_BASE ) then
set fakeipbase = $ROMGEN_FAKE_IP_BASE
else
set fakeipbase = 1
endif
set thishost = `lchost`
set netnum = `pnetnum $thishost`
if ( $?ROMGEN_HOST ) then
set arphost = $ROMGEN_HOST
else
set arphost = cheltenham
endif
set i = 1
foreach host ( $hl )
set hostp[$i] = $base
set hostn[$i] = `phostnumber $host`
set j = 1
set hcount = 0
while ( $j < $i )
if ( $hl[$j] == $host ) @ hcount += 1
@ j += 1
end
if ( $hcount > 0 ) then
set hostsn[$i] = $netnum.$fakeipbase
@ fakeipbase += 1
else
set hostsn[$i] = $hostn[$i]
endif
$PING $host
set hosteth = `$ARP $host`
if ( $#hosteth > 3 && $hosteth[4] != no ) then
set hoste[$i] = $hosteth[4]
else
if ( $#hosteth <= 3) then
set hoste[$i] = '01:02:03:04:05:06'
else
set hosteth = `rsh $arphost /usr/etc/arp $host`
if ( $#hosteth > 3 ) then
if ( $hosteth[4] != no ) then
set hoste[$i] = $hosteth[4]
endif
else
set hosteth = `rsh $arphost /etc/arp $host`
if ( $#hosteth > 3 ) then
if ( $hosteth[4] != no ) then
set hoste[$i] = $hosteth[4]
endif
else
set hosteth = `rsh $arphost /usr/sbin/arp $host`
if ( $#hosteth > 3 ) then
if ( $hosteth[4] != no ) then
set hoste[$i] = $hosteth[4]
endif
else
set hoste[$i] = '01:02:03:04:05:06'
endif
endif
endif
endif
endif
set hostfe[$i] = `pfakeether "$hostsn[$i]" $base`
set hostun[$i] = $host
@ imo = $i - 1
if ( $i > 1 && $hostun[$i] == $hostun[$imo] ) set hostun[$i] = $hostun[$i]$i
@ base += 1
@ i += 1
end
set i = 1
set style = ipeth
set fn = $fn1
foreach host ( $hl )
set linen = 0
set file = rom.$host.$i
if ( -e $file ) rm $file
set line = `promfile $fn $linen`
set lline = ( $line )
while ( $#lline > 0 )
switch ( $lline[1] )
case simeth:
echo simeth $hostp[$i] >> $file
set style = simeth
breaksw
case simsimeth:
echo simsimeth $hostp[$i] >> $file
set style = simsimeth
breaksw
case dns:
set j = 1
foreach host ( $hl )
if ( $style == ipeth ) then
echo dns $hostun[$j] $hostn[$j] >> $file
else
echo dns $hostun[$j] $hostsn[$j] >> $file
endif
@ j += 1
end
breaksw
default:
set arp = `echo $line | awk '$1 ~ /arp\// { print $1 } $1 ~ /^arp$/ { print $1 }'`
if ( a$arp != a ) then
set j = 1
switch ( $style )
case ipeth :
foreach host ( $hl )
echo $arp $hostn[$j] $hoste[$j] >> $file
@ j += 1
end
breaksw
case simeth:
foreach host ( $hl )
echo $arp $hostsn[$j] $hostn[$j] $hostp[$j] >> $file
@ j += 1
end
breaksw
case simsimeth:
foreach host ( $hl )
echo $arp $hostn[$j] $hostfe[$j] >> $file
@ j += 1
end
breaksw
endsw
else
echo $line >> $file
endif
breaksw
endsw
@ linen += 1
set line = `promfile $fn $linen`
set lline = ( $line )
end
@ i += 1
set fn = $fn2
set style=ipeth
end