13 use POSIX qw
(LONG_MAX
);
16 # fixme: lock container ?
18 my $dablibdir = "/usr/lib/dab";
19 my $devicetar = "$dablibdir/devices.tar.gz";
20 my $default_env = "$dablibdir/scripts/defenv";
21 my $fake_init = "$dablibdir/scripts/init.pl";
22 my $script_ssh_init = "$dablibdir/scripts/ssh_gen_host_keys";
23 my $script_mysql_randompw = "$dablibdir/scripts/mysql_randompw";
24 my $script_init_urandom = "$dablibdir/scripts/init_urandom";
26 my $postfix_main_cf = <<EOD;
27 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
29 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
32 # appending .domain is the MUA's job.
33 append_dot_mydomain = no
35 # Uncomment the next line to generate "delayed mail" warnings
36 #delay_warning_time = 4h
38 alias_maps = hash:/etc/aliases
39 alias_database = hash:/etc/aliases
40 mydestination = \$myhostname, localhost.\$mydomain, localhost
42 mynetworks = 127.0.0.0/8
43 inet_interfaces = loopback-only
44 recipient_delimiter = +
46 compatibility_level = 2
50 # produce apt compatible filenames (/var/lib/apt/lists)
51 sub __url_to_filename
{
64 # systemd: true (except for devuan ostypes)
65 my $supported_suites = {
67 ostype
=> "debian-12",
70 ostype
=> "debian-11",
73 ostype
=> "debian-10",
76 # DEVUAN (imply systemd = 0 default)
78 ostype
=> "devuan-3.0",
81 ostype
=> "devuan-4.0",
84 ostype
=> "devuan-5.0",
89 ostype
=> "ubuntu-18.04",
93 ostype
=> "ubuntu-20.04",
97 ostype
=> "ubuntu-22.04",
101 ostype
=> "ubuntu-22.10",
105 ostype
=> "ubuntu-23.04",
109 ostype
=> "ubuntu-23.10",
117 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
120 $suiteinfo->{origin
} //= 'debian';
121 $suiteinfo->{suite
} //= $suite;
123 $suiteinfo->{flags
} //= {};
124 if ($suiteinfo->{ostype
} =~ /^devuan/) {
125 $suiteinfo->{flags
}->{systemd
} //= 0;
127 $suiteinfo->{flags
}->{systemd
} //= 1;
134 my ($self, $url, $path) = @_;
135 my $tmpfn = "$path.tmp$$";
137 $self->logmsg ("download: $url\n");
139 eval { $self->run_command ("wget -q '$url' -O '$tmpfn'") };
145 rename ($tmpfn, $path);
149 my ($data, $file, $perm) = @_;
151 die "no filename" if !$file;
155 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
156 die "unable to open file '$file'";
166 die "no filename" if !$file;
168 my $fh = IO
::File-
>new ($file) ||
169 die "unable to open file '$file'";
171 local $/; # slurp mode
185 my $fh = IO
::File-
>new ("<$filename") || return $res;
188 while (defined (my $line = <$fh>)) {
189 next if $line =~ m/^\#/;
190 next if $line =~ m/^\s*$/;
200 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
201 $res->{headline
} = $1;
202 chomp $res->{headline
};
205 $res->{description
} = $long;
206 chomp $res->{description
};
207 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
208 my ($key, $value) = (lc ($1), $2);
209 if ($key eq 'source' || $key eq 'mirror') {
210 push @{$res->{$key}}, $value;
212 die "duplicate key '$key'\n" if defined ($res->{$key});
213 $res->{$key} = $value;
216 die "unable to parse config file: $rec";
220 die "unable to parse config file" if $rec;
226 my ($self, $cmd, $input, $getoutput) = @_;
228 my $reader = IO
::File-
>new();
229 my $writer = IO
::File-
>new();
230 my $error = IO
::File-
>new();
234 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
238 if (ref ($cmd) eq 'ARRAY') {
239 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
241 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
248 if ($orig_pid != $$) {
249 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
256 print $writer $input if defined $input;
259 my $select = IO
::Select-
>new();
260 $select->add ($reader);
261 $select->add ($error);
264 my $logfd = $self->{logfd
};
266 while ($select->count) {
267 my @handles = $select->can_read ();
269 foreach my $h (@handles) {
271 my $count = sysread ($h, $buf, 4096);
272 if (!defined ($count)) {
274 die "command '$cmdstr' failed: $!";
276 $select->remove ($h) if !$count;
280 $res .= $buf if $getoutput;
287 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
295 $self->writelog (@_);
300 my $fd = $self->{logfd
};
304 sub __sample_config
{
308 my $arch = $self->{config
}->{architecture
};
310 my $ostype = $self->{config
}->{ostype
};
312 if ($ostype =~ m/^de(bi|vu)an-/) {
313 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
314 $data .= "lxc.include = /usr/share/lxc/config/debian.userns.conf\n" if $> != 0;
315 } elsif ($ostype =~ m/^ubuntu-/) {
316 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
317 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.userns.conf\n" if $> != 0;
319 die "unknown os type '$ostype'\n";
322 $data .= "lxc.idmap = u 0 100000 65536\n";
323 $data .= "lxc.idmap = g 0 100000 65536\n";
325 $data .= "lxc.uts.name = localhost\n";
326 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
335 if (my $fd = IO
::File-
>new (".veid")) {
342 $self->{working_dir
} = getcwd
;
343 $self->{veconffile
} = "$self->{working_dir}/config";
344 $self->{rootfs
} = "$self->{working_dir}/rootfs";
347 $self->{veid
} = $cid;
353 UUID
::generate
($uuid);
354 UUID
::unparse
($uuid, $uuid_str);
355 $self->{veid
} = $uuid_str;
357 my $fd = IO
::File-
>new (">.veid") ||
358 die "unable to write '.veid'\n";
359 print $fd "$self->{veid}\n";
362 my $cdata = $self->__sample_config();
364 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
365 die "unable to write lxc config file '$self->{veconffile}' - $!";
369 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
371 $self->logmsg ("allocated VE $self->{veid}\n");
373 return $self->{veid
};
376 # just use some simple heuristic for now, merge usr for releases newer than ubuntu 21.x or debian 11
380 my $ostype = $self->{config
}->{ostype
};
382 # FIXME: add configuration override posibillity
384 if ($ostype =~ m/^debian-(\d+)/) {
385 return int($1) >= 11;
386 } elsif ($ostype =~ m/^ubuntu-(\d+)/) {
387 return int($1) >= 21;
392 sub setup_usr_merge
{
395 my $rootfs = $self->{rootfs
};
396 my $arch = $self->{config
}->{architecture
};
398 # similar to https://salsa.debian.org/installer-team/debootstrap/-/blob/master/functions#L1354
399 my @merged_dirs = qw(bin sbin lib);
401 if ($arch eq 'amd64') {
402 push @merged_dirs, qw(lib32 lib64 libx32);
403 } elsif ($arch eq 'i386') {
404 push @merged_dirs, qw(lib64 libx32);
407 $self->logmsg ("setup usr-merge symlinks for '" . join("', '", @merged_dirs) . "'\n");
409 for my $dir (@merged_dirs) {
410 symlink("usr/$dir", "$rootfs/$dir") or warn "could not create symlink - $!\n";
411 mkpath
"$rootfs/usr/$dir";
415 sub get_target_name
{
418 my $name = $config->{name
} || die "no 'name' specified\n";
419 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || die "illegal characters in name '$name'\n";
421 my ($version, $arch, $ostype) = $config->@{'version', 'architecture', 'ostype'};
422 $name = "${ostype}-${name}" if $name !~ m/^$ostype/;
424 return "${name}_${version}_${arch}"
428 my ($class, $config) = @_;
430 $class = ref ($class) || $class;
431 $config = read_config
('dab.conf') if !$config;
438 $self->{logfile
} = "logfile";
439 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") || die "unable to open log file";
441 my $arch = $config->{architecture
} || die "no 'architecture' specified\n";
442 die "unsupported architecture '$arch'\n" if $arch !~ m/^(i386|amd64)$/;
444 my $suite = $config->{suite
} || die "no 'suite' specified\n";
446 my $suiteinfo = get_suite_info
($suite);
447 $suite = $suiteinfo->{suite
};
448 $config->{ostype
} = $suiteinfo->{ostype
};
450 # assert required dab.conf keys exist
451 for my $key (qw(version section headline maintainer)) {
452 die "no '$key' specified\n" if !$config->{$key};
455 $self->{targetname
} = get_target_name
($config);
457 if (!$config->{source
}) {
458 if (lc($suiteinfo->{origin
}) eq 'debian') {
459 if ($suite eq 'etch' || $suite eq 'lenny') {
460 push @{$config->{source
}}, (
461 'http://ftp.debian.org/debian SUITE main contrib',
462 'http://security.debian.org SUITE/updates main contrib',
464 } elsif ($suite =~ /^(?:bullseye|bookworm|trixie|forky)$/) {
465 push @{$config->{source
}}, (
466 "http://deb.debian.org/debian SUITE main contrib",
467 "http://deb.debian.org/debian SUITE-updates main contrib",
468 "http://security.debian.org SUITE-security main contrib",
471 push @{$config->{source
}}, (
472 "http://ftp.debian.org/debian SUITE main contrib",
473 "http://ftp.debian.org/debian SUITE-updates main contrib",
474 "http://security.debian.org SUITE/updates main contrib",
477 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
478 my $comp = "main restricted universe multiverse";
479 push @{$config->{source
}}, (
480 "http://archive.ubuntu.com/ubuntu SUITE $comp",
481 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
482 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
491 foreach my $s (@{$config->{source
}}) {
492 if ($s =~ m
@^\s*((https?
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
493 my ($url, $su, $components) = ($1, $3, $4);
494 $su =~ s/SUITE/$suite/;
495 $components =~ s/^\s+//;
496 $components =~ s/\s+$//;
498 foreach my $co (split (/\s+/, $components)) {
501 $ca = ['main'] if !$ca;
509 die "syntax error in source spezification '$s'\n";
513 foreach my $m (@{$config->{mirror
}}) {
514 if ($m =~ m
@^\s*((https?
|ftp
)://\S
+)\s
*=>\s
*((https?
|ftp
)://\S
+)\s
*$@) {
515 my ($ms, $md) = ($1, $3);
517 foreach my $ss (@$sources) {
518 if ($ss->{source
} eq $ms) {
524 die "unusable mirror $ms\n" if !$found;
526 die "syntax error in mirror spezification '$m'\n";
529 $self->{sources
} = $sources;
530 $self->{infodir
} = "info";
532 $self->__allocate_ve();
534 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
536 my $incl = [qw
(less ssh openssh-server logrotate
)];
537 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe pppoeconf nfs-common mtools ntp
)];
539 # ubuntu has too many dependencies on udev, so we cannot exclude it (instead we disable udevd)
540 if (lc($suiteinfo->{origin
}) eq 'ubuntu' && $suiteinfo->{flags
}->{systemd
}) {
541 push @$incl, 'isc-dhcp-client';
542 push @$excl, qw(libmodule-build-perl libdrm-common libdrm2 libplymouth5 plymouth plymouth-theme-ubuntu-text powermgmt-base);
543 if ($suite eq 'jammy') {
544 push @$excl, qw(fuse); # avoid fuse2 <-> fuse3 conflict
546 } elsif ($suite eq 'buster' || $suite eq 'bullseye' || $suite eq 'bookworm') {
547 push @$excl, qw(module-init-tools pciutils hdparm memtest86+ parted);
549 push @$excl, qw(udev module-init-tools pciutils hdparm memtest86+ parted);
552 $self->{incl
} = $incl;
553 $self->{excl
} = $excl;
561 my $infodir = $self->{infodir
};
562 my $arch = $self->{config
}->{architecture
};
568 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
569 die "unable to open log file";
582 foreach my $ss (@{$self->{sources
}}) {
583 my $src = $ss->{mirror
} || $ss->{source
};
584 my $path = "dists/$ss->{suite}/Release";
585 my $url = "$src/$path";
586 my $target = __url_to_filename
("$ss->{source}/$path");
588 $self->download ($url, "$infodir/$target");
589 $self->download ("$url.gpg", "$infodir/$target.gpg");
590 # fixme: impl. verify (needs --keyring option)
594 warn "Release info ignored\n";
597 foreach my $comp (@{$ss->{comp
}}) {
598 foreach my $compressor (@$COMPRESSORS) {
599 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
600 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
601 my $pkgsrc = "$src/$path";
603 $self->download ($pkgsrc, $target);
604 $self->run_command ("$compressor->{decomp} '$target'");
607 print $logfd "could not download Packages.$compressor->{ext}\n";
617 my ($self, $filename, $size) = @_;
619 my $config = $self->{config
};
623 $data .= "Name: $config->{name}\n";
624 $data .= "Version: $config->{version}\n";
625 $data .= "Type: lxc\n";
626 $data .= "OS: $config->{ostype}\n";
627 $data .= "Section: $config->{section}\n";
628 $data .= "Maintainer: $config->{maintainer}\n";
629 $data .= "Architecture: $config->{architecture}\n";
630 $data .= "Installed-Size: $size\n";
633 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
634 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
635 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
638 $data .= "Description: $config->{headline}\n";
639 $data .= "$config->{description}\n" if $config->{description
};
641 write_file
($data, $filename, 0644);
645 my ($self, $opts) = @_;
647 my $suite = $self->{config
}->{suite
};
648 my $infodir = $self->{infodir
};
649 my $arch = $self->{config
}->{architecture
};
651 my $instpkgs = $self->read_installed ();
652 my $pkginfo = $self->pkginfo();
653 my $veid = $self->{veid
};
654 my $conffile = $self->{veconffile
};
655 my $rootdir = $self->{rootfs
};
657 my $vestat = $self->ve_status();
658 die "ve not running - unable to finalize\n" if !$vestat->{running
};
661 if (-f
"$rootdir/etc/init.d/mysql") {
662 $self->ve_command ("/etc/init.d/mysql stop");
665 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
666 unlink "$rootdir/root/.my.cnf";
669 if ($suite eq 'etch') {
670 # enable apache2 startup
671 if ($instpkgs->{apache2
}) {
672 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
674 unlink "$rootdir/etc/default/apache2";
677 $self->logmsg ("cleanup package status\n");
678 # prevent auto selection of all standard, required or important
679 # packages which are not installed
680 foreach my $pkg (keys %$pkginfo) {
681 my $pri = $pkginfo->{$pkg}->{priority
};
682 if ($pri && ($pri eq 'required' || $pri eq 'important'
683 || $pri eq 'standard')) {
684 if (!$instpkgs->{$pkg}) {
685 $self->ve_dpkg_set_selection ($pkg, 'purge');
690 $self->ve_command ("apt-get clean");
692 $self->logmsg ("update available package list\n");
694 $self->ve_command ("dpkg --clear-avail");
695 foreach my $ss (@{$self->{sources
}}) {
696 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
697 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
698 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
699 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
701 foreach my $comp (@{$ss->{comp
}}) {
702 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
703 "$comp/binary-$arch/Packages");
704 my $target = "/var/lib/apt/lists/$src";
705 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
706 $self->ve_command ("dpkg --merge-avail '$target'");
710 # set dselect default method
711 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
713 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
715 $self->ve_divert_remove ("/sbin/start-stop-daemon");
717 $self->ve_divert_remove ("/sbin/init");
719 # finally stop the VE
720 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
722 unlink "$rootdir/sbin/defenv";
723 unlink <$rootdir/root/dead.letter
*>;
724 unlink "$rootdir/var/log/init.log";
725 unlink "$rootdir/aquota.group", "$rootdir/aquota.user";
727 write_file
("", "$rootdir/var/log/syslog");
729 my $get_path_size = sub {
731 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
732 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
735 die "unable to detect size for '$path'\n";
739 $self->logmsg ("detecting final appliance size: ");
740 my $size = $get_path_size->($rootdir);
741 $self->logmsg ("$size MB\n");
743 $self->write_config ("$rootdir/etc/appliance.info", $size);
745 $self->logmsg ("creating final appliance archive\n");
747 my $target = "$self->{targetname}.tar";
749 my $compressor = $opts->{compressor
} // 'gz';
750 my $compressor2cmd_map = {
753 zst
=> 'zstd --rm -9',
754 zstd
=> 'zstd --rm -9',
755 'zstd-max' => 'zstd --rm -19 -T0', # maximal level where the decompressor can still run efficiently
757 my $compressor2ending = {
762 my $compressor_cmd = $compressor2cmd_map->{$compressor};
763 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
764 if !defined($compressor_cmd);
766 my $ending = $compressor2ending->{$compressor} // $compressor;
767 my $final_archive = "${target}.${ending}";
769 unlink $final_archive;
771 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
772 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
773 $self->run_command ("$compressor_cmd $target");
775 $self->logmsg ("detecting final commpressed appliance size: ");
776 $size = $get_path_size->($final_archive);
777 $self->logmsg ("$size MB\n");
779 $self->logmsg ("appliance archive: $final_archive\n");
785 my $rootdir = $self->{rootfs
};
787 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
789 open(my $PKGLST, '<', $pkgfilelist) or die "unable to open '$pkgfilelist' - $!";
793 while (my $rec = <$PKGLST>) {
799 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
803 my $pkg = $res->{'package'};
804 if (my $status = $res->{status
}) {
805 my @sa = split (/\s+/, $status);
807 if ($stat && ($stat ne 'purge')) {
808 $pkglist->{$pkg} = $res;
821 my $veid = $self->{veid
};
823 my $res = { running
=> 0 };
825 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
827 my $filename = "/proc/net/unix";
829 # similar test is used by lcxcontainers.c: list_active_containers
830 my $fh = IO
::File-
>new ($filename, "r");
833 while (defined(my $line = <$fh>)) {
834 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
836 if ($path =~ m!^@/\S+/$veid/command$!) {
847 my ($self, $cmd, $input) = @_;
849 my $veid = $self->{veid
};
850 my $conffile = $self->{veconffile
};
852 if (ref ($cmd) eq 'ARRAY') {
853 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
854 $self->run_command($cmd, $input);
856 $self->run_command("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
860 # like ve_command, but pipes stdin correctly
862 my ($self, @cmd) = @_;
864 my $veid = $self->{veid
};
865 my $conffile = $self->{veconffile
};
868 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
869 'defenv', @cmd) || die "unable to exec command";
871 while (defined (my $line = <$reader>)) {
872 $self->logmsg ($line);
878 die "ve_exec failed - status $rc\n" if $rc != 0;
882 my ($self, $filename) = @_;
884 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
885 "--rename '$filename'");
887 sub ve_divert_remove
{
888 my ($self, $filename) = @_;
890 my $rootdir = $self->{rootfs
};
892 unlink "$rootdir/$filename";
893 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
896 sub ve_debconfig_set
{
897 my ($self, $dcdata) = @_;
899 my $rootdir = $self->{rootfs
};
900 my $cfgfile = "/tmp/debconf.txt";
901 write_file
($dcdata, "$rootdir/$cfgfile");
902 $self->ve_command ("debconf-set-selections $cfgfile");
903 unlink "$rootdir/$cfgfile";
906 sub ve_dpkg_set_selection
{
907 my ($self, $pkg, $status) = @_;
909 $self->ve_command ("dpkg --set-selections", "$pkg $status");
913 my ($self, $cmd, @pkglist) = @_;
915 return if !scalar (@pkglist);
917 my $pkginfo = $self->pkginfo();
919 my $rootdir = $self->{rootfs
};
920 my $cachedir = $self->{cachedir
};
924 foreach my $pkg (@pkglist) {
925 my $filename = $self->getpkgfile ($pkg);
926 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
927 push @files, "/$filename";
928 $self->logmsg ("$cmd: $pkg\n");
931 my $fl = join (' ', @files);
933 if ($cmd eq 'install') {
934 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
935 } elsif ($cmd eq 'unpack') {
936 $self->ve_command ("dpkg --force-depends --unpack $fl");
938 die "internal error";
941 foreach my $fn (@files) { unlink "$rootdir$fn"; }
947 my $veid = $self->{veid
}; # fixme
948 my $conffile = $self->{veconffile
};
950 my $vestat = $self->ve_status();
951 if ($vestat->{running
}) {
952 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
955 rmtree
$self->{rootfs
};
956 unlink $self->{veconffile
};
962 my $veid = $self->{veid
};
963 my $conffile = $self->{veconffile
};
965 $self->logmsg ("initialize VE $veid\n");
967 my $vestat = $self->ve_status();
968 if ($vestat->{running
}) {
969 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
972 rmtree
$self->{rootfs
};
973 mkpath
$self->{rootfs
};
976 sub __deb_version_cmp
{
977 my ($cur, $op, $new) = @_;
979 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
986 sub __parse_packages
{
987 my ($pkginfo, $filename, $src) = @_;
990 open(my $PKGLST, '<', $filename) or die "unable to open '$filename' - $!";
992 while (my $rec = <$PKGLST>) {
999 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
1003 my $pkg = $res->{'package'};
1004 if ($pkg && $res->{'filename'}) {
1006 if (my $info = $pkginfo->{$pkg}) {
1007 $cur = $info->{version
};
1009 my $new = $res->{version
};
1010 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1012 $res->{url
} = "$src/$res->{'filename'}";
1014 die "no url for package '$pkg'" if !$res->{url
};
1016 $pkginfo->{$pkg} = $res;
1027 return $self->{pkginfo
} if $self->{pkginfo
};
1029 my $infodir = $self->{infodir
};
1030 my $arch = $self->{config
}->{architecture
};
1032 my $availfn = "$infodir/available";
1037 # reading 'available' is faster, because it only contains latest version
1038 # (no need to do slow version compares)
1040 __parse_packages
($pkginfo, $availfn);
1041 $self->{pkginfo
} = $pkginfo;
1045 $self->logmsg ("generating available package list\n");
1047 foreach my $ss (@{$self->{sources
}}) {
1048 foreach my $comp (@{$ss->{comp
}}) {
1049 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1050 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1052 my $src = $ss->{mirror
} || $ss->{source
};
1054 __parse_packages
($pkginfo, $pkgfilelist, $src);
1058 if (my $dep = $self->{config
}->{depends
}) {
1059 foreach my $d (split (/,/, $dep)) {
1060 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1061 my ($pkg, $op, $rver) = ($1, $3, $4);
1062 $self->logmsg ("checking dependencies: $d\n");
1063 my $info = $pkginfo->{$pkg};
1064 die "package '$pkg' not available\n" if !$info;
1066 my $cver = $info->{version
};
1067 if (!__deb_version_cmp
($cver, $op, $rver)) {
1068 die "detected wrong version '$cver'\n";
1072 die "syntax error in depends field";
1077 $self->{pkginfo
} = $pkginfo;
1079 my $tmpfn = "$availfn.tmp$$";
1080 my $fd = IO
::File-
>new (">$tmpfn");
1081 foreach my $pkg (sort keys %$pkginfo) {
1082 my $info = $pkginfo->{$pkg};
1083 print $fd "package: $pkg\n";
1084 foreach my $k (sort keys %$info) {
1085 next if $k eq 'description';
1086 next if $k eq 'package';
1087 my $v = $info->{$k};
1088 print $fd "$k: $v\n" if $v;
1090 print $fd "description: $info->{description}\n" if $info->{description
};
1095 rename ($tmpfn, $availfn);
1100 sub __record_provides
{
1101 my ($pkginfo, $closure, $list, $skipself) = @_;
1103 foreach my $pname (@$list) {
1104 my $info = $pkginfo->{$pname};
1105 # fixme: if someone install packages directly using dpkg, there
1106 # is no entry in 'available', only in 'status'. In that case, we
1107 # should extract info from $instpkgs
1109 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1112 if (my $prov = $info->{provides
}) {
1113 my @pl = split (',', $prov);
1114 foreach my $p (@pl) {
1116 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1121 $closure->{$pname} = 1 if !$skipself;
1126 my ($self, $closure, $list) = @_;
1128 my $pkginfo = $self->pkginfo();
1130 # first, record provided packages
1131 __record_provides
($pkginfo, $closure, $list, 1);
1136 # then resolve dependencies
1137 foreach my $pname (@$list) {
1138 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1144 sub __closure_single
{
1145 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1149 $pname =~ s/:any$//;
1151 return if $closure->{$pname};
1153 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1155 my $dep = $info->{depends
};
1156 my $predep = $info->{'pre-depends'};
1158 my $size = $info->{size
};
1159 my $url = $info->{url
};
1161 $url || die "$pname: no url for package '$pname'";
1163 if (!$pkghash->{$pname}) {
1164 unshift @$pkglist, $pname;
1165 $pkghash->{$pname} = 1;
1168 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1170 $closure->{$pname} = 1;
1176 push @l, split (/,/, $predep) if $predep;
1177 push @l, split (/,/, $dep) if $dep;
1179 DEPEND
: foreach my $p (@l) {
1180 my @l1 = split (/\|/, $p);
1181 foreach my $p1 (@l1) {
1182 if ($p1 =~ m/^\s*(\S+).*/) {
1183 #printf (STDERR "$pname: $p --> $1\n");
1184 if ($closure->{$1}) {
1185 next DEPEND
; # dependency already met
1189 # search for non-excluded alternative
1191 foreach my $p1 (@l1) {
1192 if ($p1 =~ m/^\s*(\S+).*/) {
1193 next if grep { $1 eq $_ } @$excl;
1198 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1200 #printf (STDERR "$pname: $p --> $found\n");
1202 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1206 sub cache_packages
{
1207 my ($self, $pkglist) = @_;
1209 foreach my $pkg (@$pkglist) {
1210 $self->getpkgfile ($pkg);
1215 my ($self, $pkg) = @_;
1217 my $pkginfo = $self->pkginfo();
1218 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1219 my $cachedir = $self->{cachedir
};
1221 my $url = $info->{url
};
1224 if ($url =~ m
|/([^/]+.deb
)$|) {
1227 die "internal error";
1230 return $filename if -f
"$cachedir/$filename";
1234 $self->download ($url, "$cachedir/$filename");
1239 sub install_init_script
{
1240 my ($self, $script, $runlevel, $prio) = @_;
1242 my $suite = $self->{config
}->{suite
};
1243 my $suiteinfo = get_suite_info
($suite);
1244 my $rootdir = $self->{rootfs
};
1246 my $base = basename
($script);
1247 my $target = "$rootdir/etc/init.d/$base";
1249 $self->run_command ("install -m 0755 '$script' '$target'");
1250 if ($suite eq 'etch' || $suite eq 'lenny') {
1251 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1252 } elsif ($suiteinfo->{flags
}->{systemd
}) {
1253 die "unable to install init script (system uses systemd)\n";
1254 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1255 die "unable to install init script (system uses upstart)\n";
1257 $self->ve_command ("insserv $base");
1264 my ($self, $opts) = @_;
1266 my $pkginfo = $self->pkginfo();
1267 my $veid = $self->{veid
};
1268 my $suite = $self->{config
}->{suite
};
1269 my $suiteinfo = get_suite_info
($suite);
1271 my $important = [ @{$self->{incl
}} ];
1275 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1276 if ($mta eq 'postfix') {
1277 push @$important, "postfix";
1280 if ($opts->{include
}) {
1281 push @$important, split(',', $opts->{include
});
1285 if ($opts->{exclude
}) {
1286 $exclude->{$_} = 1 for split(',', $opts->{exclude
});
1289 foreach my $p (sort keys %$pkginfo) {
1290 next if grep { $p eq $_ } @{$self->{excl
}};
1291 my $pri = $pkginfo->{$p}->{priority
};
1293 next if $mta ne 'exim' && $p =~ m/exim/;
1294 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1296 push @$required, $p if $pri eq 'required';
1297 next if $exclude->{$p};
1298 push @$important, $p if $pri eq 'important';
1299 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1303 $required = $self->closure($closure, $required);
1304 $important = $self->closure($closure, $important);
1306 if (!$opts->{minimal
}) {
1307 $standard = $self->closure($closure, $standard);
1310 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1311 # except those explicitly excluded
1312 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1313 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1314 foreach my $d (split (/,/, $mdeps)) {
1315 if ($d =~ m/^\s*(\S+)$/) {
1317 next if $closure->{$pkg};
1318 next if grep { $pkg eq $_ } @{$self->{excl
}};
1319 die "missing ubuntu-minimal package '$pkg'\n";
1322 if (!$opts->{minimal
}) {
1323 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1324 foreach my $d (split (/,/, $mdeps)) {
1325 if ($d =~ m/^\s*(\S+)$/) {
1327 next if $closure->{$pkg};
1328 next if grep { $pkg eq $_ } @{$self->{excl
}};
1329 die "missing ubuntu-standard package '$pkg'\n";
1335 # download/cache all files first
1336 $self->cache_packages ($required);
1337 $self->cache_packages ($important);
1338 $self->cache_packages ($standard);
1340 my $rootdir = $self->{rootfs
};
1342 # extract required packages first
1343 $self->logmsg ("create basic environment\n");
1345 if ($self->can_usr_merge()) {
1346 $self->setup_usr_merge();
1349 my $compressor2opt = {
1354 my $compressor_re = join('|', keys $compressor2opt->%*);
1356 $self->logmsg ("extract required packages to rootfs\n");
1357 foreach my $p (@$required) {
1358 my $filename = $self->getpkgfile ($p);
1359 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1360 if ($content =~ m/^(data.tar.($compressor_re))$/m) {
1362 my $tar_opts = "--keep-directory-symlink $compressor2opt->{$2}";
1364 $self->run_command("ar -p '$self->{cachedir}/$filename' '$archive' | tar -C '$rootdir' -xf - $tar_opts");
1366 die "unexpected error for $p: no data.tar.{xz,gz,zst} found...";
1371 my $data = "Package: dpkg\n" .
1372 "Version: $pkginfo->{dpkg}->{version}\n" .
1373 "Status: install ok installed\n";
1375 write_file
($data, "$rootdir/var/lib/dpkg/status");
1376 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1377 write_file
("", "$rootdir/var/lib/dpkg/available");
1380 foreach my $ss (@{$self->{sources
}}) {
1381 my $url = $ss->{source
};
1382 my $comp = join (' ', @{$ss->{comp
}});
1383 $data .= "deb $url $ss->{suite} $comp\n\n";
1386 write_file
($data, "$rootdir/etc/apt/sources.list");
1388 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1389 write_file
($data, "$rootdir/etc/fstab", 0644);
1391 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1393 # avoid warnings about non-existent resolv.conf
1394 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1396 if (lc($suiteinfo->{origin
}) eq 'ubuntu' && $suiteinfo->{flags
}->{systemd
}) {
1397 # no need to configure loopback device
1398 # FIXME: Debian (systemd based?) too?
1400 $data = "auto lo\niface lo inet loopback\n";
1401 mkdir "$rootdir/etc/network";
1402 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1406 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'") if $opts->{'device-skelleton'};
1408 # avoid warnings about missing default locale
1409 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1412 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1413 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1415 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1417 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1419 $self->logmsg ("initialize ld cache\n");
1420 $self->ve_command ("/sbin/ldconfig");
1421 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1423 $self->logmsg ("installing packages\n");
1425 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1427 $self->ve_dpkg ('install', 'dpkg');
1429 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1431 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1433 $self->ve_dpkg ('install', 'libc6');
1434 $self->ve_dpkg ('install', 'perl-base');
1436 unlink "$rootdir/usr/bin/awk";
1438 $self->ve_dpkg ('install', 'mawk');
1439 $self->ve_dpkg ('install', 'debconf');
1441 # unpack required packages
1442 foreach my $p (@$required) {
1443 $self->ve_dpkg ('unpack', $p);
1446 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1447 $self->ve_divert_add ("/sbin/init");
1448 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1450 # disable service activation
1451 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1452 $data = "#!/bin/sh\nexit 101\n";
1453 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1455 # disable start-stop-daemon
1456 $self->ve_divert_add ("/sbin/start-stop-daemon");
1460 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1462 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1465 $self->ve_divert_add ("/sbin/udevd");
1467 if ($suite eq 'etch') {
1468 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2"); # disable apache2 startup
1471 $self->logmsg ("configure required packages\n");
1472 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1474 # set postfix defaults
1475 if ($mta eq 'postfix') {
1476 $data = "postfix postfix/main_mailer_type select Local only\n";
1477 $self->ve_debconfig_set ($data);
1479 $data = "postmaster: root\nwebmaster: root\n";
1480 write_file
($data, "$rootdir/etc/aliases");
1483 if ($suite eq 'jaunty') {
1484 # jaunty does not create /var/run/network, so network startup fails.
1485 # so we do not use tmpfs for /var/run and /var/lock
1486 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1487 # and create the directory here
1488 $self->run_command ("mkdir $rootdir/var/run/network");
1491 # unpack base packages
1492 foreach my $p (@$important) {
1493 $self->ve_dpkg ('unpack', $p);
1497 if (-x
"$rootdir/sbin/ifconfig") {
1498 $self->ve_command ("ifconfig lo up");
1500 $self->ve_command ("ip link set lo up");
1503 $self->logmsg ("configure important packages\n");
1504 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1506 if (-d
"$rootdir/etc/event.d") {
1507 unlink <$rootdir/etc/event.d
/tty
*>;
1510 if (-f
"$rootdir/etc/inittab") {
1511 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1514 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1515 unlink "$rootdir/etc/mtab";
1516 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1519 $self->ve_command ("usermod -L root");
1521 if ($mta eq 'postfix') {
1522 $data = "postfix postfix/main_mailer_type select No configuration\n";
1523 $self->ve_debconfig_set ($data);
1525 unlink "$rootdir/etc/mailname";
1526 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1529 if (!$opts->{minimal
}) {
1530 # unpack standard packages
1531 foreach my $p (@$standard) {
1532 $self->ve_dpkg ('unpack', $p);
1535 $self->logmsg ("configure standard packages\n");
1536 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1539 # disable HWCLOCK access
1540 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1543 $self->ve_divert_add ("/usr/sbin/hald");
1545 # disable /dev/urandom init
1546 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1548 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1550 $self->ve_divert_add ("/sbin/klogd");
1553 # remove unnecessays sysctl entries to avoid warnings
1555 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1556 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1557 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1558 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1559 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1560 $self->run_command ($cmd);
1562 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1563 if (-f
$bindv6only) {
1565 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1566 $cmd .= " -i '$bindv6only'";
1567 $self->run_command ($cmd);
1570 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1571 # disable tty init (console-setup)
1573 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1574 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1575 $self->run_command ($cmd);
1578 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1579 # remove sysctl setup (avoid warnings at startup)
1580 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1581 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1582 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1583 $self->run_command ("rm $filelist");
1586 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1587 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1594 my $veid = $self->{veid
};
1595 my $conffile = $self->{veconffile
};
1597 my $vestat = $self->ve_status();
1599 if (!$vestat->{exist
}) {
1600 $self->logmsg ("Please create the appliance first (bootstrap)");
1604 if (!$vestat->{running
}) {
1605 $self->run_command ("lxc-start -n $veid -f $conffile");
1608 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1611 sub ve_mysql_command
{
1612 my ($self, $sql, $password) = @_;
1614 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1615 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1617 $self->ve_command("mysql", $sql);
1620 sub ve_mysql_bootstrap
{
1621 my ($self, $sql, $password) = @_;
1623 my $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --skip-bdb --skip-innodb --skip-ndbcluster";
1624 $self->ve_command($cmd, $sql);
1627 sub compute_required
{
1628 my ($self, $pkglist) = @_;
1630 my $pkginfo = $self->pkginfo();
1631 my $instpkgs = $self->read_installed ();
1634 __record_provides
($pkginfo, $closure, [keys $instpkgs->%*]);
1636 return $self->closure ($closure, $pkglist);
1640 my ($self, $opts) = @_;
1642 my @supp = ('7.4', '8.1');
1643 my $pgversion; # NOTE: not setting that defaults to the distro default, normally the best choice
1645 my $suite = $self->{config
}->{suite
};
1647 if ($suite eq 'buster') {
1650 } elsif ($suite eq 'bullseye') {
1652 } elsif ($suite eq 'bookworm') {
1655 $pgversion = $opts->{version
} if $opts->{version
};
1658 if (defined($pgversion)) {
1659 die "unsupported postgres version '$pgversion'\n" if !grep { $pgversion eq $_; } @supp;
1661 $required = $self->compute_required (["postgresql-$pgversion"]);
1663 $required = $self->compute_required (["postgresql"]);
1666 $self->cache_packages ($required);
1668 $self->ve_dpkg ('install', @$required);
1670 my $iscript = "postgresql-$pgversion";
1671 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1675 my ($self, $opts) = @_;
1677 my $password = $opts->{password
};
1678 my $rootdir = $self->{rootfs
};
1680 my $suite = $self->{config
}->{suite
};
1682 my $required = $self->compute_required(['mariadb-server']);
1684 $self->cache_packages($required);
1686 $self->ve_dpkg ('install', @$required);
1688 # fix security (see /usr/bin/mysql_secure_installation)
1689 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1690 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1691 "FLUSH PRIVILEGES;\n";
1692 $self->ve_mysql_bootstrap ($sql);
1696 my $rpw = $password eq 'random' ?
'admin' : $password;
1698 my $sql = "USE mysql;\n" .
1699 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1700 "FLUSH PRIVILEGES
;\n";
1701 $self->ve_mysql_bootstrap ($sql);
1703 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1704 if ($password eq 'random') {
1705 $self->install_init_script ($script_mysql_randompw, 2, 20);
1709 $self->ve_command("/etc/init.d/mysql start") if $opts->{start
}; # FIXME: use systemd service?!
1713 my ($self, $opts) = @_;
1715 my $memlimit = $opts->{memlimit
};
1716 my $rootdir = $self->{rootfs
};
1717 my $suite = $self->{config
}->{suite
};
1719 my $base_set = [qw(php-cli libapache2-mod-php php-gd)];
1720 my $required = $self->compute_required($base_set);
1722 $self->cache_packages ($required);
1724 $self->ve_dpkg ('install', @$required);
1727 my $sed_cmd = ['sed', '-e', "s/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/", '-i'];
1729 for my $fn (glob("'${rootdir}/etc/php/*/apache2/php.ini'")) {
1730 push @$sed_cmd, "$rootdir/$fn";
1734 warn "WARN: did not found any php.ini to set the memlimit!\n";
1737 $self->run_command($sed_cmd);
1742 my ($self, $pkglist, $unpack) = @_;
1744 my $required = $self->compute_required ($pkglist);
1746 $self->cache_packages ($required);
1748 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1752 my ($self, $distclean) = @_;
1754 unlink $self->{logfile
};
1755 unlink "$self->{targetname}.tar";
1756 unlink "$self->{targetname}.tar.gz";
1758 $self->ve_destroy ();
1761 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1763 rmtree
$self->{infodir
};