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 @@
my $rsh = "ssh";
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 |");
$_ = <WHO>;
......@@ -19,7 +21,7 @@ if (-e "$ARGV[$0]" ) {
die ("Couldn't locate $ARGV[$0]\n");
}
my $last = "";
my $OS = "";
my $OS = "Unknown";
my $IP = "";
my $IF = 0;
my $ifstr = "";
......@@ -27,7 +29,9 @@ my $newIP = "";
print "Reading input file...\n";
while (<IN>) {
chop;
s/\#(.*)//;
s/\s*\#(.*)//;
s/^\s+$//;
s/\s+/ /g;
if ($_ eq "") {next;}
#print "Got $_\n";
($IP,$IF,$newIP)= split(" ",$_);
......@@ -47,19 +51,17 @@ while (<IN>) {
$_ = <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"; }
if ($ifstr) { print "Using interface string '$ifstr'\n"; }
}
#Set up the interface
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;
}
print "Setting $IP $ifstr$IF to $newIP...\n";
......
......@@ -3,14 +3,18 @@
my $rsh = "ssh";
my $rcp = "scp";
$| = 1; #Turn off line buffering on output
if ( $#ARGV < 0) {
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 |");
$_ = <WHO>;
chop;
if ($_ ne "root") { die("This won't work unless you're root.\n"); }
close(WHO);
if (-e "$ARGV[$0]" ) {
open(IN,$ARGV[$0]) || die("Couldn't open $ARGV[$0]\n");
......@@ -21,74 +25,116 @@ if (-e "$ARGV[$0]" ) {
die ("Couldn't locate $ARGV[$0]\n");
}
my $last = "";
my $OS = "";
my $OS = "Unknown";
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"; }
chop;
s/\s*\#(.*)//;
s/^\s+$//;
s/\s+/ /g;
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;
print "Pinging $IP...";
if (-e "/bin/ping") {
open(PING,"/bin/ping -c 1 $IP 2>&1 |");
} else {
open(PING,"/sbin/ping -c 1 $IP 2>&1 |");
}
#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;
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 {
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]);
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";
}
#Set up the interface
if ( $ifstr eq "" ) {
print STDERR "Can't configure OS '$OS' on $IP. Skipping interface $IF.\n";
next;
} elsif ( $OS eq "Linux" ) {
@_ = split(/\./,$newIP);
my $network = join(".",@_[0..2]);
print "Setting $IP $ifstr$IF to $newIP...\n";
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);
my $host = `uname -n`;
$host =~ s/\n//;
open(IFC,
"$rcp /tmp/ifc_boot_file ".
"$IP:/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF |"
);
while ( <IFC> ) {
print ">> $_";
}
open(IFC, "$rcp /tmp/ifc_boot_file ".
"$IP:/etc/sysconfig/network-scripts/ifcfg-$ifstr$IF 2>&1 |");
} elsif ($OS eq "FreeBSD") {
my $exists = 0;
print "Setting $IP $ifstr$IF to $newIP...\n";
open(EXISTS, "$rsh $IP ls /etc/rc.conf.local 2>&1 |");
while ( <EXISTS> ) { if ( ! /No such file/ ) { $exists = 1; } }
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