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
{
62 my $supported_suites = {
64 ostype
=> "debian-12",
67 ostype
=> "debian-11",
70 ostype
=> "debian-10",
73 ostype
=> "debian-9.0",
76 ostype
=> "debian-8.0",
79 ostype
=> "debian-7.0",
82 ostype
=> "debian-6.0",
85 ostype
=> "debian-5.0",
88 ostype
=> "debian-4.0",
94 ostype
=> "devuan-1.0",
98 ostype
=> "devuan-2.0",
101 ostype
=> "devuan-2.0",
104 ostype
=> "devuan-3.0",
107 ostype
=> "devuan-4.0",
112 ostype
=> "ubuntu-8.04",
116 ostype
=> "ubuntu-8.10",
120 ostype
=> "ubuntu-9.04",
124 ostype
=> "ubuntu-12.04",
128 ostype
=> "ubuntu-14.04",
132 ostype
=> "ubuntu-15.04",
136 ostype
=> "ubuntu-15.10",
140 ostype
=> "ubuntu-16.04",
144 ostype
=> "ubuntu-16.10",
148 ostype
=> "ubuntu-17.04",
152 ostype
=> "ubuntu-17.10",
156 ostype
=> "ubuntu-18.04",
160 ostype
=> "ubuntu-18.10",
164 ostype
=> "ubuntu-19.04",
168 ostype
=> "ubuntu-19.10",
172 ostype
=> "ubuntu-20.04",
176 ostype
=> "ubuntu-20.10",
180 ostype
=> "ubuntu-21.04",
184 ostype
=> "ubuntu-21.10",
192 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
195 $suiteinfo->{origin
} //= 'debian';
196 $suiteinfo->{suite
} //= $suite;
202 my ($self, $url, $path) = @_;
204 $self->logmsg ("download: $url\n");
205 my $tmpfn = "$path.tmp$$";
207 $self->run_command ("wget -q '$url' -O '$tmpfn'");
216 rename ($tmpfn, $path);
220 my ($data, $file, $perm) = @_;
222 die "no filename" if !$file;
226 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
227 die "unable to open file '$file'";
237 die "no filename" if !$file;
239 my $fh = IO
::File-
>new ($file) ||
240 die "unable to open file '$file'";
242 local $/; # slurp mode
256 my $fh = IO
::File-
>new ("<$filename") || return $res;
259 while (defined (my $line = <$fh>)) {
260 next if $line =~ m/^\#/;
261 next if $line =~ m/^\s*$/;
271 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
272 $res->{headline
} = $1;
273 chomp $res->{headline
};
276 $res->{description
} = $long;
277 chomp $res->{description
};
278 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
279 my ($key, $value) = (lc ($1), $2);
280 if ($key eq 'source' || $key eq 'mirror') {
281 push @{$res->{$key}}, $value;
283 die "duplicate key '$key'\n" if defined ($res->{$key});
284 $res->{$key} = $value;
287 die "unable to parse config file: $rec";
291 die "unable to parse config file" if $rec;
297 my ($self, $cmd, $input, $getoutput) = @_;
299 my $reader = IO
::File-
>new();
300 my $writer = IO
::File-
>new();
301 my $error = IO
::File-
>new();
305 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
309 if (ref ($cmd) eq 'ARRAY') {
310 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
312 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
319 if ($orig_pid != $$) {
320 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
327 print $writer $input if defined $input;
330 my $select = new IO
::Select
;
331 $select->add ($reader);
332 $select->add ($error);
335 my $logfd = $self->{logfd
};
337 while ($select->count) {
338 my @handles = $select->can_read ();
340 foreach my $h (@handles) {
342 my $count = sysread ($h, $buf, 4096);
343 if (!defined ($count)) {
345 die "command '$cmdstr' failed: $!";
347 $select->remove ($h) if !$count;
351 $res .= $buf if $getoutput;
358 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
366 $self->writelog (@_);
371 my $fd = $self->{logfd
};
375 sub __sample_config
{
379 my $arch = $self->{config
}->{architecture
};
381 my $ostype = $self->{config
}->{ostype
};
383 if ($ostype =~ m/^de(bi|vu)an-/) {
384 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
385 } elsif ($ostype =~ m/^ubuntu-/) {
386 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
388 die "unknown os type '$ostype'\n";
390 $data .= "lxc.uts.name = localhost\n";
391 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
400 if (my $fd = IO
::File-
>new (".veid")) {
407 $self->{working_dir
} = getcwd
;
408 $self->{veconffile
} = "$self->{working_dir}/config";
409 $self->{rootfs
} = "$self->{working_dir}/rootfs";
412 $self->{veid
} = $cid;
418 UUID
::generate
($uuid);
419 UUID
::unparse
($uuid, $uuid_str);
420 $self->{veid
} = $uuid_str;
422 my $fd = IO
::File-
>new (">.veid") ||
423 die "unable to write '.veid'\n";
424 print $fd "$self->{veid}\n";
427 my $cdata = $self->__sample_config();
429 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
430 die "unable to write lxc config file '$self->{veconffile}' - $!";
434 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
436 $self->logmsg ("allocated VE $self->{veid}\n");
438 return $self->{veid
};
441 # just use some simple heuristic for now, merge usr for releases newer than ubuntu 21.x or debian 11
445 my $ostype = $self->{config
}->{ostype
};
447 # FIXME: add configuration override posibillity
449 if ($ostype =~ m/^debian-(\d+)/) {
450 return int($1) >= 11;
451 } elsif ($ostype =~ m/^ubuntu-(\d+)/) {
452 return int($1) >= 21;
457 sub setup_usr_merge
{
460 my $rootfs = $self->{rootfs
};
461 my $arch = $self->{config
}->{architecture
};
463 # similar to https://salsa.debian.org/installer-team/debootstrap/-/blob/master/functions#L1354
464 my @merged_dirs = qw(bin sbin lib);
466 if ($arch eq 'amd64') {
467 push @merged_dirs, qw(lib32 lib64 libx32);
468 } elsif ($arch eq 'i386') {
469 push @merged_dirs, qw(lib64 libx32);
472 $self->logmsg ("setup usr-merge symlinks for '" . join("', '", @merged_dirs) . "'\n");
474 for my $dir (@merged_dirs) {
475 symlink("usr/$dir", "$rootfs/$dir") or warn "could not create symlink - $!\n";
476 mkpath
"$rootfs/usr/$dir";
481 my ($class, $config) = @_;
483 $class = ref ($class) || $class;
487 $config = read_config
('dab.conf') if !$config;
489 $self->{config
} = $config;
493 $self->{logfile
} = "logfile";
494 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
495 die "unable to open log file";
497 my $arch = $config->{architecture
};
498 die "no 'architecture' specified\n" if !$arch;
500 die "unsupported architecture '$arch'\n"
501 if $arch !~ m/^(i386|amd64)$/;
503 my $suite = $config->{suite
} || die "no 'suite' specified\n";
505 my $suiteinfo = get_suite_info
($suite);
506 $suite = $suiteinfo->{suite
};
507 $config->{ostype
} = $suiteinfo->{ostype
};
509 my $name = $config->{name
} || die "no 'name' specified\n";
511 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
512 die "illegal characters in name '$name'\n";
514 my $version = $config->{version
};
515 die "no 'version' specified\n" if !$version;
516 die "no 'section' specified\n" if !$config->{section
};
517 die "no 'description' specified\n" if !$config->{headline
};
518 die "no 'maintainer' specified\n" if !$config->{maintainer
};
520 if ($name =~ m/^$config->{ostype}/) {
521 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
523 $self->{targetname
} = "$config->{ostype}-${name}_" .
524 "${version}_$config->{architecture}";
527 if (!$config->{source
}) {
528 if (lc($suiteinfo->{origin
}) eq 'debian') {
529 if ($suite eq 'etch' || $suite eq 'lenny') {
530 push @{$config->{source
}}, (
531 'http://ftp.debian.org/debian SUITE main contrib',
532 'http://security.debian.org SUITE/updates main contrib',
534 } elsif ($suite eq 'bullseye' || $suite eq 'bookworm') {
535 push @{$config->{source
}}, (
536 "http://ftp.debian.org/debian SUITE main contrib",
537 "http://ftp.debian.org/debian SUITE-updates main contrib",
538 "http://security.debian.org SUITE-security main contrib",
541 push @{$config->{source
}}, (
542 "http://ftp.debian.org/debian SUITE main contrib",
543 "http://ftp.debian.org/debian SUITE-updates main contrib",
544 "http://security.debian.org SUITE/updates main contrib",
547 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
548 my $comp = "main restricted universe multiverse";
549 push @{$config->{source
}}, (
550 "http://archive.ubuntu.com/ubuntu SUITE $comp",
551 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
552 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
561 foreach my $s (@{$config->{source
}}) {
562 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
563 my ($url, $su, $components) = ($1, $3, $4);
564 $su =~ s/SUITE/$suite/;
565 $components =~ s/^\s+//;
566 $components =~ s/\s+$//;
568 foreach my $co (split (/\s+/, $components)) {
571 $ca = ['main'] if !$ca;
579 die "syntax error in source spezification '$s'\n";
583 foreach my $m (@{$config->{mirror
}}) {
584 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
585 my ($ms, $md) = ($1, $3);
587 foreach my $ss (@$sources) {
588 if ($ss->{source
} eq $ms) {
594 die "unusable mirror $ms\n" if !$found;
596 die "syntax error in mirror spezification '$m'\n";
600 $self->{sources
} = $sources;
602 $self->{infodir
} = "info";
604 $self->__allocate_ve ();
606 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
608 my $incl = [qw
(less ssh openssh-server logrotate
)];
610 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
611 pppoeconf nfs-common mtools ntp
)];
613 # ubuntu has too many dependencies on udev, so
614 # we cannot exclude it (instead we disable udevd)
616 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
617 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
618 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
619 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
620 || $suite eq 'hirsute' || $suite eq 'impish'
622 push @$incl, 'isc-dhcp-client';
623 push @$excl, qw(libmodule-build-perl);
624 } elsif ($suite eq 'trusty') {
625 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
626 } elsif ($suite eq 'precise') {
627 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
628 } elsif ($suite eq 'hardy') {
629 push @$excl, qw(kbd);
630 push @$excl, qw(apparmor apparmor-utils ntfs-3g
632 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
633 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
634 libntfs-3g28 ntfs-3g friendly-recovery);
635 } elsif ($suite eq 'jessie') {
636 push @$incl, 'sysvinit-core'; # avoid systemd and udev
637 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
638 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm memtest86+ parted);
639 } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye' || $suite eq 'bookworm') {
640 push @$excl, qw(module-init-tools pciutils hdparm memtest86+ parted);
642 push @$excl, qw(udev module-init-tools pciutils hdparm memtest86+ parted);
645 $self->{incl
} = $incl;
646 $self->{excl
} = $excl;
654 my $infodir = $self->{infodir
};
655 my $arch = $self->{config
}->{architecture
};
661 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
662 die "unable to open log file";
675 foreach my $ss (@{$self->{sources
}}) {
676 my $src = $ss->{mirror
} || $ss->{source
};
677 my $path = "dists/$ss->{suite}/Release";
678 my $url = "$src/$path";
679 my $target = __url_to_filename
("$ss->{source}/$path");
681 $self->download ($url, "$infodir/$target");
682 $self->download ("$url.gpg", "$infodir/$target.gpg");
683 # fixme: impl. verify (needs --keyring option)
687 warn "Release info ignored\n";
690 foreach my $comp (@{$ss->{comp
}}) {
691 foreach my $compressor (@$COMPRESSORS) {
692 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
693 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
694 my $pkgsrc = "$src/$path";
696 $self->download ($pkgsrc, $target);
697 $self->run_command ("$compressor->{decomp} '$target'");
700 print $logfd "could not download Packages.$compressor->{ext}\n";
710 my ($self, $filename, $size) = @_;
712 my $config = $self->{config
};
716 $data .= "Name: $config->{name}\n";
717 $data .= "Version: $config->{version}\n";
718 $data .= "Type: lxc\n";
719 $data .= "OS: $config->{ostype}\n";
720 $data .= "Section: $config->{section}\n";
721 $data .= "Maintainer: $config->{maintainer}\n";
722 $data .= "Architecture: $config->{architecture}\n";
723 $data .= "Installed-Size: $size\n";
726 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
727 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
728 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
731 $data .= "Description: $config->{headline}\n";
732 $data .= "$config->{description}\n" if $config->{description
};
734 write_file
($data, $filename, 0644);
738 my ($self, $opts) = @_;
740 my $suite = $self->{config
}->{suite
};
741 my $infodir = $self->{infodir
};
742 my $arch = $self->{config
}->{architecture
};
744 my $instpkgs = $self->read_installed ();
745 my $pkginfo = $self->pkginfo();
746 my $veid = $self->{veid
};
747 my $conffile = $self->{veconffile
};
748 my $rootdir = $self->{rootfs
};
750 my $vestat = $self->ve_status();
751 die "ve not running - unable to finalize\n" if !$vestat->{running
};
754 if (-f
"$rootdir/etc/init.d/mysql") {
755 $self->ve_command ("/etc/init.d/mysql stop");
758 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
759 unlink "$rootdir/root/.my.cnf";
762 if ($suite eq 'etch') {
763 # enable apache2 startup
764 if ($instpkgs->{apache2
}) {
765 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
767 unlink "$rootdir/etc/default/apache2";
770 $self->logmsg ("cleanup package status\n");
771 # prevent auto selection of all standard, required or important
772 # packages which are not installed
773 foreach my $pkg (keys %$pkginfo) {
774 my $pri = $pkginfo->{$pkg}->{priority
};
775 if ($pri && ($pri eq 'required' || $pri eq 'important'
776 || $pri eq 'standard')) {
777 if (!$instpkgs->{$pkg}) {
778 $self->ve_dpkg_set_selection ($pkg, 'purge');
783 $self->ve_command ("apt-get clean");
785 $self->logmsg ("update available package list\n");
787 $self->ve_command ("dpkg --clear-avail");
788 foreach my $ss (@{$self->{sources
}}) {
789 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
790 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
791 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
792 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
794 foreach my $comp (@{$ss->{comp
}}) {
795 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
796 "$comp/binary-$arch/Packages");
797 my $target = "/var/lib/apt/lists/$src";
798 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
799 $self->ve_command ("dpkg --merge-avail '$target'");
803 # set dselect default method
804 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
806 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
808 $self->ve_divert_remove ("/sbin/start-stop-daemon");
810 $self->ve_divert_remove ("/sbin/init");
812 # finally stop the VE
813 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
815 unlink "$rootdir/sbin/defenv";
817 unlink <$rootdir/root/dead.letter
*>;
819 unlink "$rootdir/var/log/init.log";
821 unlink "$rootdir/aquota.group";
823 unlink "$rootdir/aquota.user";
825 write_file
("", "$rootdir/var/log/syslog");
827 my $get_path_size = sub {
829 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
830 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
833 die "unable to detect size for '$path'\n";
837 $self->logmsg ("detecting final appliance size: ");
838 my $size = $get_path_size->($rootdir);
839 $self->logmsg ("$size MB\n");
841 $self->write_config ("$rootdir/etc/appliance.info", $size);
843 $self->logmsg ("creating final appliance archive\n");
845 my $target = "$self->{targetname}.tar";
847 my $compressor = $opts->{compressor
} // 'gz';
848 my $compressor2cmd_map = {
853 'zstd-max' => 'zstd -19 -T0', # maximal level where the decompressor can still run efficiently
855 my $compressor2ending = {
860 my $compressor_cmd = $compressor2cmd_map->{$compressor};
861 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
862 if !defined($compressor_cmd);
864 my $ending = $compressor2ending->{$compressor} // $compressor;
865 my $final_archive = "${target}.${ending}";
867 unlink $final_archive;
869 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
870 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
871 $self->run_command ("$compressor_cmd $target");
873 $self->logmsg ("detecting final commpressed appliance size: ");
874 $size = $get_path_size->($final_archive);
875 $self->logmsg ("$size MB\n");
877 $self->logmsg ("appliance archive: $final_archive\n");
883 my $rootdir = $self->{rootfs
};
885 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
887 open (PKGLST
, "<$pkgfilelist") or die "unable to open '$pkgfilelist' - $!";
891 while (my $rec = <PKGLST
>) {
897 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
901 my $pkg = $res->{'package'};
902 if (my $status = $res->{status
}) {
903 my @sa = split (/\s+/, $status);
905 if ($stat && ($stat ne 'purge')) {
906 $pkglist->{$pkg} = $res;
919 my $veid = $self->{veid
};
921 my $res = { running
=> 0 };
923 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
925 my $filename = "/proc/net/unix";
927 # similar test is used by lcxcontainers.c: list_active_containers
928 my $fh = IO
::File-
>new ($filename, "r");
931 while (defined(my $line = <$fh>)) {
932 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
934 if ($path =~ m!^@/\S+/$veid/command$!) {
945 my ($self, $cmd, $input) = @_;
947 my $veid = $self->{veid
};
948 my $conffile = $self->{veconffile
};
950 if (ref ($cmd) eq 'ARRAY') {
951 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
952 $self->run_command($cmd, $input);
954 $self->run_command("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
958 # like ve_command, but pipes stdin correctly
960 my ($self, @cmd) = @_;
962 my $veid = $self->{veid
};
963 my $conffile = $self->{veconffile
};
966 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
967 'defenv', @cmd) || die "unable to exec command";
969 while (defined (my $line = <$reader>)) {
970 $self->logmsg ($line);
976 die "ve_exec failed - status $rc\n" if $rc != 0;
980 my ($self, $filename) = @_;
982 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
983 "--rename '$filename'");
985 sub ve_divert_remove
{
986 my ($self, $filename) = @_;
988 my $rootdir = $self->{rootfs
};
990 unlink "$rootdir/$filename";
991 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
994 sub ve_debconfig_set
{
995 my ($self, $dcdata) = @_;
997 my $rootdir = $self->{rootfs
};
998 my $cfgfile = "/tmp/debconf.txt";
999 write_file
($dcdata, "$rootdir/$cfgfile");
1000 $self->ve_command ("debconf-set-selections $cfgfile");
1001 unlink "$rootdir/$cfgfile";
1004 sub ve_dpkg_set_selection
{
1005 my ($self, $pkg, $status) = @_;
1007 $self->ve_command ("dpkg --set-selections", "$pkg $status");
1011 my ($self, $cmd, @pkglist) = @_;
1013 return if !scalar (@pkglist);
1015 my $pkginfo = $self->pkginfo();
1017 my $rootdir = $self->{rootfs
};
1018 my $cachedir = $self->{cachedir
};
1022 foreach my $pkg (@pkglist) {
1023 my $filename = $self->getpkgfile ($pkg);
1024 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
1025 push @files, "/$filename";
1026 $self->logmsg ("$cmd: $pkg\n");
1029 my $fl = join (' ', @files);
1031 if ($cmd eq 'install') {
1032 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
1033 } elsif ($cmd eq 'unpack') {
1034 $self->ve_command ("dpkg --force-depends --unpack $fl");
1036 die "internal error";
1039 foreach my $fn (@files) { unlink "$rootdir$fn"; }
1045 my $veid = $self->{veid
}; # fixme
1046 my $conffile = $self->{veconffile
};
1048 my $vestat = $self->ve_status();
1049 if ($vestat->{running
}) {
1050 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1053 rmtree
$self->{rootfs
};
1054 unlink $self->{veconffile
};
1060 my $veid = $self->{veid
};
1061 my $conffile = $self->{veconffile
};
1063 $self->logmsg ("initialize VE $veid\n");
1065 my $vestat = $self->ve_status();
1066 if ($vestat->{running
}) {
1067 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1070 rmtree
$self->{rootfs
};
1071 mkpath
$self->{rootfs
};
1074 sub __deb_version_cmp
{
1075 my ($cur, $op, $new) = @_;
1077 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
1084 sub __parse_packages
{
1085 my ($pkginfo, $filename, $src) = @_;
1088 open (PKGLST
, "<$filename") ||
1089 die "unable to open '$filename'";
1091 while (my $rec = <PKGLST
>) {
1092 $rec =~ s/\n\s+/ /g;
1098 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
1102 my $pkg = $res->{'package'};
1103 if ($pkg && $res->{'filename'}) {
1105 if (my $info = $pkginfo->{$pkg}) {
1106 $cur = $info->{version
};
1108 my $new = $res->{version
};
1109 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1111 $res->{url
} = "$src/$res->{'filename'}";
1113 die "no url for package '$pkg'" if !$res->{url
};
1115 $pkginfo->{$pkg} = $res;
1126 return $self->{pkginfo
} if $self->{pkginfo
};
1128 my $infodir = $self->{infodir
};
1129 my $arch = $self->{config
}->{architecture
};
1131 my $availfn = "$infodir/available";
1136 # reading 'available' is faster, because it only contains latest version
1137 # (no need to do slow version compares)
1139 __parse_packages
($pkginfo, $availfn);
1140 $self->{pkginfo
} = $pkginfo;
1144 $self->logmsg ("generating available package list\n");
1146 foreach my $ss (@{$self->{sources
}}) {
1147 foreach my $comp (@{$ss->{comp
}}) {
1148 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1149 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1151 my $src = $ss->{mirror
} || $ss->{source
};
1153 __parse_packages
($pkginfo, $pkgfilelist, $src);
1157 if (my $dep = $self->{config
}->{depends
}) {
1158 foreach my $d (split (/,/, $dep)) {
1159 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1160 my ($pkg, $op, $rver) = ($1, $3, $4);
1161 $self->logmsg ("checking dependencies: $d\n");
1162 my $info = $pkginfo->{$pkg};
1163 die "package '$pkg' not available\n" if !$info;
1165 my $cver = $info->{version
};
1166 if (!__deb_version_cmp
($cver, $op, $rver)) {
1167 die "detected wrong version '$cver'\n";
1171 die "syntax error in depends field";
1176 $self->{pkginfo
} = $pkginfo;
1178 my $tmpfn = "$availfn.tmp$$";
1179 my $fd = IO
::File-
>new (">$tmpfn");
1180 foreach my $pkg (sort keys %$pkginfo) {
1181 my $info = $pkginfo->{$pkg};
1182 print $fd "package: $pkg\n";
1183 foreach my $k (sort keys %$info) {
1184 next if $k eq 'description';
1185 next if $k eq 'package';
1186 my $v = $info->{$k};
1187 print $fd "$k: $v\n" if $v;
1189 print $fd "description: $info->{description}\n" if $info->{description
};
1194 rename ($tmpfn, $availfn);
1199 sub __record_provides
{
1200 my ($pkginfo, $closure, $list, $skipself) = @_;
1202 foreach my $pname (@$list) {
1203 my $info = $pkginfo->{$pname};
1204 # fixme: if someone install packages directly using dpkg, there
1205 # is no entry in 'available', only in 'status'. In that case, we
1206 # should extract info from $instpkgs
1208 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1211 if (my $prov = $info->{provides
}) {
1212 my @pl = split (',', $prov);
1213 foreach my $p (@pl) {
1215 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1220 $closure->{$pname} = 1 if !$skipself;
1225 my ($self, $closure, $list) = @_;
1227 my $pkginfo = $self->pkginfo();
1229 # first, record provided packages
1230 __record_provides
($pkginfo, $closure, $list, 1);
1235 # then resolve dependencies
1236 foreach my $pname (@$list) {
1237 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1243 sub __closure_single
{
1244 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1248 $pname =~ s/:any$//;
1250 return if $closure->{$pname};
1252 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1254 my $dep = $info->{depends
};
1255 my $predep = $info->{'pre-depends'};
1257 my $size = $info->{size
};
1258 my $url = $info->{url
};
1260 $url || die "$pname: no url for package '$pname'";
1262 if (!$pkghash->{$pname}) {
1263 unshift @$pkglist, $pname;
1264 $pkghash->{$pname} = 1;
1267 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1269 $closure->{$pname} = 1;
1275 push @l, split (/,/, $predep) if $predep;
1276 push @l, split (/,/, $dep) if $dep;
1278 DEPEND
: foreach my $p (@l) {
1279 my @l1 = split (/\|/, $p);
1280 foreach my $p1 (@l1) {
1281 if ($p1 =~ m/^\s*(\S+).*/) {
1282 #printf (STDERR "$pname: $p --> $1\n");
1283 if ($closure->{$1}) {
1284 next DEPEND
; # dependency already met
1288 # search for non-excluded alternative
1290 foreach my $p1 (@l1) {
1291 if ($p1 =~ m/^\s*(\S+).*/) {
1292 next if grep { $1 eq $_ } @$excl;
1297 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1299 #printf (STDERR "$pname: $p --> $found\n");
1301 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1305 sub cache_packages
{
1306 my ($self, $pkglist) = @_;
1308 foreach my $pkg (@$pkglist) {
1309 $self->getpkgfile ($pkg);
1314 my ($self, $pkg) = @_;
1316 my $pkginfo = $self->pkginfo();
1317 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1318 my $cachedir = $self->{cachedir
};
1320 my $url = $info->{url
};
1323 if ($url =~ m
|/([^/]+.deb
)$|) {
1326 die "internal error";
1329 return $filename if -f
"$cachedir/$filename";
1333 $self->download ($url, "$cachedir/$filename");
1338 sub install_init_script
{
1339 my ($self, $script, $runlevel, $prio) = @_;
1341 my $suite = $self->{config
}->{suite
};
1342 my $rootdir = $self->{rootfs
};
1344 my $base = basename
($script);
1345 my $target = "$rootdir/etc/init.d/$base";
1347 $self->run_command ("install -m 0755 '$script' '$target'");
1348 if ($suite eq 'etch' || $suite eq 'lenny') {
1349 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1350 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1351 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1352 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1353 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
1354 || $suite eq 'hirsute' || $suite eq 'impish'
1356 die "unable to install init script (system uses systemd)\n";
1357 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1358 die "unable to install init script (system uses upstart)\n";
1360 $self->ve_command ("insserv $base");
1367 my ($self, $opts) = @_;
1369 my $pkginfo = $self->pkginfo();
1370 my $veid = $self->{veid
};
1371 my $suite = $self->{config
}->{suite
};
1373 my $important = [ @{$self->{incl
}} ];
1377 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1378 if ($mta eq 'postfix') {
1379 push @$important, "postfix";
1382 if ($opts->{include
}) {
1383 push @$important, split(',', $opts->{include
});
1387 if ($opts->{exclude
}) {
1388 $exclude->{$_} = 1 for split(',', $opts->{exclude
});
1391 foreach my $p (sort keys %$pkginfo) {
1392 next if grep { $p eq $_ } @{$self->{excl
}};
1393 my $pri = $pkginfo->{$p}->{priority
};
1395 next if $mta ne 'exim' && $p =~ m/exim/;
1396 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1398 push @$required, $p if $pri eq 'required';
1399 next if $exclude->{$p};
1400 push @$important, $p if $pri eq 'important';
1401 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1405 $required = $self->closure($closure, $required);
1406 $important = $self->closure($closure, $important);
1408 if (!$opts->{minimal
}) {
1409 $standard = $self->closure($closure, $standard);
1412 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1413 # except those explicitly excluded
1414 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1415 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1416 foreach my $d (split (/,/, $mdeps)) {
1417 if ($d =~ m/^\s*(\S+)$/) {
1419 next if $closure->{$pkg};
1420 next if grep { $pkg eq $_ } @{$self->{excl
}};
1421 die "missing ubuntu-minimal package '$pkg'\n";
1424 if (!$opts->{minimal
}) {
1425 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1426 foreach my $d (split (/,/, $mdeps)) {
1427 if ($d =~ m/^\s*(\S+)$/) {
1429 next if $closure->{$pkg};
1430 next if grep { $pkg eq $_ } @{$self->{excl
}};
1431 die "missing ubuntu-standard package '$pkg'\n";
1437 # download/cache all files first
1438 $self->cache_packages ($required);
1439 $self->cache_packages ($important);
1440 $self->cache_packages ($standard);
1442 my $rootdir = $self->{rootfs
};
1444 # extract required packages first
1445 $self->logmsg ("create basic environment\n");
1447 if ($self->can_usr_merge()) {
1448 $self->setup_usr_merge();
1451 my $compressor2opt = {
1456 my $compressor_re = join('|', keys $compressor2opt->%*);
1458 $self->logmsg ("extract required packages to rootfs\n");
1459 foreach my $p (@$required) {
1460 my $filename = $self->getpkgfile ($p);
1461 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1462 if ($content =~ m/^(data.tar.($compressor_re))$/m) {
1464 my $tar_opts = "--keep-directory-symlink $compressor2opt->{$2}";
1466 $self->run_command("ar -p '$self->{cachedir}/$filename' '$archive' | tar -C '$rootdir' -xf - $tar_opts");
1468 die "unexpected error for $p: no data.tar.{xz,gz,zst} found...";
1473 my $data = "Package: dpkg\n" .
1474 "Version: $pkginfo->{dpkg}->{version}\n" .
1475 "Status: install ok installed\n";
1477 write_file
($data, "$rootdir/var/lib/dpkg/status");
1478 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1479 write_file
("", "$rootdir/var/lib/dpkg/available");
1482 foreach my $ss (@{$self->{sources
}}) {
1483 my $url = $ss->{source
};
1484 my $comp = join (' ', @{$ss->{comp
}});
1485 $data .= "deb $url $ss->{suite} $comp\n\n";
1488 write_file
($data, "$rootdir/etc/apt/sources.list");
1490 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1491 write_file
($data, "$rootdir/etc/fstab", 0644);
1493 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1495 # avoid warnings about non-existent resolv.conf
1496 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1499 $suite eq 'impish' ||
1500 $suite eq 'hirsute' || $suite eq 'groovy' || $suite eq 'focal' ||
1501 $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1502 $suite eq 'bionic' || $suite eq 'artful' ||
1503 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1506 # no need to configure loopback device
1508 $data = "auto lo\niface lo inet loopback\n";
1509 mkdir "$rootdir/etc/network";
1510 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1514 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1516 # avoid warnings about missing default locale
1517 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1520 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1521 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1523 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1525 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1527 $self->logmsg ("initialize ld cache\n");
1528 $self->ve_command ("/sbin/ldconfig");
1529 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1531 $self->logmsg ("installing packages\n");
1533 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1535 $self->ve_dpkg ('install', 'dpkg');
1537 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1539 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1541 $self->ve_dpkg ('install', 'libc6');
1542 $self->ve_dpkg ('install', 'perl-base');
1544 unlink "$rootdir/usr/bin/awk";
1546 $self->ve_dpkg ('install', 'mawk');
1547 $self->ve_dpkg ('install', 'debconf');
1549 # unpack required packages
1550 foreach my $p (@$required) {
1551 $self->ve_dpkg ('unpack', $p);
1554 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1555 $self->ve_divert_add ("/sbin/init");
1556 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1558 # disable service activation
1559 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1560 $data = "#!/bin/sh\nexit 101\n";
1561 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1563 # disable start-stop-daemon
1564 $self->ve_divert_add ("/sbin/start-stop-daemon");
1568 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1570 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1573 $self->ve_divert_add ("/sbin/udevd");
1575 if ($suite eq 'etch') {
1576 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2"); # disable apache2 startup
1579 $self->logmsg ("configure required packages\n");
1580 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1582 # set postfix defaults
1583 if ($mta eq 'postfix') {
1584 $data = "postfix postfix/main_mailer_type select Local only\n";
1585 $self->ve_debconfig_set ($data);
1587 $data = "postmaster: root\nwebmaster: root\n";
1588 write_file
($data, "$rootdir/etc/aliases");
1591 if ($suite eq 'jaunty') {
1592 # jaunty does not create /var/run/network, so network startup fails.
1593 # so we do not use tmpfs for /var/run and /var/lock
1594 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1595 # and create the directory here
1596 $self->run_command ("mkdir $rootdir/var/run/network");
1599 # unpack base packages
1600 foreach my $p (@$important) {
1601 $self->ve_dpkg ('unpack', $p);
1605 if (-x
"$rootdir/sbin/ifconfig") {
1606 $self->ve_command ("ifconfig lo up");
1608 $self->ve_command ("ip link set lo up");
1611 $self->logmsg ("configure important packages\n");
1612 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1614 if (-d
"$rootdir/etc/event.d") {
1615 unlink <$rootdir/etc/event.d
/tty
*>;
1618 if (-f
"$rootdir/etc/inittab") {
1619 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1622 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1623 unlink "$rootdir/etc/mtab";
1624 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1627 $self->ve_command ("usermod -L root");
1629 if ($mta eq 'postfix') {
1630 $data = "postfix postfix/main_mailer_type select No configuration\n";
1631 $self->ve_debconfig_set ($data);
1633 unlink "$rootdir/etc/mailname";
1634 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1637 if (!$opts->{minimal
}) {
1638 # unpack standard packages
1639 foreach my $p (@$standard) {
1640 $self->ve_dpkg ('unpack', $p);
1643 $self->logmsg ("configure standard packages\n");
1644 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1647 # disable HWCLOCK access
1648 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1651 $self->ve_divert_add ("/usr/sbin/hald");
1653 # disable /dev/urandom init
1654 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1656 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1658 $self->ve_divert_add ("/sbin/klogd");
1661 # remove unnecessays sysctl entries to avoid warnings
1663 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1664 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1665 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1666 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1667 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1668 $self->run_command ($cmd);
1670 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1671 if (-f
$bindv6only) {
1673 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1674 $cmd .= " -i '$bindv6only'";
1675 $self->run_command ($cmd);
1678 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1679 # disable tty init (console-setup)
1681 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1682 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1683 $self->run_command ($cmd);
1686 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1687 # remove sysctl setup (avoid warnings at startup)
1688 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1689 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1690 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1691 $self->run_command ("rm $filelist");
1694 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1695 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1702 my $veid = $self->{veid
};
1703 my $conffile = $self->{veconffile
};
1705 my $vestat = $self->ve_status();
1707 if (!$vestat->{exist
}) {
1708 $self->logmsg ("Please create the appliance first (bootstrap)");
1712 if (!$vestat->{running
}) {
1713 $self->run_command ("lxc-start -n $veid -f $conffile");
1716 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1719 sub ve_mysql_command
{
1720 my ($self, $sql, $password) = @_;
1722 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1723 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1725 $self->ve_command ("mysql", $sql);
1728 sub ve_mysql_bootstrap
{
1729 my ($self, $sql, $password) = @_;
1733 my $suite = $self->{config
}->{suite
};
1735 if ($suite eq 'jessie') {
1736 my $rootdir = $self->{rootfs
};
1737 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1740 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1741 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1744 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1745 "--skip-bdb --skip-innodb --skip-ndbcluster";
1748 $self->ve_command ($cmd, $sql);
1751 sub compute_required
{
1752 my ($self, $pkglist) = @_;
1754 my $pkginfo = $self->pkginfo();
1755 my $instpkgs = $self->read_installed ();
1758 __record_provides
($pkginfo, $closure, [keys $instpkgs->%*]);
1760 return $self->closure ($closure, $pkglist);
1764 my ($self, $opts) = @_;
1766 my @supp = ('7.4', '8.1');
1767 my $pgversion; # NOTE: not setting that defaults to the distro default, normally the best choice
1769 my $suite = $self->{config
}->{suite
};
1771 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1774 } elsif ($suite eq 'squeeze') {
1777 } elsif ($suite eq 'wheezy') {
1780 } elsif ($suite eq 'jessie') {
1783 } elsif ($suite eq 'stretch') {
1786 } elsif ($suite eq 'buster') {
1789 } elsif ($suite eq 'bullseye') {
1791 } elsif ($suite eq 'bookworm') {
1792 # FIXME: update once froozen
1793 @supp = ('13', '14');
1795 $pgversion = $opts->{version
} if $opts->{version
};
1798 if (defined($pgversion)) {
1799 die "unsupported postgres version '$pgversion'\n" if !grep { $pgversion eq $_; } @supp;
1801 $required = $self->compute_required (["postgresql-$pgversion"]);
1803 $required = $self->compute_required (["postgresql"]);
1806 $self->cache_packages ($required);
1808 $self->ve_dpkg ('install', @$required);
1810 my $iscript = "postgresql-$pgversion";
1811 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1812 $suite eq 'stretch') {
1813 $iscript = 'postgresql';
1816 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1820 my ($self, $opts) = @_;
1822 my $password = $opts->{password
};
1823 my $rootdir = $self->{rootfs
};
1825 my $suite = $self->{config
}->{suite
};
1828 if ($suite eq 'squeeze') {
1830 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1833 die "task_mysql: unsupported suite '$suite'";
1836 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1838 $self->cache_packages ($required);
1840 $self->ve_dpkg ('install', @$required);
1842 # fix security (see /usr/bin/mysql_secure_installation)
1843 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1844 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1845 "FLUSH PRIVILEGES;\n";
1846 $self->ve_mysql_bootstrap ($sql);
1850 my $rpw = $password eq 'random' ?
'admin' : $password;
1852 my $sql = "USE mysql;\n" .
1853 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1854 "FLUSH PRIVILEGES
;\n";
1855 $self->ve_mysql_bootstrap ($sql);
1857 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1858 if ($password eq 'random') {
1859 $self->install_init_script ($script_mysql_randompw, 2, 20);
1863 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1867 my ($self, $opts) = @_;
1869 my $memlimit = $opts->{memlimit
};
1870 my $rootdir = $self->{rootfs
};
1872 my $required = $self->compute_required([qw(php php-cli libapache2-mod-php php-gd)]);
1874 $self->cache_packages ($required);
1876 $self->ve_dpkg ('install', @$required);
1879 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1884 my ($self, $pkglist, $unpack) = @_;
1886 my $required = $self->compute_required ($pkglist);
1888 $self->cache_packages ($required);
1890 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1894 my ($self, $distclean) = @_;
1896 unlink $self->{logfile
};
1897 unlink "$self->{targetname}.tar";
1898 unlink "$self->{targetname}.tar.gz";
1900 $self->ve_destroy ();
1903 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1905 rmtree
$self->{infodir
};