1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#!/usr/bin/perl
$interfaces=$ARGV[0];
$networkscriptdir=$ARGV[1];
open(INTERFACES,"$interfaces") || die "interfaces: $interfaces $!\n";
chdir($networkscriptdir) || die "Can not chdir to $networkscriptdir: $!\n";
$stanza=0;
while(<INTERFACES>) {
next if (/^\#/);
chop;
if($stanza) {
if(/^\s*address\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
print IFCFG "IPADDR=$1\n";
next;
} elsif(/^\s*network\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
print IFCFG "NETMASK=$1\n";
next;
} elsif(/^\s*netmask\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
print IFCFG "NETMASK=$1\n";
next;
} elsif(/^\s*broadcast\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
print IFCFG "BROADCAST=$1\n";
next;
} elsif(/^\s*gateway\s*([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)/) {
print IFCFG "GATEWAY=$1\n";
print IFCFG "GATEWAYDEV=$device\n";
} elsif(/^\s*up\s*route\s*add\s*-(.*)/) {
open(STATICROUTES, ">>../static-routes") || die "can not open ../static-routes: $!\n";
print STATICROUTES "$device $1\n";
close(STATICROUTES);
} elsif(/iface/) {
close(IFCFG);
$stanza=0;
} elsif(/^$/) {
close(IFCFG);
$stanza=0;
next;
} else {
print STDERR "ignoring command $_\n";
}
}
if(!$stanza) {
#print "Processing $_\n";
if(/\s*iface (.*) inet static/) {
$device=$1;
$stanza=1;
open(IFCFG, ">ifcfg-$device") || die "Can not open ifcfg-$device: $!\n";
print IFCFG "ONBOOT=yes\n";
}
}
}
|