]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/Setup/Ubuntu.pm
fix typo
[pve-container.git] / src / PVE / LXC / Setup / Ubuntu.pm
CommitLineData
7af97ad5 1package PVE::LXC::Setup::Ubuntu;
a8e58e9c
DM
2
3use strict;
4use warnings;
5use Data::Dumper;
6use PVE::Tools;
7use PVE::LXC;
8use File::Path;
9
7af97ad5 10use PVE::LXC::Setup::Debian;
a8e58e9c 11
7af97ad5 12use base qw(PVE::LXC::Setup::Debian);
a8e58e9c 13
91bf89e1 14my $known_versions = {
1c5e428d 15 '16.04' => 1, # xenial
90c85c7d 16 '15.10' => 1, # wily
91bf89e1
DM
17 '15.04' => 1, # vivid
18 '14.04' => 1, # trusty LTS
19 '12.04' => 1, # precise LTS
20};
21
a8e58e9c
DM
22sub 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
40dee029
DM
37 die "unsupported Ubuntu version '$version'\n"
38 if !$known_versions->{$version};
a8e58e9c
DM
39
40 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
41
27916659 42 $conf->{ostype} = "ubuntu";
a8e58e9c
DM
43
44 return bless $self, $class;
45}
46
47sub template_fixup {
48 my ($self, $conf) = @_;
49
91bf89e1 50 my $version = $self->{version};
a8e58e9c 51
1c5e428d 52 if ($version eq '15.04' || $version eq '15.10' || $version eq '16.04') {
a8e58e9c 53 # edit /etc/securetty (enable login on console)
b7cd927f 54 $self->setup_securetty($conf, qw(pts/0));
a8e58e9c 55 }
91bf89e1
DM
56
57 if ($version eq '12.04') {
58 # suppress log level output for udev
2063d380
WB
59 my $filename = '/etc/udev/udev.conf';
60 my $data = $self->ct_file_get_contents($filename);
91bf89e1 61 $data =~ s/=\"err\"/=0/m;
2063d380 62 $self->ct_file_set_contents($filename, $data);
91bf89e1 63 }
a8e58e9c
DM
64}
65
66sub setup_init {
67 my ($self, $conf) = @_;
68
c40a11f2 69 my $version = $self->{version};
a8e58e9c 70
c40a11f2 71 if ($version eq '12.04' || $version eq '14.04') {
1b4cf758 72 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
c40a11f2 73 for (my $i = 1; $i < 7; $i++) {
2063d380 74 my $filename = "/etc/init/tty$i.conf";
c40a11f2
DM
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
82start on stopped rc RUNLEVEL=[2345] and (
83 not-container or
84 container CONTAINER=lxc or
85 container CONTAINER=lxc-libvirt)
86
87stop on runlevel [!2345]
88
89respawn
90exec /sbin/getty -8 38400 tty$i
91__EOD__
2063d380 92 $self->ct_file_set_contents($filename, $tty_conf);
c40a11f2
DM
93 } else {
94 for (my $i = $ttycount + 1; $i < 7; $i++) {
2063d380 95 $self->ct_unlink($filename);
c40a11f2
DM
96 }
97 }
98 }
99 }
a8e58e9c
DM
100}
101
1021;