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 } elsif ($ostype =~ m/^ubuntu-/) {
315 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
317 die "unknown os type '$ostype'\n";
319 $data .= "lxc.uts.name = localhost\n";
320 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
329 if (my $fd = IO
::File-
>new (".veid")) {
336 $self->{working_dir
} = getcwd
;
337 $self->{veconffile
} = "$self->{working_dir}/config";
338 $self->{rootfs
} = "$self->{working_dir}/rootfs";
341 $self->{veid
} = $cid;
347 UUID
::generate
($uuid);
348 UUID
::unparse
($uuid, $uuid_str);
349 $self->{veid
} = $uuid_str;
351 my $fd = IO
::File-
>new (">.veid") ||
352 die "unable to write '.veid'\n";
353 print $fd "$self->{veid}\n";
356 my $cdata = $self->__sample_config();
358 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
359 die "unable to write lxc config file '$self->{veconffile}' - $!";
363 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
365 $self->logmsg ("allocated VE $self->{veid}\n");
367 return $self->{veid
};
370 # just use some simple heuristic for now, merge usr for releases newer than ubuntu 21.x or debian 11
374 my $ostype = $self->{config
}->{ostype
};
376 # FIXME: add configuration override posibillity
378 if ($ostype =~ m/^debian-(\d+)/) {
379 return int($1) >= 11;
380 } elsif ($ostype =~ m/^ubuntu-(\d+)/) {
381 return int($1) >= 21;
386 sub setup_usr_merge
{
389 my $rootfs = $self->{rootfs
};
390 my $arch = $self->{config
}->{architecture
};
392 # similar to https://salsa.debian.org/installer-team/debootstrap/-/blob/master/functions#L1354
393 my @merged_dirs = qw(bin sbin lib);
395 if ($arch eq 'amd64') {
396 push @merged_dirs, qw(lib32 lib64 libx32);
397 } elsif ($arch eq 'i386') {
398 push @merged_dirs, qw(lib64 libx32);
401 $self->logmsg ("setup usr-merge symlinks for '" . join("', '", @merged_dirs) . "'\n");
403 for my $dir (@merged_dirs) {
404 symlink("usr/$dir", "$rootfs/$dir") or warn "could not create symlink - $!\n";
405 mkpath
"$rootfs/usr/$dir";
409 sub get_target_name
{
412 my $name = $config->{name
} || die "no 'name' specified\n";
413 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ || die "illegal characters in name '$name'\n";
415 my ($version, $arch, $ostype) = $config->@{'version', 'architecture', 'ostype'};
416 $name = "${ostype}-${name}" if $name !~ m/^$ostype/;
418 return "${name}_${version}_${arch}"
422 my ($class, $config) = @_;
424 $class = ref ($class) || $class;
425 $config = read_config
('dab.conf') if !$config;
432 $self->{logfile
} = "logfile";
433 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") || die "unable to open log file";
435 my $arch = $config->{architecture
} || die "no 'architecture' specified\n";
436 die "unsupported architecture '$arch'\n" if $arch !~ m/^(i386|amd64)$/;
438 my $suite = $config->{suite
} || die "no 'suite' specified\n";
440 my $suiteinfo = get_suite_info
($suite);
441 $suite = $suiteinfo->{suite
};
442 $config->{ostype
} = $suiteinfo->{ostype
};
444 # assert required dab.conf keys exist
445 for my $key (qw(version section headline maintainer)) {
446 die "no '$key' specified\n" if !$config->{$key};
449 $self->{targetname
} = get_target_name
($config);
451 if (!$config->{source
}) {
452 if (lc($suiteinfo->{origin
}) eq 'debian') {
453 if ($suite eq 'etch' || $suite eq 'lenny') {
454 push @{$config->{source
}}, (
455 'http://ftp.debian.org/debian SUITE main contrib',
456 'http://security.debian.org SUITE/updates main contrib',
458 } elsif ($suite =~ /^(?:bullseye|bookworm|trixie|forky)$/) {
459 push @{$config->{source
}}, (
460 "http://deb.debian.org/debian SUITE main contrib",
461 "http://deb.debian.org/debian SUITE-updates main contrib",
462 "http://security.debian.org SUITE-security main contrib",
465 push @{$config->{source
}}, (
466 "http://ftp.debian.org/debian SUITE main contrib",
467 "http://ftp.debian.org/debian SUITE-updates main contrib",
468 "http://security.debian.org SUITE/updates main contrib",
471 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
472 my $comp = "main restricted universe multiverse";
473 push @{$config->{source
}}, (
474 "http://archive.ubuntu.com/ubuntu SUITE $comp",
475 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
476 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
485 foreach my $s (@{$config->{source
}}) {
486 if ($s =~ m
@^\s*((https?
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
487 my ($url, $su, $components) = ($1, $3, $4);
488 $su =~ s/SUITE/$suite/;
489 $components =~ s/^\s+//;
490 $components =~ s/\s+$//;
492 foreach my $co (split (/\s+/, $components)) {
495 $ca = ['main'] if !$ca;
503 die "syntax error in source spezification '$s'\n";
507 foreach my $m (@{$config->{mirror
}}) {
508 if ($m =~ m
@^\s*((https?
|ftp
)://\S
+)\s
*=>\s
*((https?
|ftp
)://\S
+)\s
*$@) {
509 my ($ms, $md) = ($1, $3);
511 foreach my $ss (@$sources) {
512 if ($ss->{source
} eq $ms) {
518 die "unusable mirror $ms\n" if !$found;
520 die "syntax error in mirror spezification '$m'\n";
523 $self->{sources
} = $sources;
524 $self->{infodir
} = "info";
526 $self->__allocate_ve();
528 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
530 my $incl = [qw
(less ssh openssh-server logrotate
)];
531 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe pppoeconf nfs-common mtools ntp
)];
533 # ubuntu has too many dependencies on udev, so we cannot exclude it (instead we disable udevd)
534 if (lc($suiteinfo->{origin
}) eq 'ubuntu' && $suiteinfo->{flags
}->{systemd
}) {
535 push @$incl, 'isc-dhcp-client';
536 push @$excl, qw(libmodule-build-perl libdrm-common libdrm2 libplymouth5 plymouth plymouth-theme-ubuntu-text powermgmt-base);
537 if ($suite eq 'jammy') {
538 push @$excl, qw(fuse); # avoid fuse2 <-> fuse3 conflict
540 } elsif ($suite eq 'buster' || $suite eq 'bullseye' || $suite eq 'bookworm') {
541 push @$excl, qw(module-init-tools pciutils hdparm memtest86+ parted);
543 push @$excl, qw(udev module-init-tools pciutils hdparm memtest86+ parted);
546 $self->{incl
} = $incl;
547 $self->{excl
} = $excl;
555 my $infodir = $self->{infodir
};
556 my $arch = $self->{config
}->{architecture
};
562 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
563 die "unable to open log file";
576 foreach my $ss (@{$self->{sources
}}) {
577 my $src = $ss->{mirror
} || $ss->{source
};
578 my $path = "dists/$ss->{suite}/Release";
579 my $url = "$src/$path";
580 my $target = __url_to_filename
("$ss->{source}/$path");
582 $self->download ($url, "$infodir/$target");
583 $self->download ("$url.gpg", "$infodir/$target.gpg");
584 # fixme: impl. verify (needs --keyring option)
588 warn "Release info ignored\n";
591 foreach my $comp (@{$ss->{comp
}}) {
592 foreach my $compressor (@$COMPRESSORS) {
593 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
594 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
595 my $pkgsrc = "$src/$path";
597 $self->download ($pkgsrc, $target);
598 $self->run_command ("$compressor->{decomp} '$target'");
601 print $logfd "could not download Packages.$compressor->{ext}\n";
611 my ($self, $filename, $size) = @_;
613 my $config = $self->{config
};
617 $data .= "Name: $config->{name}\n";
618 $data .= "Version: $config->{version}\n";
619 $data .= "Type: lxc\n";
620 $data .= "OS: $config->{ostype}\n";
621 $data .= "Section: $config->{section}\n";
622 $data .= "Maintainer: $config->{maintainer}\n";
623 $data .= "Architecture: $config->{architecture}\n";
624 $data .= "Installed-Size: $size\n";
627 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
628 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
629 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
632 $data .= "Description: $config->{headline}\n";
633 $data .= "$config->{description}\n" if $config->{description
};
635 write_file
($data, $filename, 0644);
639 my ($self, $opts) = @_;
641 my $suite = $self->{config
}->{suite
};
642 my $infodir = $self->{infodir
};
643 my $arch = $self->{config
}->{architecture
};
645 my $instpkgs = $self->read_installed ();
646 my $pkginfo = $self->pkginfo();
647 my $veid = $self->{veid
};
648 my $conffile = $self->{veconffile
};
649 my $rootdir = $self->{rootfs
};
651 my $vestat = $self->ve_status();
652 die "ve not running - unable to finalize\n" if !$vestat->{running
};
655 if (-f
"$rootdir/etc/init.d/mysql") {
656 $self->ve_command ("/etc/init.d/mysql stop");
659 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
660 unlink "$rootdir/root/.my.cnf";
663 if ($suite eq 'etch') {
664 # enable apache2 startup
665 if ($instpkgs->{apache2
}) {
666 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
668 unlink "$rootdir/etc/default/apache2";
671 $self->logmsg ("cleanup package status\n");
672 # prevent auto selection of all standard, required or important
673 # packages which are not installed
674 foreach my $pkg (keys %$pkginfo) {
675 my $pri = $pkginfo->{$pkg}->{priority
};
676 if ($pri && ($pri eq 'required' || $pri eq 'important'
677 || $pri eq 'standard')) {
678 if (!$instpkgs->{$pkg}) {
679 $self->ve_dpkg_set_selection ($pkg, 'purge');
684 $self->ve_command ("apt-get clean");
686 $self->logmsg ("update available package list\n");
688 $self->ve_command ("dpkg --clear-avail");
689 foreach my $ss (@{$self->{sources
}}) {
690 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
691 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
692 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
693 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
695 foreach my $comp (@{$ss->{comp
}}) {
696 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
697 "$comp/binary-$arch/Packages");
698 my $target = "/var/lib/apt/lists/$src";
699 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
700 $self->ve_command ("dpkg --merge-avail '$target'");
704 # set dselect default method
705 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
707 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
709 $self->ve_divert_remove ("/sbin/start-stop-daemon");
711 $self->ve_divert_remove ("/sbin/init");
713 # finally stop the VE
714 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
716 unlink "$rootdir/sbin/defenv";
717 unlink <$rootdir/root/dead.letter
*>;
718 unlink "$rootdir/var/log/init.log";
719 unlink "$rootdir/aquota.group", "$rootdir/aquota.user";
721 write_file
("", "$rootdir/var/log/syslog");
723 my $get_path_size = sub {
725 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
726 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
729 die "unable to detect size for '$path'\n";
733 $self->logmsg ("detecting final appliance size: ");
734 my $size = $get_path_size->($rootdir);
735 $self->logmsg ("$size MB\n");
737 $self->write_config ("$rootdir/etc/appliance.info", $size);
739 $self->logmsg ("creating final appliance archive\n");
741 my $target = "$self->{targetname}.tar";
743 my $compressor = $opts->{compressor
} // 'gz';
744 my $compressor2cmd_map = {
747 zst
=> 'zstd --rm -9',
748 zstd
=> 'zstd --rm -9',
749 'zstd-max' => 'zstd --rm -19 -T0', # maximal level where the decompressor can still run efficiently
751 my $compressor2ending = {
756 my $compressor_cmd = $compressor2cmd_map->{$compressor};
757 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
758 if !defined($compressor_cmd);
760 my $ending = $compressor2ending->{$compressor} // $compressor;
761 my $final_archive = "${target}.${ending}";
763 unlink $final_archive;
765 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
766 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
767 $self->run_command ("$compressor_cmd $target");
769 $self->logmsg ("detecting final commpressed appliance size: ");
770 $size = $get_path_size->($final_archive);
771 $self->logmsg ("$size MB\n");
773 $self->logmsg ("appliance archive: $final_archive\n");
779 my $rootdir = $self->{rootfs
};
781 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
783 open(my $PKGLST, '<', $pkgfilelist) or die "unable to open '$pkgfilelist' - $!";
787 while (my $rec = <$PKGLST>) {
793 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
797 my $pkg = $res->{'package'};
798 if (my $status = $res->{status
}) {
799 my @sa = split (/\s+/, $status);
801 if ($stat && ($stat ne 'purge')) {
802 $pkglist->{$pkg} = $res;
815 my $veid = $self->{veid
};
817 my $res = { running
=> 0 };
819 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
821 my $filename = "/proc/net/unix";
823 # similar test is used by lcxcontainers.c: list_active_containers
824 my $fh = IO
::File-
>new ($filename, "r");
827 while (defined(my $line = <$fh>)) {
828 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
830 if ($path =~ m!^@/\S+/$veid/command$!) {
841 my ($self, $cmd, $input) = @_;
843 my $veid = $self->{veid
};
844 my $conffile = $self->{veconffile
};
846 if (ref ($cmd) eq 'ARRAY') {
847 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
848 $self->run_command($cmd, $input);
850 $self->run_command("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
854 # like ve_command, but pipes stdin correctly
856 my ($self, @cmd) = @_;
858 my $veid = $self->{veid
};
859 my $conffile = $self->{veconffile
};
862 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
863 'defenv', @cmd) || die "unable to exec command";
865 while (defined (my $line = <$reader>)) {
866 $self->logmsg ($line);
872 die "ve_exec failed - status $rc\n" if $rc != 0;
876 my ($self, $filename) = @_;
878 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
879 "--rename '$filename'");
881 sub ve_divert_remove
{
882 my ($self, $filename) = @_;
884 my $rootdir = $self->{rootfs
};
886 unlink "$rootdir/$filename";
887 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
890 sub ve_debconfig_set
{
891 my ($self, $dcdata) = @_;
893 my $rootdir = $self->{rootfs
};
894 my $cfgfile = "/tmp/debconf.txt";
895 write_file
($dcdata, "$rootdir/$cfgfile");
896 $self->ve_command ("debconf-set-selections $cfgfile");
897 unlink "$rootdir/$cfgfile";
900 sub ve_dpkg_set_selection
{
901 my ($self, $pkg, $status) = @_;
903 $self->ve_command ("dpkg --set-selections", "$pkg $status");
907 my ($self, $cmd, @pkglist) = @_;
909 return if !scalar (@pkglist);
911 my $pkginfo = $self->pkginfo();
913 my $rootdir = $self->{rootfs
};
914 my $cachedir = $self->{cachedir
};
918 foreach my $pkg (@pkglist) {
919 my $filename = $self->getpkgfile ($pkg);
920 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
921 push @files, "/$filename";
922 $self->logmsg ("$cmd: $pkg\n");
925 my $fl = join (' ', @files);
927 if ($cmd eq 'install') {
928 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
929 } elsif ($cmd eq 'unpack') {
930 $self->ve_command ("dpkg --force-depends --unpack $fl");
932 die "internal error";
935 foreach my $fn (@files) { unlink "$rootdir$fn"; }
941 my $veid = $self->{veid
}; # fixme
942 my $conffile = $self->{veconffile
};
944 my $vestat = $self->ve_status();
945 if ($vestat->{running
}) {
946 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
949 rmtree
$self->{rootfs
};
950 unlink $self->{veconffile
};
956 my $veid = $self->{veid
};
957 my $conffile = $self->{veconffile
};
959 $self->logmsg ("initialize VE $veid\n");
961 my $vestat = $self->ve_status();
962 if ($vestat->{running
}) {
963 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
966 rmtree
$self->{rootfs
};
967 mkpath
$self->{rootfs
};
970 sub __deb_version_cmp
{
971 my ($cur, $op, $new) = @_;
973 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
980 sub __parse_packages
{
981 my ($pkginfo, $filename, $src) = @_;
984 open(my $PKGLST, '<', $filename) or die "unable to open '$filename' - $!";
986 while (my $rec = <$PKGLST>) {
993 while ($rec =~ s/^([^:]+):\s+(.*?)\s*\n//) {
997 my $pkg = $res->{'package'};
998 if ($pkg && $res->{'filename'}) {
1000 if (my $info = $pkginfo->{$pkg}) {
1001 $cur = $info->{version
};
1003 my $new = $res->{version
};
1004 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1006 $res->{url
} = "$src/$res->{'filename'}";
1008 die "no url for package '$pkg'" if !$res->{url
};
1010 $pkginfo->{$pkg} = $res;
1021 return $self->{pkginfo
} if $self->{pkginfo
};
1023 my $infodir = $self->{infodir
};
1024 my $arch = $self->{config
}->{architecture
};
1026 my $availfn = "$infodir/available";
1031 # reading 'available' is faster, because it only contains latest version
1032 # (no need to do slow version compares)
1034 __parse_packages
($pkginfo, $availfn);
1035 $self->{pkginfo
} = $pkginfo;
1039 $self->logmsg ("generating available package list\n");
1041 foreach my $ss (@{$self->{sources
}}) {
1042 foreach my $comp (@{$ss->{comp
}}) {
1043 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1044 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1046 my $src = $ss->{mirror
} || $ss->{source
};
1048 __parse_packages
($pkginfo, $pkgfilelist, $src);
1052 if (my $dep = $self->{config
}->{depends
}) {
1053 foreach my $d (split (/,/, $dep)) {
1054 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1055 my ($pkg, $op, $rver) = ($1, $3, $4);
1056 $self->logmsg ("checking dependencies: $d\n");
1057 my $info = $pkginfo->{$pkg};
1058 die "package '$pkg' not available\n" if !$info;
1060 my $cver = $info->{version
};
1061 if (!__deb_version_cmp
($cver, $op, $rver)) {
1062 die "detected wrong version '$cver'\n";
1066 die "syntax error in depends field";
1071 $self->{pkginfo
} = $pkginfo;
1073 my $tmpfn = "$availfn.tmp$$";
1074 my $fd = IO
::File-
>new (">$tmpfn");
1075 foreach my $pkg (sort keys %$pkginfo) {
1076 my $info = $pkginfo->{$pkg};
1077 print $fd "package: $pkg\n";
1078 foreach my $k (sort keys %$info) {
1079 next if $k eq 'description';
1080 next if $k eq 'package';
1081 my $v = $info->{$k};
1082 print $fd "$k: $v\n" if $v;
1084 print $fd "description: $info->{description}\n" if $info->{description
};
1089 rename ($tmpfn, $availfn);
1094 sub __record_provides
{
1095 my ($pkginfo, $closure, $list, $skipself) = @_;
1097 foreach my $pname (@$list) {
1098 my $info = $pkginfo->{$pname};
1099 # fixme: if someone install packages directly using dpkg, there
1100 # is no entry in 'available', only in 'status'. In that case, we
1101 # should extract info from $instpkgs
1103 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1106 if (my $prov = $info->{provides
}) {
1107 my @pl = split (',', $prov);
1108 foreach my $p (@pl) {
1110 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1115 $closure->{$pname} = 1 if !$skipself;
1120 my ($self, $closure, $list) = @_;
1122 my $pkginfo = $self->pkginfo();
1124 # first, record provided packages
1125 __record_provides
($pkginfo, $closure, $list, 1);
1130 # then resolve dependencies
1131 foreach my $pname (@$list) {
1132 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1138 sub __closure_single
{
1139 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1143 $pname =~ s/:any$//;
1145 return if $closure->{$pname};
1147 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1149 my $dep = $info->{depends
};
1150 my $predep = $info->{'pre-depends'};
1152 my $size = $info->{size
};
1153 my $url = $info->{url
};
1155 $url || die "$pname: no url for package '$pname'";
1157 if (!$pkghash->{$pname}) {
1158 unshift @$pkglist, $pname;
1159 $pkghash->{$pname} = 1;
1162 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1164 $closure->{$pname} = 1;
1170 push @l, split (/,/, $predep) if $predep;
1171 push @l, split (/,/, $dep) if $dep;
1173 DEPEND
: foreach my $p (@l) {
1174 my @l1 = split (/\|/, $p);
1175 foreach my $p1 (@l1) {
1176 if ($p1 =~ m/^\s*(\S+).*/) {
1177 #printf (STDERR "$pname: $p --> $1\n");
1178 if ($closure->{$1}) {
1179 next DEPEND
; # dependency already met
1183 # search for non-excluded alternative
1185 foreach my $p1 (@l1) {
1186 if ($p1 =~ m/^\s*(\S+).*/) {
1187 next if grep { $1 eq $_ } @$excl;
1192 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1194 #printf (STDERR "$pname: $p --> $found\n");
1196 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1200 sub cache_packages
{
1201 my ($self, $pkglist) = @_;
1203 foreach my $pkg (@$pkglist) {
1204 $self->getpkgfile ($pkg);
1209 my ($self, $pkg) = @_;
1211 my $pkginfo = $self->pkginfo();
1212 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1213 my $cachedir = $self->{cachedir
};
1215 my $url = $info->{url
};
1218 if ($url =~ m
|/([^/]+.deb
)$|) {
1221 die "internal error";
1224 return $filename if -f
"$cachedir/$filename";
1228 $self->download ($url, "$cachedir/$filename");
1233 sub install_init_script
{
1234 my ($self, $script, $runlevel, $prio) = @_;
1236 my $suite = $self->{config
}->{suite
};
1237 my $suiteinfo = get_suite_info
($suite);
1238 my $rootdir = $self->{rootfs
};
1240 my $base = basename
($script);
1241 my $target = "$rootdir/etc/init.d/$base";
1243 $self->run_command ("install -m 0755 '$script' '$target'");
1244 if ($suite eq 'etch' || $suite eq 'lenny') {
1245 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1246 } elsif ($suiteinfo->{flags
}->{systemd
}) {
1247 die "unable to install init script (system uses systemd)\n";
1248 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1249 die "unable to install init script (system uses upstart)\n";
1251 $self->ve_command ("insserv $base");
1258 my ($self, $opts) = @_;
1260 my $pkginfo = $self->pkginfo();
1261 my $veid = $self->{veid
};
1262 my $suite = $self->{config
}->{suite
};
1263 my $suiteinfo = get_suite_info
($suite);
1265 my $important = [ @{$self->{incl
}} ];
1269 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1270 if ($mta eq 'postfix') {
1271 push @$important, "postfix";
1274 if ($opts->{include
}) {
1275 push @$important, split(',', $opts->{include
});
1279 if ($opts->{exclude
}) {
1280 $exclude->{$_} = 1 for split(',', $opts->{exclude
});
1283 foreach my $p (sort keys %$pkginfo) {
1284 next if grep { $p eq $_ } @{$self->{excl
}};
1285 my $pri = $pkginfo->{$p}->{priority
};
1287 next if $mta ne 'exim' && $p =~ m/exim/;
1288 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1290 push @$required, $p if $pri eq 'required';
1291 next if $exclude->{$p};
1292 push @$important, $p if $pri eq 'important';
1293 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1297 $required = $self->closure($closure, $required);
1298 $important = $self->closure($closure, $important);
1300 if (!$opts->{minimal
}) {
1301 $standard = $self->closure($closure, $standard);
1304 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1305 # except those explicitly excluded
1306 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1307 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1308 foreach my $d (split (/,/, $mdeps)) {
1309 if ($d =~ m/^\s*(\S+)$/) {
1311 next if $closure->{$pkg};
1312 next if grep { $pkg eq $_ } @{$self->{excl
}};
1313 die "missing ubuntu-minimal package '$pkg'\n";
1316 if (!$opts->{minimal
}) {
1317 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1318 foreach my $d (split (/,/, $mdeps)) {
1319 if ($d =~ m/^\s*(\S+)$/) {
1321 next if $closure->{$pkg};
1322 next if grep { $pkg eq $_ } @{$self->{excl
}};
1323 die "missing ubuntu-standard package '$pkg'\n";
1329 # download/cache all files first
1330 $self->cache_packages ($required);
1331 $self->cache_packages ($important);
1332 $self->cache_packages ($standard);
1334 my $rootdir = $self->{rootfs
};
1336 # extract required packages first
1337 $self->logmsg ("create basic environment\n");
1339 if ($self->can_usr_merge()) {
1340 $self->setup_usr_merge();
1343 my $compressor2opt = {
1348 my $compressor_re = join('|', keys $compressor2opt->%*);
1350 $self->logmsg ("extract required packages to rootfs\n");
1351 foreach my $p (@$required) {
1352 my $filename = $self->getpkgfile ($p);
1353 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1354 if ($content =~ m/^(data.tar.($compressor_re))$/m) {
1356 my $tar_opts = "--keep-directory-symlink $compressor2opt->{$2}";
1358 $self->run_command("ar -p '$self->{cachedir}/$filename' '$archive' | tar -C '$rootdir' -xf - $tar_opts");
1360 die "unexpected error for $p: no data.tar.{xz,gz,zst} found...";
1365 my $data = "Package: dpkg\n" .
1366 "Version: $pkginfo->{dpkg}->{version}\n" .
1367 "Status: install ok installed\n";
1369 write_file
($data, "$rootdir/var/lib/dpkg/status");
1370 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1371 write_file
("", "$rootdir/var/lib/dpkg/available");
1374 foreach my $ss (@{$self->{sources
}}) {
1375 my $url = $ss->{source
};
1376 my $comp = join (' ', @{$ss->{comp
}});
1377 $data .= "deb $url $ss->{suite} $comp\n\n";
1380 write_file
($data, "$rootdir/etc/apt/sources.list");
1382 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1383 write_file
($data, "$rootdir/etc/fstab", 0644);
1385 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1387 # avoid warnings about non-existent resolv.conf
1388 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1390 if (lc($suiteinfo->{origin
}) eq 'ubuntu' && $suiteinfo->{flags
}->{systemd
}) {
1391 # no need to configure loopback device
1392 # FIXME: Debian (systemd based?) too?
1394 $data = "auto lo\niface lo inet loopback\n";
1395 mkdir "$rootdir/etc/network";
1396 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1400 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'") if $opts->{'device-skelleton'};
1402 # avoid warnings about missing default locale
1403 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1406 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1407 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1409 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1411 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1413 $self->logmsg ("initialize ld cache\n");
1414 $self->ve_command ("/sbin/ldconfig");
1415 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1417 $self->logmsg ("installing packages\n");
1419 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1421 $self->ve_dpkg ('install', 'dpkg');
1423 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1425 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1427 $self->ve_dpkg ('install', 'libc6');
1428 $self->ve_dpkg ('install', 'perl-base');
1430 unlink "$rootdir/usr/bin/awk";
1432 $self->ve_dpkg ('install', 'mawk');
1433 $self->ve_dpkg ('install', 'debconf');
1435 # unpack required packages
1436 foreach my $p (@$required) {
1437 $self->ve_dpkg ('unpack', $p);
1440 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1441 $self->ve_divert_add ("/sbin/init");
1442 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1444 # disable service activation
1445 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1446 $data = "#!/bin/sh\nexit 101\n";
1447 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1449 # disable start-stop-daemon
1450 $self->ve_divert_add ("/sbin/start-stop-daemon");
1454 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1456 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1459 $self->ve_divert_add ("/sbin/udevd");
1461 if ($suite eq 'etch') {
1462 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2"); # disable apache2 startup
1465 $self->logmsg ("configure required packages\n");
1466 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1468 # set postfix defaults
1469 if ($mta eq 'postfix') {
1470 $data = "postfix postfix/main_mailer_type select Local only\n";
1471 $self->ve_debconfig_set ($data);
1473 $data = "postmaster: root\nwebmaster: root\n";
1474 write_file
($data, "$rootdir/etc/aliases");
1477 if ($suite eq 'jaunty') {
1478 # jaunty does not create /var/run/network, so network startup fails.
1479 # so we do not use tmpfs for /var/run and /var/lock
1480 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1481 # and create the directory here
1482 $self->run_command ("mkdir $rootdir/var/run/network");
1485 # unpack base packages
1486 foreach my $p (@$important) {
1487 $self->ve_dpkg ('unpack', $p);
1491 if (-x
"$rootdir/sbin/ifconfig") {
1492 $self->ve_command ("ifconfig lo up");
1494 $self->ve_command ("ip link set lo up");
1497 $self->logmsg ("configure important packages\n");
1498 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1500 if (-d
"$rootdir/etc/event.d") {
1501 unlink <$rootdir/etc/event.d
/tty
*>;
1504 if (-f
"$rootdir/etc/inittab") {
1505 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1508 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1509 unlink "$rootdir/etc/mtab";
1510 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1513 $self->ve_command ("usermod -L root");
1515 if ($mta eq 'postfix') {
1516 $data = "postfix postfix/main_mailer_type select No configuration\n";
1517 $self->ve_debconfig_set ($data);
1519 unlink "$rootdir/etc/mailname";
1520 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1523 if (!$opts->{minimal
}) {
1524 # unpack standard packages
1525 foreach my $p (@$standard) {
1526 $self->ve_dpkg ('unpack', $p);
1529 $self->logmsg ("configure standard packages\n");
1530 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1533 # disable HWCLOCK access
1534 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1537 $self->ve_divert_add ("/usr/sbin/hald");
1539 # disable /dev/urandom init
1540 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1542 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1544 $self->ve_divert_add ("/sbin/klogd");
1547 # remove unnecessays sysctl entries to avoid warnings
1549 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1550 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1551 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1552 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1553 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1554 $self->run_command ($cmd);
1556 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1557 if (-f
$bindv6only) {
1559 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1560 $cmd .= " -i '$bindv6only'";
1561 $self->run_command ($cmd);
1564 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1565 # disable tty init (console-setup)
1567 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1568 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1569 $self->run_command ($cmd);
1572 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1573 # remove sysctl setup (avoid warnings at startup)
1574 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1575 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1576 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1577 $self->run_command ("rm $filelist");
1580 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1581 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1588 my $veid = $self->{veid
};
1589 my $conffile = $self->{veconffile
};
1591 my $vestat = $self->ve_status();
1593 if (!$vestat->{exist
}) {
1594 $self->logmsg ("Please create the appliance first (bootstrap)");
1598 if (!$vestat->{running
}) {
1599 $self->run_command ("lxc-start -n $veid -f $conffile");
1602 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1605 sub ve_mysql_command
{
1606 my ($self, $sql, $password) = @_;
1608 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1609 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1611 $self->ve_command("mysql", $sql);
1614 sub ve_mysql_bootstrap
{
1615 my ($self, $sql, $password) = @_;
1617 my $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables --skip-bdb --skip-innodb --skip-ndbcluster";
1618 $self->ve_command($cmd, $sql);
1621 sub compute_required
{
1622 my ($self, $pkglist) = @_;
1624 my $pkginfo = $self->pkginfo();
1625 my $instpkgs = $self->read_installed ();
1628 __record_provides
($pkginfo, $closure, [keys $instpkgs->%*]);
1630 return $self->closure ($closure, $pkglist);
1634 my ($self, $opts) = @_;
1636 my @supp = ('7.4', '8.1');
1637 my $pgversion; # NOTE: not setting that defaults to the distro default, normally the best choice
1639 my $suite = $self->{config
}->{suite
};
1641 if ($suite eq 'buster') {
1644 } elsif ($suite eq 'bullseye') {
1646 } elsif ($suite eq 'bookworm') {
1649 $pgversion = $opts->{version
} if $opts->{version
};
1652 if (defined($pgversion)) {
1653 die "unsupported postgres version '$pgversion'\n" if !grep { $pgversion eq $_; } @supp;
1655 $required = $self->compute_required (["postgresql-$pgversion"]);
1657 $required = $self->compute_required (["postgresql"]);
1660 $self->cache_packages ($required);
1662 $self->ve_dpkg ('install', @$required);
1664 my $iscript = "postgresql-$pgversion";
1665 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1669 my ($self, $opts) = @_;
1671 my $password = $opts->{password
};
1672 my $rootdir = $self->{rootfs
};
1674 my $suite = $self->{config
}->{suite
};
1676 my $required = $self->compute_required(['mariadb-server']);
1678 $self->cache_packages($required);
1680 $self->ve_dpkg ('install', @$required);
1682 # fix security (see /usr/bin/mysql_secure_installation)
1683 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1684 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1685 "FLUSH PRIVILEGES;\n";
1686 $self->ve_mysql_bootstrap ($sql);
1690 my $rpw = $password eq 'random' ?
'admin' : $password;
1692 my $sql = "USE mysql;\n" .
1693 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1694 "FLUSH PRIVILEGES
;\n";
1695 $self->ve_mysql_bootstrap ($sql);
1697 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1698 if ($password eq 'random') {
1699 $self->install_init_script ($script_mysql_randompw, 2, 20);
1703 $self->ve_command("/etc/init.d/mysql start") if $opts->{start
}; # FIXME: use systemd service?!
1707 my ($self, $opts) = @_;
1709 my $memlimit = $opts->{memlimit
};
1710 my $rootdir = $self->{rootfs
};
1711 my $suite = $self->{config
}->{suite
};
1713 my $base_set = [qw(php-cli libapache2-mod-php php-gd)];
1714 my $required = $self->compute_required($base_set);
1716 $self->cache_packages ($required);
1718 $self->ve_dpkg ('install', @$required);
1721 my $sed_cmd = ['sed', '-e', "s/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/", '-i'];
1723 for my $fn (glob("'${rootdir}/etc/php/*/apache2/php.ini'")) {
1724 push @$sed_cmd, "$rootdir/$fn";
1728 warn "WARN: did not found any php.ini to set the memlimit!\n";
1731 $self->run_command($sed_cmd);
1736 my ($self, $pkglist, $unpack) = @_;
1738 my $required = $self->compute_required ($pkglist);
1740 $self->cache_packages ($required);
1742 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1746 my ($self, $distclean) = @_;
1748 unlink $self->{logfile
};
1749 unlink "$self->{targetname}.tar";
1750 unlink "$self->{targetname}.tar.gz";
1752 $self->ve_destroy ();
1755 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1757 rmtree
$self->{infodir
};