]> git.proxmox.com Git - pve-container.git/blob - src/PVE/LXC/Setup/Ubuntu.pm
fix typo
[pve-container.git] / src / PVE / LXC / Setup / Ubuntu.pm
1 package PVE::LXC::Setup::Ubuntu;
2
3 use strict;
4 use warnings;
5 use Data::Dumper;
6 use PVE::Tools;
7 use PVE::LXC;
8 use File::Path;
9
10 use PVE::LXC::Setup::Debian;
11
12 use base qw(PVE::LXC::Setup::Debian);
13
14 my $known_versions = {
15 '16.04' => 1, # xenial
16 '15.10' => 1, # wily
17 '15.04' => 1, # vivid
18 '14.04' => 1, # trusty LTS
19 '12.04' => 1, # precise LTS
20 };
21
22 sub new {
23 my ($class, $conf, $rootdir) = @_;
24
25 my $lsb_fn = "$rootdir/etc/lsb-release";
26 my $lsbinfo = PVE::Tools::file_get_contents($lsb_fn);
27
28 die "got unknown DISTRIB_ID\n" if $lsbinfo !~ m/^DISTRIB_ID=Ubuntu$/mi;
29
30 my $version;
31 if ($lsbinfo =~ m/^DISTRIB_RELEASE=(\d+\.\d+)$/mi) {
32 $version = $1;
33 }
34
35 die "unable to read version info\n" if !defined($version);
36
37 die "unsupported Ubuntu version '$version'\n"
38 if !$known_versions->{$version};
39
40 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
41
42 $conf->{ostype} = "ubuntu";
43
44 return bless $self, $class;
45 }
46
47 sub template_fixup {
48 my ($self, $conf) = @_;
49
50 my $version = $self->{version};
51
52 if ($version eq '15.04' || $version eq '15.10' || $version eq '16.04') {
53 # edit /etc/securetty (enable login on console)
54 $self->setup_securetty($conf, qw(pts/0));
55 }
56
57 if ($version eq '12.04') {
58 # suppress log level output for udev
59 my $filename = '/etc/udev/udev.conf';
60 my $data = $self->ct_file_get_contents($filename);
61 $data =~ s/=\"err\"/=0/m;
62 $self->ct_file_set_contents($filename, $data);
63 }
64 }
65
66 sub setup_init {
67 my ($self, $conf) = @_;
68
69 my $version = $self->{version};
70
71 if ($version eq '12.04' || $version eq '14.04') {
72 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
73 for (my $i = 1; $i < 7; $i++) {
74 my $filename = "/etc/init/tty$i.conf";
75 if ($i <= $ttycount) {
76 my $tty_conf = <<__EOD__;
77 # tty$i - getty
78 #
79 # This service maintains a getty on tty$i from the point the system is
80 # started until it is shut down again.
81
82 start on stopped rc RUNLEVEL=[2345] and (
83 not-container or
84 container CONTAINER=lxc or
85 container CONTAINER=lxc-libvirt)
86
87 stop on runlevel [!2345]
88
89 respawn
90 exec /sbin/getty -8 38400 tty$i
91 __EOD__
92 $self->ct_file_set_contents($filename, $tty_conf);
93 } else {
94 for (my $i = $ttycount + 1; $i < 7; $i++) {
95 $self->ct_unlink($filename);
96 }
97 }
98 }
99 }
100 }
101
102 1;