diff --git a/adjust_apache.pl b/adjust_apache.pl index f694d4e4..93b64137 100755 --- a/adjust_apache.pl +++ b/adjust_apache.pl @@ -6,6 +6,13 @@ use diagnostics; use Carp; use Data::Dumper; +my @idhunks = split(' ', `id`); +my @hunks = grep { /uid=/ } @idhunks; +die ("Must be root to use this") + unless( $hunks[0] eq "uid=0(root)" ); + +my $MgrHostname = "lanforge-srv"; + my $config_v = "/home/lanforge/config.values"; # grab the config.values file die ("Unable to find $config_v" ) @@ -33,17 +40,27 @@ die ("No ip found for mgt_dev") print "ip: $ip\n"; my @host_lines = `cat /etc/hosts`; -chomp (@host_lines0; +chomp (@host_lines); @host_lines = ("127.0.0.1 localhost", @host_lines) if (@host_lines < 1); for (my $i =$#host_lines-1; $i>=0; $i--) { - print "$i\n"; my $line = $host_lines[$i]; - if ($line =~ /lanforge-mgr/) { - + if ($line =~ /$MgrHostname/) { + splice(@host_lines, $i, 1); } } -@host_lines = (@host_lines, - +@host_lines = (@host_lines, ("$ip $MgrHostname", "\n")); +my $dt = `date +%Y%m%d-%H%M%s`; +chomp $dt; +print "dt[$dt]\n"; +print "cp /etc/hosts /etc/.hosts.$dt\n"; +print "=======================================\n"; +print join("\n", @host_lines); +print "=======================================\n"; +die ("Unable to write to /etc/hosts: $!") + unless open(my $fh, ">", "/etc/hosts"); +print $fh join("\n", @host_lines); +close $fh; +print "Updated /etc/hosts\n"; # grab the 0000-default.conf file