Line 0
Link Here
|
|
|
1 |
package PVE::LXC::Setup::ALTLinux; |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
use PVE::LXC::Setup::Base; |
6 |
use base qw(PVE::LXC::Setup::Base); |
7 |
|
8 |
sub new { |
9 |
my $ostype = "altlinux"; |
10 |
my ($class, $conf, $rootdir) = @_; |
11 |
my $version = PVE::Tools::file_read_firstline("$rootdir/etc/$ostype-release"); |
12 |
my $self = { conf => $conf, rootdir => $rootdir, version => $version }; |
13 |
$conf->{ostype} = $ostype; |
14 |
return bless $self, $class; |
15 |
} |
16 |
|
17 |
sub set_hostname { |
18 |
my ($self, $conf) = @_; |
19 |
# Redhat wants the fqdn in /etc/sysconfig/network's HOSTNAME |
20 |
my $hostname = $conf->{hostname} || 'localhost'; |
21 |
my $sysconfig_network = "/etc/sysconfig/network"; |
22 |
my $oldname; |
23 |
my $data = $self->ct_file_get_contents($sysconfig_network); |
24 |
if ($data =~ m/^HOSTNAME=\s*(\S+)\s*$/m){ |
25 |
$oldname = $1; |
26 |
} |
27 |
my $hosts_fn = "/etc/hosts"; |
28 |
my ($ipv4, $ipv6) = PVE::LXC::get_primary_ips($conf); |
29 |
my $hostip = $ipv4 || $ipv6; |
30 |
my ($searchdomains) = $self->lookup_dns_conf($conf); |
31 |
$self->update_etc_hosts($hostip, $oldname, $hostname, $searchdomains); |
32 |
if ($self->ct_file_exists($sysconfig_network)){ |
33 |
my $data = $self->ct_file_get_contents($sysconfig_network); |
34 |
if ($data !~ s/^HOSTNAME=\h*(\S+)\h*$/HOSTNAME=$hostname/m){ |
35 |
$data .= "HOSTNAME=$hostname\n"; |
36 |
} |
37 |
$self->ct_file_set_contents($sysconfig_network, $data); |
38 |
} |
39 |
} |
40 |
|
41 |
sub setup_init { |
42 |
my ($self, $conf) = @_; |
43 |
my $filename = "/etc/inittab"; |
44 |
return if !$self->ct_file_exists($filename); |
45 |
my $ttycount = PVE::LXC::Config->get_tty_count($conf); |
46 |
my $inittab = $self->ct_file_get_contents($filename); |
47 |
my @lines = grep { |
48 |
# remove getty lines |
49 |
!/^\s*\d+:\d+:[^:]*:.*getty/ && |
50 |
# remove power lines |
51 |
!/^\s*p[fno0]:/ |
52 |
} split(/\n/, $inittab); |
53 |
$inittab = join("\n", @lines) . "\n"; |
54 |
$inittab .= "p0::powerfail:/sbin/shutdown -f -h +2 \"Power failure, system shutting down...\"\n"; |
55 |
for (my $id = 1; $id <= $ttycount; $id++){ |
56 |
next if $id == 7; # reserved for X11 |
57 |
my $levels = ($id == 1) ? '234' : '2345'; |
58 |
$inittab .= "$id:$levels:respawn:/sbin/mingetty tty$id\n"; |
59 |
} |
60 |
$self->ct_file_set_contents($filename, $inittab); |
61 |
} |
62 |
|
63 |
sub setup_network { |
64 |
my ($self, $conf) = @_; |
65 |
# my $gw; |
66 |
foreach my $k (keys %$conf) { |
67 |
next if $k !~ m/^net(\d+)$/; |
68 |
my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k}); |
69 |
next if !$d->{name}; |
70 |
my $ifpath = "/etc/net/ifaces/$d->{name}"; |
71 |
$self->ct_make_path($ifpath); |
72 |
my $optfile = "$ifpath/options"; |
73 |
my $addrfile = "$ifpath/ipv4address"; |
74 |
my $routefile = "$ifpath/ipv4route"; |
75 |
my $options = "TYPE=eth\n"; |
76 |
my $address = ''; |
77 |
my $routes = ''; |
78 |
if ($d->{ip} && $d->{ip} ne 'manual'){ |
79 |
if ($d->{ip} eq 'dhcp'){ |
80 |
$options .= "BOOTPROTO=dhcp\n"; |
81 |
} else { |
82 |
$options .= "BOOTPROTO=static\n"; |
83 |
$address = "$d->{ip}\n"; |
84 |
if (defined($d->{gw})){ |
85 |
$routes .= "default via $d->{gw}\n"; |
86 |
$self->ct_modify_file($routefile, $routes, delete => 1, prepend => 1); |
87 |
} |
88 |
$self->ct_file_set_contents($addrfile, $address); |
89 |
} |
90 |
$self->ct_file_set_contents($optfile, $options); |
91 |
} |
92 |
} |
93 |
} |
94 |
|
95 |
1; |