summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/network/network.pm19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/network/network.pm b/lib/network/network.pm
index eb88435..fa8df00 100644
--- a/lib/network/network.pm
+++ b/lib/network/network.pm
@@ -243,16 +243,23 @@ sub add2hosts {
my $file = "$::prefix/etc/hosts";
- my %l;
+ my @l;
+ push(@l, [$_, $hostname, if_($sub_hostname, $sub_hostname)]) foreach(@ips);
foreach (cat_($file)) {
+ # strip our own comments
+ next if ($_ =~ /# generated by drak.*/);
my ($ip, $aliases) = /^\s*(\S+)\s+(\S+.*)$/ or next;
- push @{$l{$ip}}, difference2([ split /\s+/, $aliases ], [ $hostname, $sub_hostname ]);
- } cat_($file);
-
- unshift @{$l{$_}}, $hostname, if_($sub_hostname, $sub_hostname) foreach grep { $_ } @ips;
+ my @hosts = difference2([ split /\s+/, $aliases ], [ $hostname, $sub_hostname ]);
+ if (@hosts) {
+ push (@l, [$ip, @hosts]);
+ }
+ };
log::explanations("writing host information to $file");
- output($file, map { "$_\t\t" . join(" ", @{$l{$_}}) . "\n" } keys %l);
+ output($file, "# generated by drakconnect\n");
+ foreach (@l) {
+ append_to_file($file, join(" ", @{$_}) . "\n");
+ }
}
# The interface/gateway needs to be configured before this will work!