]> git.proxmox.com Git - pve-container.git/commitdiff
Close #999: gentoo: hostname is in /etc/conf.d/hostname
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Mon, 23 May 2016 10:53:06 +0000 (12:53 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 23 May 2016 14:55:41 +0000 (16:55 +0200)
This is also a shell-style assignment but should only
contain the hostname and nothing else. Although if someone
complains we could switch to ct_modify_file there as well.

src/PVE/LXC/Setup/Gentoo.pm

index 762cb748f199001429adfba4c9973aa7d327ac59..c1810bbcf5a9dd3ac51275e999b9a4fcdc418f73 100644 (file)
@@ -149,4 +149,37 @@ sub setup_network {
     }
 }
 
+sub set_hostname {
+    my ($self, $conf) = @_;
+
+    my $hostname = $conf->{hostname} || 'localhost';
+
+    my $namepart = ($hostname =~ s/\..*$//r);
+
+    my $hostname_fn = "/etc/conf.d/hostname";
+
+    my $oldname = 'localhost';
+    my $fh = $self->ct_open_file_read($hostname_fn);
+    while (defined(my $line = <$fh>)) {
+       chomp $line;
+       next if $line =~ /^\s*(#.*)?$/;
+       if ($line =~ /^\s*hostname=("[^"]*"|'[^']*'|\S*)\s*$/) {
+           $oldname = $1;
+           last;
+       }
+    }
+    $fh->close();
+
+    my ($ipv4, $ipv6) = PVE::LXC::get_primary_ips($conf);
+    my $hostip = $ipv4 || $ipv6;
+
+    my ($searchdomains) = $self->lookup_dns_conf($conf);
+
+    $self->update_etc_hosts($hostip, $oldname, $hostname, $searchdomains);
+
+    # This is supposed to contain only the hostname, so we just replace the
+    # file.
+    $self->ct_file_set_contents($hostname_fn, "hostname=\"$namepart\"\n");
+}
+
 1;