]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/Setup/Alpine.pm
alpine: fix getty line removal
[pve-container.git] / src / PVE / LXC / Setup / Alpine.pm
CommitLineData
a8700492
JV
1package PVE::LXC::Setup::Alpine;
2
3use strict;
4use warnings;
5
a8700492
JV
6use PVE::LXC;
7use PVE::Network;
8use File::Path;
9
10use PVE::LXC::Setup::Base;
d93a2739 11use PVE::LXC::Setup::Debian;
a8700492
JV
12
13use base qw(PVE::LXC::Setup::Base);
14
15sub new {
16 my ($class, $conf, $rootdir) = @_;
b46d6081
WB
17
18 my $version = PVE::Tools::file_read_firstline("$rootdir/etc/alpine-release");
19
20 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
a8700492
JV
21 $conf->{ostype} = "alpine";
22 return bless $self, $class;
23}
24
25sub template_fixup {
26 my ($self, $conf) = @_;
855b0646 27
a8700492
JV
28 # enable networking service
29 $self->ct_symlink('/etc/init.d/networking',
30 '/etc/runlevels/boot/networking');
31 # fixup any symlinks
32 $self->ct_symlink('/etc/init.d/bootmisc',
33 '/etc/runlevels/boot/bootmisc');
34 $self->ct_symlink('/etc/init.d/hostname',
e9076752
WB
35 '/etc/runlevels/boot/hostname');
36 # fix stop system
a8700492 37 $self->ct_symlink('/etc/init.d/killprocs',
e9076752 38 '/etc/runlevels/shutdown/killprocs');
a8700492 39 $self->ct_symlink('/etc/init.d/savecache',
e9076752 40 '/etc/runlevels/shutdown/savecache');
6077b5dd
TL
41
42 $self->setup_securetty($conf, qw(lxc/console lxc/tty1 lxc/tty2 lxc/tty3 lxc/tty4));
a8700492
JV
43}
44
45sub setup_init {
0c63baec
TL
46 my ($self, $conf) = @_;
47
48 my $filename = "/etc/inittab";
49 return if !$self->ct_file_exists($filename);
50
51 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
52 my $inittab = $self->ct_file_get_contents($filename);
53
54 my @lines = grep {
55 # remove getty lines
f4cd6178 56 !/^\s*tty\d+:\d*:[^:]*:.*getty/
0c63baec
TL
57 } split(/\n/, $inittab);
58
59 $inittab = join("\n", @lines) . "\n";
60
61 for (my $id = 1; $id <= $ttycount; $id++) {
62 next if $id == 7; # reserved for X11
63 $inittab .= "tty$id\::respawn:/sbin/getty 38400 tty$id\n";
64 }
65
66 $self->ct_file_set_contents($filename, $inittab);
a8700492
JV
67}
68
69sub setup_network {
d93a2739
WB
70 # Network is debian compatible, but busybox' udhcpc6 is unfinished
71 my ($self, $conf) = @_;
72
73 # XXX: udhcpc6 in busybox is broken; once a working alpine release comes
74 # we can remove this bit.
75 #
76 # Filter out ipv6 dhcp and turn it into 'manual' so they see what's up.
77 my $netconf = {};
78 my $networks = {};
79 foreach my $k (keys %$conf) {
80 next if $k !~ m/^net(\d+)$/;
81 my $netstring = $conf->{$k};
82 # check for dhcp6:
1b4cf758 83 my $d = PVE::LXC::Config->parse_lxc_network($netstring);
d93a2739
WB
84 if (defined($d->{ip6}) && $d->{ip6} eq 'dhcp') {
85 $d->{ip6} = 'manual';
1b4cf758 86 $netstring = PVE::LXC::Config->print_lxc_network($d);
d93a2739
WB
87 }
88 $netconf->{$k} = $netstring;
89 }
90
91 PVE::LXC::Setup::Debian::setup_network($self, $netconf);
a8700492
JV
92}
93
941;