]>
git.proxmox.com Git - pve-container.git/blob - src/PVE/LXCSetup/Base.pm
1 package PVE
::LXCSetup
::Base
;
7 my ($etc_hosts_data, $hostip, $oldname, $newname) = @_;
9 # fixme: searchdomain ?
15 foreach my $line (split(/\n/, $etc_hosts_data)) {
16 if ($line =~ m/^#/ || $line =~ m/^\s*$/) {
21 my ($ip, @names) = split(/\s+/, $line);
22 if (($ip eq '127.0.0.1') || ($ip eq '::1')) {
28 foreach my $name (@names) {
29 if ($name eq $oldname || $name eq $newname) {
32 # fixme: record extra names?
35 $found = 1 if defined($hostip) && ($ip eq $hostip);
39 if (defined($hostip)) {
40 push @lines, "$ip $newname";
42 push @lines, "127.0.1.1 $newname";
53 if (defined($hostip)) {
54 push @lines, "$hostip $newname";
56 push @lines, "127.0.1.1 $newname";
60 my $found_localhost = 0;
61 foreach my $line (@lines) {
62 if ($line =~ m/^127.0.0.1\s/) {
68 if (!$found_localhost) {
69 unshift @lines, "127.0.0.1 localhost.localnet localhost";
72 $etc_hosts_data = join("\n", @lines) . "\n";
74 return $etc_hosts_data;
78 my ($class, $conf) = @_;
80 my $hostname = $conf->{'lxc.utsname'} || 'debian';
82 $hostname =~ s/\..*$//;
84 my $rootfs = $conf->{'lxc.rootfs'};
86 my $hostname_fn = "$rootfs/etc/hostname";
88 my $oldname = PVE
::Tools
::file_read_firstline
($hostname_fn) || 'debian';
90 my $hosts_fn = "$rootfs/etc/hosts";
91 my $etc_hosts_data = '';
94 $etc_hosts_data = PVE
::Tools
::file_get_contents
($hosts_fn);
97 my $hostip = undef; # fixme;
99 $etc_hosts_data = change_hostname
($etc_hosts_data, $hostip, $oldname, $hostname);
101 PVE
::Tools
::file_set_contents
($hostname_fn, "$hostname\n");
102 PVE
::Tools
::file_set_contents
($hosts_fn, $etc_hosts_data);
106 my ($class, $conf) = @_;
108 $class->set_hostname($conf);
110 # fixme: what else (network, ...)