Commit a82e9d3d authored by Mac Newbold's avatar Mac Newbold

Fixed problems, taught freebsd to ifc_boot. These will soon be deprecated in

favor of ifc_setup, which performs both functions.
parent e47e4b33
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
my $rsh = "ssh"; my $rsh = "ssh";
if ( $#ARGV < 0) { if ( $#ARGV < 0) {
die("Usage: ifc_all <ifc_file>\n"); die("Usage: ifc_all <ifc_file>\n".
"Sets current network configurations.\n".
"(Changes lost when rebooted. See also ifc_boot.)\n");
} }
open(WHO,"/usr/bin/whoami 2>&1 |"); open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>; $_ = <WHO>;
...@@ -19,7 +21,7 @@ if (-e "$ARGV[$0]" ) { ...@@ -19,7 +21,7 @@ if (-e "$ARGV[$0]" ) {
die ("Couldn't locate $ARGV[$0]\n"); die ("Couldn't locate $ARGV[$0]\n");
} }
my $last = ""; my $last = "";
my $OS = ""; my $OS = "Unknown";
my $IP = ""; my $IP = "";
my $IF = 0; my $IF = 0;
my $ifstr = ""; my $ifstr = "";
...@@ -27,7 +29,9 @@ my $newIP = ""; ...@@ -27,7 +29,9 @@ my $newIP = "";
print "Reading input file...\n"; print "Reading input file...\n";
while (<IN>) { while (<IN>) {
chop; chop;
s/\#(.*)//; s/\s*\#(.*)//;
s/^\s+$//;
s/\s+/ /g;
if ($_ eq "") {next;} if ($_ eq "") {next;}
#print "Got $_\n"; #print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_); ($IP,$IF,$newIP)= split(" ",$_);
...@@ -47,19 +51,17 @@ while (<IN>) { ...@@ -47,19 +51,17 @@ while (<IN>) {
$_ = <UNAME>; $_ = <UNAME>;
#print $_; #print $_;
if ($_ ) { @temp = split(" ",$_); $OS = $temp[$0]; } if ($_ ) { @temp = split(" ",$_); $OS = $temp[$0]; }
} else { }
$ifstr="";
}
print "OS for $IP is $OS \t"; print "OS for $IP is $OS \t";
if ($OS eq "Linux") { $ifstr="eth"; } if ($OS eq "Linux") { $ifstr="eth"; }
elsif ($OS eq "FreeBSD") { $ifstr="fxp"; } elsif ($OS eq "FreeBSD") { $ifstr="fxp"; }
else { $ifstr = ""; } else { $ifstr = ""; }
if ($ifstr) { print "Using interface string \"$ifstr\"\n"; } if ($ifstr) { print "Using interface string '$ifstr'\n"; }
} }
#Set up the interface #Set up the interface
if ( $ifstr eq "" ) { if ( $ifstr eq "" ) {
print "Unknown OS $OS on $IP. Skipping interface $IF.\n"; print "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next; next;
} }
print "Setting $IP $ifstr$IF to $newIP...\n"; print "Setting $IP $ifstr$IF to $newIP...\n";
......
...@@ -3,14 +3,18 @@ ...@@ -3,14 +3,18 @@
my $rsh = "ssh"; my $rsh = "ssh";
my $rcp = "scp"; my $rcp = "scp";
$| = 1; #Turn off line buffering on output
if ( $#ARGV < 0) { if ( $#ARGV < 0) {
die("Usage: ifc_boot <ifc_file>\n". die("Usage: ifc_boot <ifc_file>\n".
"(Sets network configurations for booting)\n"); "Sets network configurations for booting.\n".
"(Does not have any effect until rebooted. See also ifc_all.)\n");
} }
open(WHO,"/usr/bin/whoami 2>&1 |"); open(WHO,"/usr/bin/whoami 2>&1 |");
$_ = <WHO>; $_ = <WHO>;
chop; chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); } if ($_ ne "root") { die("This won't work unless you're root.\n"); }
close(WHO);
if (-e "$ARGV[$0]" ) { if (-e "$ARGV[$0]" ) {
open(IN,$ARGV[$0]) || die("Couldn't open $ARGV[$0]\n"); open(IN,$ARGV[$0]) || die("Couldn't open $ARGV[$0]\n");
...@@ -21,74 +25,116 @@ if (-e "$ARGV[$0]" ) { ...@@ -21,74 +25,116 @@ if (-e "$ARGV[$0]" ) {
die ("Couldn't locate $ARGV[$0]\n"); die ("Couldn't locate $ARGV[$0]\n");
} }
my $last = ""; my $last = "";
my $OS = ""; my $OS = "Unknown";
my $IP = ""; my $IP = "";
my $IF = 0; my $IF = 0;
my $ifstr = ""; my $ifstr = "";
my $newIP = ""; my $newIP = "";
print "Reading input file...\n"; print "Reading input file...\n";
while (<IN>) { while (<IN>) {
chop; chop;
s/\#(.*)//; s/\s*\#(.*)//;
if ($_ eq "") {next;} s/^\s+$//;
#print "Got $_\n"; s/\s+/ /g;
($IP,$IF,$newIP)= split(" ",$_); if ($_ eq "") {next;}
#print "Config $IP, interface $IF, to IP $newIP\n"; #print "Got $_\n";
#if its not the same as the last one, get the OS ($IP,$IF,$newIP)= split(" ",$_);
if ( $IP ne $last ) { #print "Config $IP, interface $IF, to IP $newIP\n";
$last = $IP; #if its not the same as the last one, get the OS
if (-e "/bin/ping") { if ( $IP ne $last ) {
open(PING,"/bin/ping -c 1 $IP 2>&1 |"); $last = $IP;
} else { print "Pinging $IP...";
open(PING,"/sbin/ping -c 1 $IP 2>&1 |"); if (-e "/bin/ping") {
} open(PING,"/bin/ping -c 1 $IP 2>&1 |");
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ ); } else {
print "Got $1 ping packet(s) back from $IP.\n"; open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
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"; }
} }
do { } until ( <PING> =~ /transmitted, (\d*) packets received/ );
#Until I can do FreeBSD with this too, print "Got $1 ping packet(s) back from $IP.\n";
if ( $ifstr eq "FreeBSD" ) { $ifstr=""; } if ( $1 > 0 ) {
open(UNAME,"$rsh $IP uname -a 2>&1 |");
#Set up the interface $_ = <UNAME>;
if ( $ifstr eq "" ) { #print $_;
print "Unknown OS $OS on $IP. Skipping interface $IF.\n"; if ($_ ) { @temp = split(" ",$_); $OS = $temp[$0]; }
next; } else {
print STDERR "Can't reach $IP with ping. Skipping interface $IF.\n";
$OS = "_NO_PING_";
next;
}
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"; }
} else {
if ($OS eq "_NO_PING_") {
print STDERR "Can't reach $IP with ping. Skipping interface $IF.\n";
next;
} }
@_ = split(/./,$newIP); }
my $network=join(".",@_[0-2]); #Set up the interface
my $file = if ( $ifstr eq "" ) {
"DEVICE=$ifstr$IF\n". print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
"IPADDR=$newIP\n". next;
"NETMASK=255.255.255.0\n". } elsif ( $OS eq "Linux" ) {
"NETWORK=$network.0\n". @_ = split(/\./,$newIP);
"BROADCAST=$network.255\n". my $network = join(".",@_[0..2]);
"ONBOOT=yes\n".
"BOOTPROTO=bootp\n".
"USERCTL=no\n";
print "Setting $IP $ifstr$IF to $newIP...\n"; print "Setting $IP $ifstr$IF to $newIP...\n";
open(TEMP,">/tmp/ifc_boot_file"); open(TEMP,">/tmp/ifc_boot_file");
print TEMP $file; print TEMP "DEVICE=$ifstr$IF\nIPADDR=$newIP\nNETMASK=255.255.255.0\n".
"NETWORK=$network.0\nBROADCAST=$network.255\nONBOOT=yes\n".
"BOOTPROTO=bootp\nUSERCTL=no\n";
close(TEMP); close(TEMP);
my $host = `uname -n`; open(IFC, "$rcp /tmp/ifc_boot_file ".
$host =~ s/\n//; "$IP:/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF 2>&1 |");
open(IFC, } elsif ($OS eq "FreeBSD") {
"$rcp /tmp/ifc_boot_file ". my $exists = 0;
"$IP:/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF |" print "Setting $IP $ifstr$IF to $newIP...\n";
); open(EXISTS, "$rsh $IP ls /etc/rc.conf.local 2>&1 |");
while ( <IFC> ) { while ( <EXISTS> ) { if ( ! /No such file/ ) { $exists = 1; } }
print ">> $_"; close(EXISTS);
} open(TEMP,">/tmp/ifc_boot_file");
if ($exists) {
open(COPY, "$rcp $IP:/etc/rc.conf.local /etc/ifc_boot_input 2>&1 |");
while ( <COPY> ) { print "COPY>> $_"; }
close(COPY);
open(CONF,"/etc/ifc_boot_input");
while ( <CONF> ) {
print "CONF>>$_";
if ( ! /ifconfig_fxp$IF=/ ) {
if ( /network_interfaces\s*=\s*\"([A-Za-z0-9_ ]*)\"/ ) {
$_ = $1;
s/\s+/ /g;
s/^\s+//g;
s/\s+$//g;
my @ifcs = split(" ",$_);
print TEMP "network_interfaces=\"";
foreach my $ifc (@ifcs) {
if ($ifc ne "fxp$IF") { print TEMP "$ifc "; }
}
print TEMP "fxp$IF\"\n";
}
print TEMP $_;
print "KEPT\n";
}
}
close(CONF);
} else { print TEMP "network_interfaces=\"fxp$IF lo0\"\n"; }
print TEMP "ifconfig_fxp$IF=\"inet $newIP netmask 255.255.255.0\"\n";
close(TEMP);
open(IFC,"$rcp /tmp/ifc_boot_file $IP:/etc/rc.conf.local 2>&1 |");
} else {
print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
}
while ( <IFC> ) {
print ">> $_";
}
close(IFC);
} }
close(IN);
print "End of input file.\nDone.\n";
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