Commit f39d1874 authored by Mac Newbold's avatar Mac Newbold

Modifies startup files to include experimental ifc configs. (ips, etc)

parent 1000b5a6
#!/usr/bin/perl
if ( $#ARGV < 0) {
die("Usage: ifc_boot <ifc_file>\n".
"(Sets network configurations for booting)\n");
}
open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>;
chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); }
if (-e "$ARGV[$0]" ) {
open(IN,$ARGV[$0]) || die("Couldn't open $ARGV[$0]\n");
} elsif (-e "/usr/testbed/etc/$ARGV[$0]") {
open(IN,"/usr/testbed/etc/$ARGV[$0]") ||
die("Couldn't open /usr/testbed/etc/$ARGV[$0]\n");
} else {
die ("Couldn't locate $ARGV[$0]\n");
}
my $last = "";
my $OS = "";
my $IP = "";
my $IF = 0;
my $ifstr = "";
my $newIP = "";
print "Reading input file...\n";
while (<IN>) {
chop;
s/\#(.*)//;
if ($_ eq "") {next;}
#print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_);
#print "Config $IP, interface $IF, to IP $newIP\n";
#if its not the same as the last one, get the OS
if ( $IP ne $last ) {
$last = $IP;
if (-e "/bin/ping") {
open(PING,"/bin/ping -c 1 $IP 2>&1 |");
} else {
open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
}
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ );
print "Got $1 ping packet(s) back from $IP.\n";
if ( $1 > 0 ) {
open(UNAME,"rsh $IP uname -a 2>&1 |");
$_ = <UNAME>;
#print $_;
if ($_ ) { @temp = split(" ",$_); $OS = $temp[$0]; }
} else {
$ifstr="";
}
print "OS for $IP is $OS \t";
if ($OS eq "Linux") { $ifstr="eth"; }
elsif ($OS eq "FreeBSD") { $ifstr="fxp"; }
else { $ifstr = ""; }
if ($ifstr) { print "Using interface string \"$ifstr\"\n"; }
}
#Until I can do FreeBSD with this too,
if ( $ifstr eq "FreeBSD" ) { $ifstr=""; }
#Set up the interface
if ( $ifstr eq "" ) {
print "Unknown OS $OS on $IP. Skipping interface $IF.\n";
next;
}
@_ = split(/./,$newIP);
my $network=join(".",@_[0-2]);
my $file =
"DEVICE=$ifstr$IF\n".
"IPADDR=$newIP\n".
"NETMASK=255.255.255.0\n".
"NETWORK=$network.0\n".
"BROADCAST=$network.255\n".
"ONBOOT=yes\n".
"BOOTPROTO=bootp\n".
"USERCTL=no\n";
print "Setting $IP $ifstr$IF to $newIP...\n";
open(TEMP,">/tmp/ifc_boot_file");
print TEMP $file;
close(TEMP);
my $host = `uname -n`;
$host =~ s/\n//;
open(IFC,
"rsh $IP rcp $host:/tmp/ifc_boot_file ".
"/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF |"
);
while ( <IFC> ) {
print ">> $_";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment