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