]>
git.proxmox.com Git - pve-container.git/blob - src/PVE/LXCSetup/Base.pm
1 package PVE
::LXCSetup
::Base
;
9 my ($etc_hosts_data, $hostip, $oldname, $newname) = @_;
11 # fixme: searchdomain ?
17 foreach my $line (split(/\n/, $etc_hosts_data)) {
18 if ($line =~ m/^#/ || $line =~ m/^\s*$/) {
23 my ($ip, @names) = split(/\s+/, $line);
24 if (($ip eq '127.0.0.1') || ($ip eq '::1')) {
30 foreach my $name (@names) {
31 if ($name eq $oldname || $name eq $newname) {
34 # fixme: record extra names?
37 $found = 1 if defined($hostip) && ($ip eq $hostip);
41 if (defined($hostip)) {
42 push @lines, "$ip $newname";
44 push @lines, "127.0.1.1 $newname";
55 if (defined($hostip)) {
56 push @lines, "$hostip $newname";
58 push @lines, "127.0.1.1 $newname";
62 my $found_localhost = 0;
63 foreach my $line (@lines) {
64 if ($line =~ m/^127.0.0.1\s/) {
70 if (!$found_localhost) {
71 unshift @lines, "127.0.0.1 localhost.localnet localhost";
74 $etc_hosts_data = join("\n", @lines) . "\n";
76 return $etc_hosts_data;
80 my ($class, $conf) = @_;
82 my $hostname = $conf->{'lxc.utsname'} || 'debian';
84 $hostname =~ s/\..*$//;
86 my $rootfs = $conf->{'lxc.rootfs'};
88 my $hostname_fn = "$rootfs/etc/hostname";
90 my $oldname = PVE
::Tools
::file_read_firstline
($hostname_fn) || 'debian';
92 my $hosts_fn = "$rootfs/etc/hosts";
93 my $etc_hosts_data = '';
96 $etc_hosts_data = PVE
::Tools
::file_get_contents
($hosts_fn);
99 my $hostip = undef; # fixme;
101 $etc_hosts_data = change_hostname
($etc_hosts_data, $hostip, $oldname, $hostname);
103 PVE
::Tools
::file_set_contents
($hostname_fn, "$hostname\n");
104 PVE
::Tools
::file_set_contents
($hosts_fn, $etc_hosts_data);
108 my ($class, $conf) = @_;
110 die "please implement this inside subclass"
114 my ($class, $conf) = @_;
116 $class->setup_network($conf);
117 $class->set_hostname($conf);