11 use POSIX qw
(LONG_MAX
);
15 # fixme: lock container ?
17 my $dablibdir = "/usr/lib/dab";
18 my $devicetar = "$dablibdir/devices.tar.gz";
19 my $default_env = "$dablibdir/scripts/defenv";
20 my $fake_init = "$dablibdir/scripts/init.pl";
21 my $script_ssh_init = "$dablibdir/scripts/ssh_gen_host_keys";
22 my $script_mysql_randompw = "$dablibdir/scripts/mysql_randompw";
23 my $script_init_urandom = "$dablibdir/scripts/init_urandom";
25 my $postfix_main_cf = <<EOD;
26 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
28 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
31 # appending .domain is the MUA's job.
32 append_dot_mydomain = no
34 # Uncomment the next line to generate "delayed mail" warnings
35 #delay_warning_time = 4h
37 alias_maps = hash:/etc/aliases
38 alias_database = hash:/etc/aliases
39 mydestination = \$myhostname, localhost.\$mydomain, localhost
41 mynetworks = 127.0.0.0/8
42 inet_interfaces = loopback-only
43 recipient_delimiter = +
45 compatibility_level = 2
49 # produce apt compatible filenames (/var/lib/apt/lists)
50 sub __url_to_filename
{
63 # systemd: true (except for devuan ostypes)
64 my $supported_suites = {
66 ostype
=> "debian-12",
69 ostype
=> "debian-11",
72 ostype
=> "debian-10",
75 ostype
=> "debian-9.0",
78 ostype
=> "debian-8.0",
84 ostype
=> "debian-7.0",
90 ostype
=> "debian-6.0",
96 ostype
=> "debian-5.0",
102 ostype
=> "debian-4.0",
105 # DEVUAN (imply systemd = 0 default)
108 ostype
=> "devuan-1.0",
112 ostype
=> "devuan-2.0",
115 ostype
=> "devuan-2.0",
118 ostype
=> "devuan-3.0",
121 ostype
=> "devuan-4.0",
124 ostype
=> "devuan-5.0",
132 ostype
=> "ubuntu-8.04",
139 ostype
=> "ubuntu-8.10",
146 ostype
=> "ubuntu-9.04",
153 ostype
=> "ubuntu-12.04",
160 ostype
=> "ubuntu-14.04",
164 ostype
=> "ubuntu-15.04",
168 ostype
=> "ubuntu-15.10",
172 ostype
=> "ubuntu-16.04",
176 ostype
=> "ubuntu-16.10",
180 ostype
=> "ubuntu-17.04",
184 ostype
=> "ubuntu-17.10",
188 ostype
=> "ubuntu-18.04",
192 ostype
=> "ubuntu-18.10",
196 ostype
=> "ubuntu-19.04",
200 ostype
=> "ubuntu-19.10",
204 ostype
=> "ubuntu-20.04",
208 ostype
=> "ubuntu-20.10",
212 ostype
=> "ubuntu-21.04",
216 ostype
=> "ubuntu-21.10",
220 ostype
=> "ubuntu-22.04",
224 ostype
=> "ubuntu-22.10",
232 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
235 $suiteinfo->{origin
} //= 'debian';
236 $suiteinfo->{suite
} //= $suite;
238 $suiteinfo->{flags
} //= {};
239 if ($suiteinfo->{ostype
} =~ /^devuan/) {
240 $suiteinfo->{flags
}->{systemd
} //= 0;
242 $suiteinfo->{flags
}->{systemd
} //= 1;
249 my ($self, $url, $path) = @_;
250 my $tmpfn = "$path.tmp$$";
252 $self->logmsg ("download: $url\n");
254 eval { $self->run_command ("wget -q '$url' -O '$tmpfn'") };
260 rename ($tmpfn, $path);
264 my ($data, $file, $perm) = @_;
266 die "no filename" if !$file;
270 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
271 die "unable to open file '$file'";
281 die "no filename" if !$file;
283 my $fh = IO
::File-
>new ($file) ||
284 die "unable to open file '$file'";
286 local $/; # slurp mode
300 my $fh = IO
::File-
>new ("<$filename") || return $res;
303 while (defined (my $line = <$fh>)) {
304 next if $line =~ m/^\#/;
305 next if $line =~ m/^\s*$/;
315 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
316 $res->{headline
} = $1;
317 chomp $res->{headline
};
320 $res->{description
} = $long;
321 chomp $res->{description
};
322 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
323 my ($key, $value) = (lc ($1), $2);
324 if ($key eq 'source' || $key eq 'mirror') {
325 push @{$res->{$key}}, $value;
327 die "duplicate key '$key'\n" if defined ($res->{$key});
328 $res->{$key} = $value;
331 die "unable to parse config file: $rec";
335 die "unable to parse config file" if $rec;
341 my ($self, $cmd, $input, $getoutput) = @_;
343 my $reader = IO
::File-
>new();
344 my $writer = IO
::File-
>new();
345 my $error = IO
::File-
>new();
349 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
353 if (ref ($cmd) eq 'ARRAY') {
354 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
356 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
363 if ($orig_pid != $$) {
364 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
371 print $writer $input if defined $input;
374 my $select = IO
::Select-
>new();
375 $select->add ($reader);
376 $select->add ($error);
379 my $logfd = $self->{logfd
};
381 while ($select->count) {
382 my @handles = $select->can_read ();
384 foreach my $h (@handles) {
386 my $count = sysread ($h, $buf, 4096);
387 if (!defined ($count)) {
389 die "command '$cmdstr' failed: $!";
391 $select->remove ($h) if !$count;
395 $res .= $buf if $getoutput;
402 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
410 $self->writelog (@_);
415 my $fd = $self->{logfd
};
419 sub __sample_config
{
423 my $arch = $self->{config
}->{architecture
};
425 my $ostype = $self->{config
}->{ostype
};
427 if ($ostype =~ m/^de(bi|vu)an-/) {
428 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
429 } elsif ($ostype =~ m/^ubuntu-/) {
430 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
432 die "unknown os type '$ostype'\n";
434 $data .= "lxc.uts.name = localhost\n";
435 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
444 if (my $fd = IO
::File-
>new (".veid")) {
451 $self->{working_dir
} = getcwd
;
452 $self->{veconffile
} = "$self->{working_dir}/config";
453 $self->{rootfs
} = "$self->{working_dir}/rootfs";
456 $self->{veid
} = $cid;
462 UUID
::generate
($uuid);
463 UUID
::unparse
($uuid, $uuid_str);
464 $self->{veid
} = $uuid_str;
466 my $fd = IO
::File-
>new (">.veid") ||
467 die "unable to write '.veid'\n";
468 print $fd "$self->{veid}\n";
471 my $cdata = $self->__sample_config();
473 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
474 die "unable to write lxc config file '$self->{veconffile}' - $!";
478 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
480 $self->logmsg ("allocated VE $self->{veid}\n");
482 return $self->{veid
};
485 # just use some simple heuristic for now, merge usr for releases newer than ubuntu 21.x or debian 11
489 my $ostype = $self->{config
}->{ostype
};
491 # FIXME: add configuration override posibillity
493 if ($ostype =~ m/^debian-(\d+)/) {
494 return int($1) >= 11;
495 } elsif ($ostype =~ m/^ubuntu-(\d+)/) {
496 return int($1) >= 21;
501 sub setup_usr_merge
{
504 my $rootfs = $self->{rootfs
};
505 my $arch = $self->{config
}->{architecture
};
507 # similar to https://salsa.debian.org/installer-team/debootstrap/-/blob/master/functions#L1354
508 my @merged_dirs = qw(bin sbin lib);
510 if ($arch eq 'amd64') {
511 push @merged_dirs, qw(lib32 lib64 libx32);
512 } elsif ($arch eq 'i386') {
513 push @merged_dirs, qw(lib64 libx32);
516 $self->logmsg ("setup usr-merge symlinks for '" . join("', '", @merged_dirs) . "'\n");
518 for my $dir (@merged_dirs) {
519 symlink("usr/$dir", "$rootfs/$dir") or warn "could not create symlink - $!\n";
520 mkpath
"$rootfs/usr/$dir";
525 my ($class, $config) = @_;
527 $class = ref ($class) || $class;
528 $config = read_config
('dab.conf') if !$config;
535 $self->{logfile
} = "logfile";
536 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") || die "unable to open log file";
538 my $arch = $config->{architecture
} ||die "no 'architecture' specified\n";
539 die "unsupported architecture '$arch'\n" if $arch !~ m/^(i386|amd64)$/;
541 my $suite = $config->{suite
} || die "no 'suite' specified\n";
543 my $suiteinfo = get_suite_info
($suite);
544 $suite = $suiteinfo->{suite
};
545 $config->{ostype
} = $suiteinfo->{ostype
};
547 my $name = $config->{name
} || die "no 'name' specified\n";
548 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || die "illegal characters in name '$name'\n";
550 # assert required dab.conf keys exist
551 for my $key (qw(version section headline maintainer)) {
552 die "no '$key' specified\n" if !$config->{$key};
554 my $version = $config->{version
};
556 if ($name =~ m/^$config->{ostype}/) {
557 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
559 $self->{targetname
} = "$config->{ostype}-${name}_${version}_$config->{architecture}";
562 if (!$config->{source
}) {
563 if (lc($suiteinfo->{origin
}) eq 'debian') {
564 if ($suite eq 'etch' || $suite eq 'lenny') {
565 push @{$config->{source
}}, (
566 'http://ftp.debian.org/debian SUITE main contrib',
567 'http://security.debian.org SUITE/updates main contrib',
569 } elsif ($suite eq 'bullseye' || $suite eq 'bookworm') {
570 push @{$config->{source
}}, (
571 "http://ftp.debian.org/debian SUITE main contrib",
572 "http://ftp.debian.org/debian SUITE-updates main contrib",
573 "http://security.debian.org SUITE-security main contrib",
576 push @{$config->{source
}}, (
577 "http://ftp.debian.org/debian SUITE main contrib",
578 "http://ftp.debian.org/debian SUITE-updates main contrib",
579 "http://security.debian.org SUITE/updates main contrib",
582 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
583 my $comp = "main restricted universe multiverse";
584 push @{$config->{source
}}, (
585 "http://archive.ubuntu.com/ubuntu SUITE $comp",
586 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
587 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
596 foreach my $s (@{$config->{source
}}) {
597 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
598 my ($url, $su, $components) = ($1, $3, $4);
599 $su =~ s/SUITE/$suite/;
600 $components =~ s/^\s+//;
601 $components =~ s/\s+$//;
603 foreach my $co (split (/\s+/, $components)) {
606 $ca = ['main'] if !$ca;
614 die "syntax error in source spezification '$s'\n";
618 foreach my $m (@{$config->{mirror
}}) {
619 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
620 my ($ms, $md) = ($1, $3);
622 foreach my $ss (@$sources) {
623 if ($ss->{source
} eq $ms) {
629 die "unusable mirror $ms\n" if !$found;
631 die "syntax error in mirror spezification '$m'\n";
634 $self->{sources
} = $sources;
635 $self->{infodir
} = "info";
637 $self->__allocate_ve();
639 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
641 my $incl = [qw
(less ssh openssh-server logrotate
)];
642 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe pppoeconf nfs-common mtools ntp
)];
644 # ubuntu has too many dependencies on udev, so we cannot exclude it (instead we disable udevd)
645 if (lc($suiteinfo->{origin
}) eq 'ubuntu' && $suiteinfo->{flags
}->{systemd
}) {
646 push @$incl, 'isc-dhcp-client';
647 push @$excl, qw(libmodule-build-perl libdrm-common libdrm2 libplymouth5 plymouth plymouth-theme-ubuntu-text powermgmt-base);
648 if ($suite eq 'jammy') {
649 push @$excl, qw(fuse); # avoid fuse2 <-> fuse3 conflict
651 } elsif ($suite eq 'trusty') {
652 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
653 } elsif ($suite eq 'precise') {
654 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
655 } elsif ($suite eq 'hardy') {
656 push @$excl, qw(kbd);
657 push @$excl, qw(apparmor apparmor-utils ntfs-3g friendly-recovery);
658 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
659 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl libntfs-3g28);
660 push @$excl, qw(ntfs-3g friendly-recovery);
661 } elsif ($suite eq 'jessie') {
662 push @$incl, 'sysvinit-core'; # avoid systemd and udev
663 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
664 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm memtest86+ parted);
665 } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye' || $suite eq 'bookworm') {
666 push @$excl, qw(module-init-tools pciutils hdparm memtest86+ parted);
668 push @$excl, qw(udev module-init-tools pciutils hdparm memtest86+ parted);
671 $self->{incl
} = $incl;
672 $self->{excl
} = $excl;
680 my $infodir = $self->{infodir
};
681 my $arch = $self->{config
}->{architecture
};
687 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
688 die "unable to open log file";
701 foreach my $ss (@{$self->{sources
}}) {
702 my $src = $ss->{mirror
} || $ss->{source
};
703 my $path = "dists/$ss->{suite}/Release";
704 my $url = "$src/$path";
705 my $target = __url_to_filename
("$ss->{source}/$path");
707 $self->download ($url, "$infodir/$target");
708 $self->download ("$url.gpg", "$infodir/$target.gpg");
709 # fixme: impl. verify (needs --keyring option)
713 warn "Release info ignored\n";
716 foreach my $comp (@{$ss->{comp
}}) {
717 foreach my $compressor (@$COMPRESSORS) {
718 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
719 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
720 my $pkgsrc = "$src/$path";
722 $self->download ($pkgsrc, $target);
723 $self->run_command ("$compressor->{decomp} '$target'");
726 print $logfd "could not download Packages.$compressor->{ext}\n";
736 my ($self, $filename, $size) = @_;
738 my $config = $self->{config
};
742 $data .= "Name: $config->{name}\n";
743 $data .= "Version: $config->{version}\n";
744 $data .= "Type: lxc\n";
745 $data .= "OS: $config->{ostype}\n";
746 $data .= "Section: $config->{section}\n";
747 $data .= "Maintainer: $config->{maintainer}\n";
748 $data .= "Architecture: $config->{architecture}\n";
749 $data .= "Installed-Size: $size\n";
752 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
753 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
754 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
757 $data .= "Description: $config->{headline}\n";
758 $data .= "$config->{description}\n" if $config->{description
};
760 write_file
($data, $filename, 0644);
764 my ($self, $opts) = @_;
766 my $suite = $self->{config
}->{suite
};
767 my $infodir = $self->{infodir
};
768 my $arch = $self->{config
}->{architecture
};
770 my $instpkgs = $self->read_installed ();
771 my $pkginfo = $self->pkginfo();
772 my $veid = $self->{veid
};
773 my $conffile = $self->{veconffile
};
774 my $rootdir = $self->{rootfs
};
776 my $vestat = $self->ve_status();
777 die "ve not running - unable to finalize\n" if !$vestat->{running
};
780 if (-f
"$rootdir/etc/init.d/mysql") {
781 $self->ve_command ("/etc/init.d/mysql stop");
784 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
785 unlink "$rootdir/root/.my.cnf";
788 if ($suite eq 'etch') {
789 # enable apache2 startup
790 if ($instpkgs->{apache2
}) {
791 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
793 unlink "$rootdir/etc/default/apache2";
796 $self->logmsg ("cleanup package status\n");
797 # prevent auto selection of all standard, required or important
798 # packages which are not installed
799 foreach my $pkg (keys %$pkginfo) {
800 my $pri = $pkginfo->{$pkg}->{priority
};
801 if ($pri && ($pri eq 'required' || $pri eq 'important'
802 || $pri eq 'standard')) {
803 if (!$instpkgs->{$pkg}) {
804 $self->ve_dpkg_set_selection ($pkg, 'purge');
809 $self->ve_command ("apt-get clean");
811 $self->logmsg ("update available package list\n");
813 $self->ve_command ("dpkg --clear-avail");
814 foreach my $ss (@{$self->{sources
}}) {
815 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
816 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
817 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
818 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
820 foreach my $comp (@{$ss->{comp
}}) {
821 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
822 "$comp/binary-$arch/Packages");
823 my $target = "/var/lib/apt/lists/$src";
824 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
825 $self->ve_command ("dpkg --merge-avail '$target'");
829 # set dselect default method
830 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
832 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
834 $self->ve_divert_remove ("/sbin/start-stop-daemon");
836 $self->ve_divert_remove ("/sbin/init");
838 # finally stop the VE
839 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
841 unlink "$rootdir/sbin/defenv";
842 unlink <$rootdir/root/dead.letter
*>;
843 unlink "$rootdir/var/log/init.log";
844 unlink "$rootdir/aquota.group", "$rootdir/aquota.user";
846 write_file
("", "$rootdir/var/log/syslog");
848 my $get_path_size = sub {
850 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
851 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
854 die "unable to detect size for '$path'\n";
858 $self->logmsg ("detecting final appliance size: ");
859 my $size = $get_path_size->($rootdir);
860 $self->logmsg ("$size MB\n");
862 $self->write_config ("$rootdir/etc/appliance.info", $size);
864 $self->logmsg ("creating final appliance archive\n");
866 my $target = "$self->{targetname}.tar";
868 my $compressor = $opts->{compressor
} // 'gz';
869 my $compressor2cmd_map = {
874 'zstd-max' => 'zstd -19 -T0', # maximal level where the decompressor can still run efficiently
876 my $compressor2ending = {
881 my $compressor_cmd = $compressor2cmd_map->{$compressor};
882 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
883 if !defined($compressor_cmd);
885 my $ending = $compressor2ending->{$compressor} // $compressor;
886 my $final_archive = "${target}.${ending}";
888 unlink $final_archive;
890 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
891 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
892 $self->run_command ("$compressor_cmd $target");
894 $self->logmsg ("detecting final commpressed appliance size: ");
895 $size = $get_path_size->($final_archive);
896 $self->logmsg ("$size MB\n");
898 $self->logmsg ("appliance archive: $final_archive\n");
904 my $rootdir = $self->{rootfs
};
906 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
908 open(my $PKGLST, '<', $pkgfilelist) or die "unable to open '$pkgfilelist' - $!";
912 while (my $rec = <$PKGLST>) {
918 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
922 my $pkg = $res->{'package'};
923 if (my $status = $res->{status
}) {
924 my @sa = split (/\s+/, $status);
926 if ($stat && ($stat ne 'purge')) {
927 $pkglist->{$pkg} = $res;
940 my $veid = $self->{veid
};
942 my $res = { running
=> 0 };
944 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
946 my $filename = "/proc/net/unix";
948 # similar test is used by lcxcontainers.c: list_active_containers
949 my $fh = IO
::File-
>new ($filename, "r");
952 while (defined(my $line = <$fh>)) {
953 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
955 if ($path =~ m!^@/\S+/$veid/command$!) {
966 my ($self, $cmd, $input) = @_;
968 my $veid = $self->{veid
};
969 my $conffile = $self->{veconffile
};
971 if (ref ($cmd) eq 'ARRAY') {
972 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
973 $self->run_command($cmd, $input);
975 $self->run_command("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
979 # like ve_command, but pipes stdin correctly
981 my ($self, @cmd) = @_;
983 my $veid = $self->{veid
};
984 my $conffile = $self->{veconffile
};
987 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
988 'defenv', @cmd) || die "unable to exec command";
990 while (defined (my $line = <$reader>)) {
991 $self->logmsg ($line);
997 die "ve_exec failed - status $rc\n" if $rc != 0;
1001 my ($self, $filename) = @_;
1003 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
1004 "--rename '$filename'");
1006 sub ve_divert_remove
{
1007 my ($self, $filename) = @_;
1009 my $rootdir = $self->{rootfs
};
1011 unlink "$rootdir/$filename";
1012 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
1015 sub ve_debconfig_set
{
1016 my ($self, $dcdata) = @_;
1018 my $rootdir = $self->{rootfs
};
1019 my $cfgfile = "/tmp/debconf.txt";
1020 write_file
($dcdata, "$rootdir/$cfgfile");
1021 $self->ve_command ("debconf-set-selections $cfgfile");
1022 unlink "$rootdir/$cfgfile";
1025 sub ve_dpkg_set_selection
{
1026 my ($self, $pkg, $status) = @_;
1028 $self->ve_command ("dpkg --set-selections", "$pkg $status");
1032 my ($self, $cmd, @pkglist) = @_;
1034 return if !scalar (@pkglist);
1036 my $pkginfo = $self->pkginfo();
1038 my $rootdir = $self->{rootfs
};
1039 my $cachedir = $self->{cachedir
};
1043 foreach my $pkg (@pkglist) {
1044 my $filename = $self->getpkgfile ($pkg);
1045 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
1046 push @files, "/$filename";
1047 $self->logmsg ("$cmd: $pkg\n");
1050 my $fl = join (' ', @files);
1052 if ($cmd eq 'install') {
1053 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
1054 } elsif ($cmd eq 'unpack') {
1055 $self->ve_command ("dpkg --force-depends --unpack $fl");
1057 die "internal error";
1060 foreach my $fn (@files) { unlink "$rootdir$fn"; }
1066 my $veid = $self->{veid
}; # fixme
1067 my $conffile = $self->{veconffile
};
1069 my $vestat = $self->ve_status();
1070 if ($vestat->{running
}) {
1071 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1074 rmtree
$self->{rootfs
};
1075 unlink $self->{veconffile
};
1081 my $veid = $self->{veid
};
1082 my $conffile = $self->{veconffile
};
1084 $self->logmsg ("initialize VE $veid\n");
1086 my $vestat = $self->ve_status();
1087 if ($vestat->{running
}) {
1088 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1091 rmtree
$self->{rootfs
};
1092 mkpath
$self->{rootfs
};
1095 sub __deb_version_cmp
{
1096 my ($cur, $op, $new) = @_;
1098 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
1105 sub __parse_packages
{
1106 my ($pkginfo, $filename, $src) = @_;
1109 open(my $PKGLST, '<', $filename) or die "unable to open '$filename' - $!";
1111 while (my $rec = <$PKGLST>) {
1112 $rec =~ s/\n\s+/ /g;
1118 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
1122 my $pkg = $res->{'package'};
1123 if ($pkg && $res->{'filename'}) {
1125 if (my $info = $pkginfo->{$pkg}) {
1126 $cur = $info->{version
};
1128 my $new = $res->{version
};
1129 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1131 $res->{url
} = "$src/$res->{'filename'}";
1133 die "no url for package '$pkg'" if !$res->{url
};
1135 $pkginfo->{$pkg} = $res;
1146 return $self->{pkginfo
} if $self->{pkginfo
};
1148 my $infodir = $self->{infodir
};
1149 my $arch = $self->{config
}->{architecture
};
1151 my $availfn = "$infodir/available";
1156 # reading 'available' is faster, because it only contains latest version
1157 # (no need to do slow version compares)
1159 __parse_packages
($pkginfo, $availfn);
1160 $self->{pkginfo
} = $pkginfo;
1164 $self->logmsg ("generating available package list\n");
1166 foreach my $ss (@{$self->{sources
}}) {
1167 foreach my $comp (@{$ss->{comp
}}) {
1168 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1169 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1171 my $src = $ss->{mirror
} || $ss->{source
};
1173 __parse_packages
($pkginfo, $pkgfilelist, $src);
1177 if (my $dep = $self->{config
}->{depends
}) {
1178 foreach my $d (split (/,/, $dep)) {
1179 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1180 my ($pkg, $op, $rver) = ($1, $3, $4);
1181 $self->logmsg ("checking dependencies: $d\n");
1182 my $info = $pkginfo->{$pkg};
1183 die "package '$pkg' not available\n" if !$info;
1185 my $cver = $info->{version
};
1186 if (!__deb_version_cmp
($cver, $op, $rver)) {
1187 die "detected wrong version '$cver'\n";
1191 die "syntax error in depends field";
1196 $self->{pkginfo
} = $pkginfo;
1198 my $tmpfn = "$availfn.tmp$$";
1199 my $fd = IO
::File-
>new (">$tmpfn");
1200 foreach my $pkg (sort keys %$pkginfo) {
1201 my $info = $pkginfo->{$pkg};
1202 print $fd "package: $pkg\n";
1203 foreach my $k (sort keys %$info) {
1204 next if $k eq 'description';
1205 next if $k eq 'package';
1206 my $v = $info->{$k};
1207 print $fd "$k: $v\n" if $v;
1209 print $fd "description: $info->{description}\n" if $info->{description
};
1214 rename ($tmpfn, $availfn);
1219 sub __record_provides
{
1220 my ($pkginfo, $closure, $list, $skipself) = @_;
1222 foreach my $pname (@$list) {
1223 my $info = $pkginfo->{$pname};
1224 # fixme: if someone install packages directly using dpkg, there
1225 # is no entry in 'available', only in 'status'. In that case, we
1226 # should extract info from $instpkgs
1228 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1231 if (my $prov = $info->{provides
}) {
1232 my @pl = split (',', $prov);
1233 foreach my $p (@pl) {
1235 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1240 $closure->{$pname} = 1 if !$skipself;
1245 my ($self, $closure, $list) = @_;
1247 my $pkginfo = $self->pkginfo();
1249 # first, record provided packages
1250 __record_provides
($pkginfo, $closure, $list, 1);
1255 # then resolve dependencies
1256 foreach my $pname (@$list) {
1257 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1263 sub __closure_single
{
1264 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1268 $pname =~ s/:any$//;
1270 return if $closure->{$pname};
1272 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1274 my $dep = $info->{depends
};
1275 my $predep = $info->{'pre-depends'};
1277 my $size = $info->{size
};
1278 my $url = $info->{url
};
1280 $url || die "$pname: no url for package '$pname'";
1282 if (!$pkghash->{$pname}) {
1283 unshift @$pkglist, $pname;
1284 $pkghash->{$pname} = 1;
1287 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1289 $closure->{$pname} = 1;
1295 push @l, split (/,/, $predep) if $predep;
1296 push @l, split (/,/, $dep) if $dep;
1298 DEPEND
: foreach my $p (@l) {
1299 my @l1 = split (/\|/, $p);
1300 foreach my $p1 (@l1) {
1301 if ($p1 =~ m/^\s*(\S+).*/) {
1302 #printf (STDERR "$pname: $p --> $1\n");
1303 if ($closure->{$1}) {
1304 next DEPEND
; # dependency already met
1308 # search for non-excluded alternative
1310 foreach my $p1 (@l1) {
1311 if ($p1 =~ m/^\s*(\S+).*/) {
1312 next if grep { $1 eq $_ } @$excl;
1317 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1319 #printf (STDERR "$pname: $p --> $found\n");
1321 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1325 sub cache_packages
{
1326 my ($self, $pkglist) = @_;
1328 foreach my $pkg (@$pkglist) {
1329 $self->getpkgfile ($pkg);
1334 my ($self, $pkg) = @_;
1336 my $pkginfo = $self->pkginfo();
1337 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1338 my $cachedir = $self->{cachedir
};
1340 my $url = $info->{url
};
1343 if ($url =~ m
|/([^/]+.deb
)$|) {
1346 die "internal error";
1349 return $filename if -f
"$cachedir/$filename";
1353 $self->download ($url, "$cachedir/$filename");
1358 sub install_init_script
{
1359 my ($self, $script, $runlevel, $prio) = @_;
1361 my $suite = $self->{config
}->{suite
};
1362 my $suiteinfo = get_suite_info
($suite);
1363 my $rootdir = $self->{rootfs
};
1365 my $base = basename
($script);
1366 my $target = "$rootdir/etc/init.d/$base";
1368 $self->run_command ("install -m 0755 '$script' '$target'");
1369 if ($suite eq 'etch' || $suite eq 'lenny') {
1370 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1371 } elsif ($suiteinfo->{flags
}->{systemd
}) {
1372 die "unable to install init script (system uses systemd)\n";
1373 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1374 die "unable to install init script (system uses upstart)\n";
1376 $self->ve_command ("insserv $base");
1383 my ($self, $opts) = @_;
1385 my $pkginfo = $self->pkginfo();
1386 my $veid = $self->{veid
};
1387 my $suite = $self->{config
}->{suite
};
1388 my $suiteinfo = get_suite_info
($suite);
1390 my $important = [ @{$self->{incl
}} ];
1394 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1395 if ($mta eq 'postfix') {
1396 push @$important, "postfix";
1399 if ($opts->{include
}) {
1400 push @$important, split(',', $opts->{include
});
1404 if ($opts->{exclude
}) {
1405 $exclude->{$_} = 1 for split(',', $opts->{exclude
});
1408 foreach my $p (sort keys %$pkginfo) {
1409 next if grep { $p eq $_ } @{$self->{excl
}};
1410 my $pri = $pkginfo->{$p}->{priority
};
1412 next if $mta ne 'exim' && $p =~ m/exim/;
1413 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1415 push @$required, $p if $pri eq 'required';
1416 next if $exclude->{$p};
1417 push @$important, $p if $pri eq 'important';
1418 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1422 $required = $self->closure($closure, $required);
1423 $important = $self->closure($closure, $important);
1425 if (!$opts->{minimal
}) {
1426 $standard = $self->closure($closure, $standard);
1429 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1430 # except those explicitly excluded
1431 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1432 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1433 foreach my $d (split (/,/, $mdeps)) {
1434 if ($d =~ m/^\s*(\S+)$/) {
1436 next if $closure->{$pkg};
1437 next if grep { $pkg eq $_ } @{$self->{excl
}};
1438 die "missing ubuntu-minimal package '$pkg'\n";
1441 if (!$opts->{minimal
}) {
1442 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1443 foreach my $d (split (/,/, $mdeps)) {
1444 if ($d =~ m/^\s*(\S+)$/) {
1446 next if $closure->{$pkg};
1447 next if grep { $pkg eq $_ } @{$self->{excl
}};
1448 die "missing ubuntu-standard package '$pkg'\n";
1454 # download/cache all files first
1455 $self->cache_packages ($required);
1456 $self->cache_packages ($important);
1457 $self->cache_packages ($standard);
1459 my $rootdir = $self->{rootfs
};
1461 # extract required packages first
1462 $self->logmsg ("create basic environment\n");
1464 if ($self->can_usr_merge()) {
1465 $self->setup_usr_merge();
1468 my $compressor2opt = {
1473 my $compressor_re = join('|', keys $compressor2opt->%*);
1475 $self->logmsg ("extract required packages to rootfs\n");
1476 foreach my $p (@$required) {
1477 my $filename = $self->getpkgfile ($p);
1478 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1479 if ($content =~ m/^(data.tar.($compressor_re))$/m) {
1481 my $tar_opts = "--keep-directory-symlink $compressor2opt->{$2}";
1483 $self->run_command("ar -p '$self->{cachedir}/$filename' '$archive' | tar -C '$rootdir' -xf - $tar_opts");
1485 die "unexpected error for $p: no data.tar.{xz,gz,zst} found...";
1490 my $data = "Package: dpkg\n" .
1491 "Version: $pkginfo->{dpkg}->{version}\n" .
1492 "Status: install ok installed\n";
1494 write_file
($data, "$rootdir/var/lib/dpkg/status");
1495 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1496 write_file
("", "$rootdir/var/lib/dpkg/available");
1499 foreach my $ss (@{$self->{sources
}}) {
1500 my $url = $ss->{source
};
1501 my $comp = join (' ', @{$ss->{comp
}});
1502 $data .= "deb $url $ss->{suite} $comp\n\n";
1505 write_file
($data, "$rootdir/etc/apt/sources.list");
1507 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1508 write_file
($data, "$rootdir/etc/fstab", 0644);
1510 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1512 # avoid warnings about non-existent resolv.conf
1513 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1515 if (lc($suiteinfo->{origin
}) eq 'ubuntu' && $suiteinfo->{flags
}->{systemd
}) {
1516 # no need to configure loopback device
1517 # FIXME: Debian (systemd based?) too?
1519 $data = "auto lo\niface lo inet loopback\n";
1520 mkdir "$rootdir/etc/network";
1521 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1525 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1527 # avoid warnings about missing default locale
1528 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1531 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1532 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1534 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1536 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1538 $self->logmsg ("initialize ld cache\n");
1539 $self->ve_command ("/sbin/ldconfig");
1540 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1542 $self->logmsg ("installing packages\n");
1544 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1546 $self->ve_dpkg ('install', 'dpkg');
1548 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1550 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1552 $self->ve_dpkg ('install', 'libc6');
1553 $self->ve_dpkg ('install', 'perl-base');
1555 unlink "$rootdir/usr/bin/awk";
1557 $self->ve_dpkg ('install', 'mawk');
1558 $self->ve_dpkg ('install', 'debconf');
1560 # unpack required packages
1561 foreach my $p (@$required) {
1562 $self->ve_dpkg ('unpack', $p);
1565 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1566 $self->ve_divert_add ("/sbin/init");
1567 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1569 # disable service activation
1570 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1571 $data = "#!/bin/sh\nexit 101\n";
1572 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1574 # disable start-stop-daemon
1575 $self->ve_divert_add ("/sbin/start-stop-daemon");
1579 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1581 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1584 $self->ve_divert_add ("/sbin/udevd");
1586 if ($suite eq 'etch') {
1587 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2"); # disable apache2 startup
1590 $self->logmsg ("configure required packages\n");
1591 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1593 # set postfix defaults
1594 if ($mta eq 'postfix') {
1595 $data = "postfix postfix/main_mailer_type select Local only\n";
1596 $self->ve_debconfig_set ($data);
1598 $data = "postmaster: root\nwebmaster: root\n";
1599 write_file
($data, "$rootdir/etc/aliases");
1602 if ($suite eq 'jaunty') {
1603 # jaunty does not create /var/run/network, so network startup fails.
1604 # so we do not use tmpfs for /var/run and /var/lock
1605 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1606 # and create the directory here
1607 $self->run_command ("mkdir $rootdir/var/run/network");
1610 # unpack base packages
1611 foreach my $p (@$important) {
1612 $self->ve_dpkg ('unpack', $p);
1616 if (-x
"$rootdir/sbin/ifconfig") {
1617 $self->ve_command ("ifconfig lo up");
1619 $self->ve_command ("ip link set lo up");
1622 $self->logmsg ("configure important packages\n");
1623 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1625 if (-d
"$rootdir/etc/event.d") {
1626 unlink <$rootdir/etc/event.d
/tty
*>;
1629 if (-f
"$rootdir/etc/inittab") {
1630 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1633 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1634 unlink "$rootdir/etc/mtab";
1635 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1638 $self->ve_command ("usermod -L root");
1640 if ($mta eq 'postfix') {
1641 $data = "postfix postfix/main_mailer_type select No configuration\n";
1642 $self->ve_debconfig_set ($data);
1644 unlink "$rootdir/etc/mailname";
1645 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1648 if (!$opts->{minimal
}) {
1649 # unpack standard packages
1650 foreach my $p (@$standard) {
1651 $self->ve_dpkg ('unpack', $p);
1654 $self->logmsg ("configure standard packages\n");
1655 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1658 # disable HWCLOCK access
1659 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1662 $self->ve_divert_add ("/usr/sbin/hald");
1664 # disable /dev/urandom init
1665 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1667 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1669 $self->ve_divert_add ("/sbin/klogd");
1672 # remove unnecessays sysctl entries to avoid warnings
1674 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1675 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1676 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1677 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1678 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1679 $self->run_command ($cmd);
1681 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1682 if (-f
$bindv6only) {
1684 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1685 $cmd .= " -i '$bindv6only'";
1686 $self->run_command ($cmd);
1689 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1690 # disable tty init (console-setup)
1692 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1693 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1694 $self->run_command ($cmd);
1697 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1698 # remove sysctl setup (avoid warnings at startup)
1699 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1700 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1701 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1702 $self->run_command ("rm $filelist");
1705 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1706 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1713 my $veid = $self->{veid
};
1714 my $conffile = $self->{veconffile
};
1716 my $vestat = $self->ve_status();
1718 if (!$vestat->{exist
}) {
1719 $self->logmsg ("Please create the appliance first (bootstrap)");
1723 if (!$vestat->{running
}) {
1724 $self->run_command ("lxc-start -n $veid -f $conffile");
1727 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1730 sub ve_mysql_command
{
1731 my ($self, $sql, $password) = @_;
1733 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1734 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1736 $self->ve_command ("mysql", $sql);
1739 sub ve_mysql_bootstrap
{
1740 my ($self, $sql, $password) = @_;
1744 my $suite = $self->{config
}->{suite
};
1746 if ($suite eq 'jessie') {
1747 my $rootdir = $self->{rootfs
};
1748 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1751 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1752 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1755 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1756 "--skip-bdb --skip-innodb --skip-ndbcluster";
1759 $self->ve_command ($cmd, $sql);
1762 sub compute_required
{
1763 my ($self, $pkglist) = @_;
1765 my $pkginfo = $self->pkginfo();
1766 my $instpkgs = $self->read_installed ();
1769 __record_provides
($pkginfo, $closure, [keys $instpkgs->%*]);
1771 return $self->closure ($closure, $pkglist);
1775 my ($self, $opts) = @_;
1777 my @supp = ('7.4', '8.1');
1778 my $pgversion; # NOTE: not setting that defaults to the distro default, normally the best choice
1780 my $suite = $self->{config
}->{suite
};
1782 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1785 } elsif ($suite eq 'squeeze') {
1788 } elsif ($suite eq 'wheezy') {
1791 } elsif ($suite eq 'jessie') {
1794 } elsif ($suite eq 'stretch') {
1797 } elsif ($suite eq 'buster') {
1800 } elsif ($suite eq 'bullseye') {
1802 } elsif ($suite eq 'bookworm') {
1803 # FIXME: update once froozen
1804 @supp = ('13', '14');
1806 $pgversion = $opts->{version
} if $opts->{version
};
1809 if (defined($pgversion)) {
1810 die "unsupported postgres version '$pgversion'\n" if !grep { $pgversion eq $_; } @supp;
1812 $required = $self->compute_required (["postgresql-$pgversion"]);
1814 $required = $self->compute_required (["postgresql"]);
1817 $self->cache_packages ($required);
1819 $self->ve_dpkg ('install', @$required);
1821 my $iscript = "postgresql-$pgversion";
1822 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1823 $suite eq 'stretch') {
1824 $iscript = 'postgresql';
1827 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1831 my ($self, $opts) = @_;
1833 my $password = $opts->{password
};
1834 my $rootdir = $self->{rootfs
};
1836 my $suite = $self->{config
}->{suite
};
1839 if ($suite eq 'squeeze') {
1841 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1844 die "task_mysql: unsupported suite '$suite'";
1847 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1849 $self->cache_packages ($required);
1851 $self->ve_dpkg ('install', @$required);
1853 # fix security (see /usr/bin/mysql_secure_installation)
1854 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1855 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1856 "FLUSH PRIVILEGES;\n";
1857 $self->ve_mysql_bootstrap ($sql);
1861 my $rpw = $password eq 'random' ?
'admin' : $password;
1863 my $sql = "USE mysql;\n" .
1864 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1865 "FLUSH PRIVILEGES
;\n";
1866 $self->ve_mysql_bootstrap ($sql);
1868 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1869 if ($password eq 'random') {
1870 $self->install_init_script ($script_mysql_randompw, 2, 20);
1874 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1878 my ($self, $opts) = @_;
1880 my $memlimit = $opts->{memlimit
};
1881 my $rootdir = $self->{rootfs
};
1882 my $suite = $self->{config
}->{suite
};
1884 my $base_set = [qw(php-cli libapache2-mod-php php-gd)];
1885 if ($suite =~ /(?:squeeze|wheezy|jessie)$/) {
1886 $self->logmsg("WARN: using EOL php release on EOL suite");
1887 $base_set = [qw(php5 php5-cli libapache2-mod-php5 php5-gd)];
1889 my $required = $self->compute_required($base_set);
1891 $self->cache_packages ($required);
1893 $self->ve_dpkg ('install', @$required);
1896 my $sed_cmd = ['sed', '-e', "s/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/", '-i'];
1897 if ($suite =~ /(?:squeeze|wheezy|jessie)$/) {
1898 push @$sed_cmd, "$rootdir/etc/php5/apache2/php.ini";
1901 for my $fn (glob("'${rootdir}/etc/php/*/apache2/php.ini'")) {
1902 push @$sed_cmd, "$rootdir/$fn";
1906 warn "WARN: did not found any php.ini to set the memlimit!\n";
1910 $self->run_command($sed_cmd);
1915 my ($self, $pkglist, $unpack) = @_;
1917 my $required = $self->compute_required ($pkglist);
1919 $self->cache_packages ($required);
1921 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1925 my ($self, $distclean) = @_;
1927 unlink $self->{logfile
};
1928 unlink "$self->{targetname}.tar";
1929 unlink "$self->{targetname}.tar.gz";
1931 $self->ve_destroy ();
1934 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1936 rmtree
$self->{infodir
};