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