adjust_apache updated to consolidate hostnames for manangement ip, duplicate hostname lines cause trouble

This commit is contained in:
Jed Reynolds
2020-02-24 15:42:28 -08:00
parent f8ad1b53c9
commit 8f38e50513

View File

@@ -56,24 +56,44 @@ if (-f "$fname") {
open(FILE, ">$fname") or die "Couldn't open file: $fname for writing: $!\n\n"; open(FILE, ">$fname") or die "Couldn't open file: $fname for writing: $!\n\n";
my $foundit = 0; my $foundit = 0;
my $i; my $i;
chomp(@lines);
# we want to consolidate the $ip $hostname entry for MgrHostname
my @newlines = ();
my %more_hostnames = ("lanforge-srv" => 1);
my $new_entry = "$ip ";
my $blank = 0;
my $was_blank = 0;
for ($i = 0; $i<@lines; $i++) { for my $ln (@lines) {
my $ln =$lines[$i]; $was_blank = $blank;
chomp($ln); $blank = ($ln =~ /^\s*$/) ? 1 : 0;
if ($ln =~ /^###-LF-HOSTAME-NEXT-###/) { next if ($blank && $was_blank);
print FILE "$ln\n"; next if ($ln =~/^$ip $MgrHostname$/);
print FILE "$ip $MgrHostname\n"; next if ($ln =~ /^###-LF-HOSTAME-NEXT-###/);
$i++; if ($ln =~ /\b($MgrHostname|lanforge-srv|$ip)\b/) {
$foundit = 1; print "Matching LINE $ln\n";
} my @hunks = split(/\s+/, $ln);
else { for my $hunk (@hunks) {
print FILE "$ln\n"; #print "HUNK{$hunk} ";
next if ($hunk =~ /^($ip|lanforge-srv|$MgrHostname)$/);
$more_hostnames{$hunk} = 1;
}
next;
} }
print "ok ln[$ln]\n";
push(@newlines, $ln);
} }
if (!$foundit) { push(@newlines, "###-LF-HOSTAME-NEXT-###");
print FILE "###-LF-HOSTAME-NEXT-###\n";
print FILE "$ip $MgrHostname"; for my $ln (@newlines) {
print FILE "$ln\n";
} }
print FILE "$ip $MgrHostname";
for my $name (keys %more_hostnames) {
print FILE " $name";
}
print FILE "\n\n";
close FILE; close FILE;
} }