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 = +
47 # produce apt compatible filenames (/var/lib/apt/lists)
48 sub __url_to_filename
{
59 my ($self, $url, $path) = @_;
61 $self->logmsg ("download: $url\n");
62 my $tmpfn = "$path.tmp$$";
64 $self->run_command ("wget -q '$url' -O '$tmpfn'");
73 rename ($tmpfn, $path);
77 my ($data, $file, $perm) = @_;
79 die "no filename" if !$file;
83 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
84 die "unable to open file '$file'";
94 die "no filename" if !$file;
96 my $fh = IO
::File-
>new ($file) ||
97 die "unable to open file '$file'";
99 local $/; # slurp mode
113 my $fh = IO
::File-
>new ("<$filename") || return $res;
116 while (defined (my $line = <$fh>)) {
117 next if $line =~ m/^\#/;
118 next if $line =~ m/^\s*$/;
128 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
129 $res->{headline
} = $1;
130 chomp $res->{headline
};
133 $res->{description
} = $long;
134 chomp $res->{description
};
135 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
136 my ($key, $value) = (lc ($1), $2);
137 if ($key eq 'source' || $key eq 'mirror') {
138 push @{$res->{$key}}, $value;
140 die "duplicate key '$key'\n" if defined ($res->{$key});
141 $res->{$key} = $value;
144 die "unable to parse config file: $rec";
148 die "unable to parse config file" if $rec;
154 my ($self, $cmd, $input, $getoutput) = @_;
156 my $reader = IO
::File-
>new();
157 my $writer = IO
::File-
>new();
158 my $error = IO
::File-
>new();
162 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
166 if (ref ($cmd) eq 'ARRAY') {
167 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
169 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
176 if ($orig_pid != $$) {
177 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
184 print $writer $input if defined $input;
187 my $select = new IO
::Select
;
188 $select->add ($reader);
189 $select->add ($error);
192 my $logfd = $self->{logfd
};
194 while ($select->count) {
195 my @handles = $select->can_read ();
197 foreach my $h (@handles) {
199 my $count = sysread ($h, $buf, 4096);
200 if (!defined ($count)) {
202 die "command '$cmdstr' failed: $!";
204 $select->remove ($h) if !$count;
208 $res .= $buf if $getoutput;
215 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
223 $self->writelog (@_);
228 my $fd = $self->{logfd
};
232 sub __sample_config
{
236 my $arch = $self->{config
}->{architecture
};
238 my $ostype = $self->{config
}->{ostype
};
240 if ($ostype =~ m/^de(bi|vu)an-/) {
241 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
242 } elsif ($ostype =~ m/^ubuntu-/) {
243 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
245 die "unknown os type '$ostype'\n";
247 $data .= "lxc.uts.name = localhost\n";
248 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
257 if (my $fd = IO
::File-
>new (".veid")) {
264 $self->{working_dir
} = getcwd
;
265 $self->{veconffile
} = "$self->{working_dir}/config";
266 $self->{rootfs
} = "$self->{working_dir}/rootfs";
269 $self->{veid
} = $cid;
275 UUID
::generate
($uuid);
276 UUID
::unparse
($uuid, $uuid_str);
277 $self->{veid
} = $uuid_str;
279 my $fd = IO
::File-
>new (">.veid") ||
280 die "unable to write '.veid'\n";
281 print $fd "$self->{veid}\n";
284 my $cdata = $self->__sample_config();
286 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
287 die "unable to write lxc config file '$self->{veconffile}' - $!";
291 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
293 $self->logmsg ("allocated VE $self->{veid}\n");
295 return $self->{veid
};
299 my ($class, $config) = @_;
301 $class = ref ($class) || $class;
305 $config = read_config
('dab.conf') if !$config;
307 $self->{config
} = $config;
311 $self->{logfile
} = "logfile";
312 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
313 die "unable to open log file";
315 my $arch = $config->{architecture
};
316 die "no 'architecture' specified\n" if !$arch;
318 die "unsupported architecture '$arch'\n"
319 if $arch !~ m/^(i386|amd64)$/;
321 my $suite = $config->{suite
} || die "no 'suite' specified\n";
322 if ($suite eq 'buster') {
323 $config->{ostype
} = "debian-10.0";
324 } elsif ($suite eq 'stretch') {
325 $config->{ostype
} = "debian-9.0";
326 } elsif ($suite eq 'jessie') {
327 $config->{ostype
} = "debian-8.0";
328 } elsif ($suite eq 'wheezy') {
329 $config->{ostype
} = "debian-7.0";
330 } elsif ($suite eq 'squeeze') {
331 $config->{ostype
} = "debian-6.0";
332 } elsif ($suite eq 'lenny') {
333 $config->{ostype
} = "debian-5.0";
334 } elsif ($suite eq 'etch') {
335 $config->{ostype
} = "debian-4.0";
336 } elsif ($suite eq 'devuan-jessie') {
338 $config->{ostype
} = "devuan-1.0";
339 } elsif ($suite eq 'devuan-ascii' || $suite eq 'ascii') {
341 $config->{ostype
} = "devuan-2.0";
342 } elsif ($suite eq 'hardy') {
343 $config->{ostype
} = "ubuntu-8.04";
344 } elsif ($suite eq 'intrepid') {
345 $config->{ostype
} = "ubuntu-8.10";
346 } elsif ($suite eq 'jaunty') {
347 $config->{ostype
} = "ubuntu-9.04";
348 } elsif ($suite eq 'precise') {
349 $config->{ostype
} = "ubuntu-12.04";
350 } elsif ($suite eq 'trusty') {
351 $config->{ostype
} = "ubuntu-14.04";
352 } elsif ($suite eq 'vivid') {
353 $config->{ostype
} = "ubuntu-15.04";
354 } elsif ($suite eq 'wily') {
355 $config->{ostype
} = "ubuntu-15.10";
356 } elsif ($suite eq 'xenial') {
357 $config->{ostype
} = "ubuntu-16.04";
358 } elsif ($suite eq 'yakkety') {
359 $config->{ostype
} = "ubuntu-16.10";
360 } elsif ($suite eq 'zesty') {
361 $config->{ostype
} = "ubuntu-17.04";
362 } elsif ($suite eq 'artful') {
363 $config->{ostype
} = "ubuntu-17.10";
364 } elsif ($suite eq 'bionic') {
365 $config->{ostype
} = "ubuntu-18.04";
366 } elsif ($suite eq 'cosmic') {
367 $config->{ostype
} = "ubuntu-18.10";
369 die "unsupported debian suite '$suite'\n";
372 my $name = $config->{name
} || die "no 'name' specified\n";
374 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
375 die "illegal characters in name '$name'\n";
377 my $version = $config->{version
};
378 die "no 'version' specified\n" if !$version;
379 die "no 'section' specified\n" if !$config->{section
};
380 die "no 'description' specified\n" if !$config->{headline
};
381 die "no 'maintainer' specified\n" if !$config->{maintainer
};
383 if ($name =~ m/^$config->{ostype}/) {
384 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
386 $self->{targetname
} = "$config->{ostype}-${name}_" .
387 "${version}_$config->{architecture}";
390 if (!$config->{source
}) {
391 if ($suite eq 'etch' || $suite eq 'lenny') {
392 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE main contrib";
393 push @{$config->{source
}}, "http://security.debian.org SUITE/updates main contrib";
394 } elsif ($suite eq 'squeeze' || $suite eq 'stretch' ||
395 $suite eq 'jessie' || $suite eq 'buster' ) {
396 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE main contrib";
397 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE-updates main contrib";
398 push @{$config->{source
}}, "http://security.debian.org SUITE/updates main contrib";
399 } elsif ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty' ||
400 $suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
401 $suite eq 'trusty' || $suite eq 'precise' || $suite eq 'yakkety' ||
402 $suite eq 'zesty' || $suite eq 'artful' || $suite eq 'bionic' ||
403 $suite eq 'cosmic') {
404 my $comp = "main restricted universe multiverse";
405 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE $comp";
406 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE-updates $comp";
407 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE-security $comp";
415 foreach my $s (@{$config->{source
}}) {
416 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
417 my ($url, $su, $components) = ($1, $3, $4);
418 $su =~ s/SUITE/$suite/;
419 $components =~ s/^\s+//;
420 $components =~ s/\s+$//;
422 foreach my $co (split (/\s+/, $components)) {
425 $ca = ['main'] if !$ca;
433 die "syntax error in source spezification '$s'\n";
437 foreach my $m (@{$config->{mirror
}}) {
438 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
439 my ($ms, $md) = ($1, $3);
441 foreach my $ss (@$sources) {
442 if ($ss->{source
} eq $ms) {
448 die "unusable mirror $ms\n" if !$found;
450 die "syntax error in mirror spezification '$m'\n";
454 $self->{sources
} = $sources;
456 $self->{infodir
} = "info";
458 $self->__allocate_ve ();
460 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
462 my $incl = [qw
(less ssh openssh-server logrotate
)];
464 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
465 pppoeconf nfs-common mtools ntp
)];
467 # ubuntu has too many dependencies on udev, so
468 # we cannot exclude it (instead we disable udevd)
470 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
471 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
472 $suite eq 'bionic' || $suite eq 'cosmic') {
473 push @$incl, 'isc-dhcp-client';
474 push @$excl, qw(libmodule-build-perl);
475 } elsif ($suite eq 'trusty') {
476 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
477 } elsif ($suite eq 'precise') {
478 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
479 } elsif ($suite eq 'hardy') {
480 push @$excl, qw(kbd);
481 push @$excl, qw(apparmor apparmor-utils ntfs-3g
483 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
484 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
485 libntfs-3g28 ntfs-3g friendly-recovery);
486 } elsif ($suite eq 'jessie') {
487 push @$incl, 'sysvinit-core'; # avoid systemd and udev
488 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
489 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm
491 } elsif ($suite eq 'stretch' || $suite eq 'buster') {
492 push @$excl, qw(module-init-tools pciutils hdparm
495 push @$excl, qw(udev module-init-tools pciutils hdparm
499 $self->{incl
} = $incl;
500 $self->{excl
} = $excl;
508 my $infodir = $self->{infodir
};
509 my $arch = $self->{config
}->{architecture
};
515 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
516 die "unable to open log file";
518 foreach my $ss (@{$self->{sources
}}) {
519 my $src = $ss->{mirror
} || $ss->{source
};
520 my $path = "dists/$ss->{suite}/Release";
521 my $url = "$src/$path";
522 my $target = __url_to_filename
("$ss->{source}/$path");
524 $self->download ($url, "$infodir/$target");
525 $self->download ("$url.gpg", "$infodir/$target.gpg");
526 # fixme: impl. verify (needs --keyring option)
530 warn "Release info ignored\n";
532 foreach my $comp (@{$ss->{comp
}}) {
533 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.gz";
534 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
535 my $pkgsrc = "$src/$path";
536 $self->download ($pkgsrc, $target);
537 $self->run_command ("gzip -d '$target'");
543 my ($self, $filename, $size) = @_;
545 my $config = $self->{config
};
549 $data .= "Name: $config->{name}\n";
550 $data .= "Version: $config->{version}\n";
551 $data .= "Type: lxc\n";
552 $data .= "OS: $config->{ostype}\n";
553 $data .= "Section: $config->{section}\n";
554 $data .= "Maintainer: $config->{maintainer}\n";
555 $data .= "Architecture: $config->{architecture}\n";
556 $data .= "Installed-Size: $size\n";
559 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
560 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
561 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
564 $data .= "Description: $config->{headline}\n";
565 $data .= "$config->{description}\n" if $config->{description
};
567 write_file
($data, $filename, 0644);
571 my ($self, $opts) = @_;
573 my $suite = $self->{config
}->{suite
};
574 my $infodir = $self->{infodir
};
575 my $arch = $self->{config
}->{architecture
};
577 my $instpkgs = $self->read_installed ();
578 my $pkginfo = $self->pkginfo();
579 my $veid = $self->{veid
};
580 my $conffile = $self->{veconffile
};
581 my $rootdir = $self->{rootfs
};
583 my $vestat = $self->ve_status();
584 die "ve not running - unable to finalize\n" if !$vestat->{running
};
587 if (-f
"$rootdir/etc/init.d/mysql") {
588 $self->ve_command ("/etc/init.d/mysql stop");
591 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
592 unlink "$rootdir/root/.my.cnf";
595 if ($suite eq 'etch') {
596 # enable apache2 startup
597 if ($instpkgs->{apache2
}) {
598 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
600 unlink "$rootdir/etc/default/apache2";
603 $self->logmsg ("cleanup package status\n");
604 # prevent auto selection of all standard, required or important
605 # packages which are not installed
606 foreach my $pkg (keys %$pkginfo) {
607 my $pri = $pkginfo->{$pkg}->{priority
};
608 if ($pri && ($pri eq 'required' || $pri eq 'important'
609 || $pri eq 'standard')) {
610 if (!$instpkgs->{$pkg}) {
611 $self->ve_dpkg_set_selection ($pkg, 'purge');
616 $self->ve_command ("apt-get clean");
618 $self->logmsg ("update available package list\n");
620 $self->ve_command ("dpkg --clear-avail");
621 foreach my $ss (@{$self->{sources
}}) {
622 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
623 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
624 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
625 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
627 foreach my $comp (@{$ss->{comp
}}) {
628 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
629 "$comp/binary-$arch/Packages");
630 my $target = "/var/lib/apt/lists/$src";
631 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
632 $self->ve_command ("dpkg --merge-avail '$target'");
636 # set dselect default method
637 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
639 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
641 $self->ve_divert_remove ("/sbin/start-stop-daemon");
643 $self->ve_divert_remove ("/sbin/init");
645 # finally stop the VE
646 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
648 unlink "$rootdir/sbin/defenv";
650 unlink <$rootdir/root/dead.letter
*>;
652 unlink "$rootdir/var/log/init.log";
654 unlink "$rootdir/aquota.group";
656 unlink "$rootdir/aquota.user";
658 write_file
("", "$rootdir/var/log/syslog");
660 $self->logmsg ("detecting final size: ");
662 my $sizestr = $self->run_command ("du -sm $rootdir", undef, 1);
664 if ($sizestr =~ m/^(\d+)\s+\Q$rootdir\E$/) {
667 die "unable to detect size\n";
669 $self->logmsg ("$size MB\n");
671 $self->write_config ("$rootdir/etc/appliance.info", $size);
673 $self->logmsg ("creating final appliance archive\n");
675 my $target = "$self->{targetname}.tar";
679 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
680 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
681 $self->run_command ("gzip $target");
687 my $rootdir = $self->{rootfs
};
689 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
691 open (PKGLST
, "<$pkgfilelist") ||
692 die "unable to open '$pkgfilelist'";
696 while (my $rec = <PKGLST
>) {
702 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
706 my $pkg = $res->{'package'};
707 if (my $status = $res->{status
}) {
708 my @sa = split (/\s+/, $status);
710 if ($stat && ($stat ne 'purge')) {
711 $pkglist->{$pkg} = $res;
724 my $veid = $self->{veid
};
726 my $res = { running
=> 0 };
728 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
730 my $filename = "/proc/net/unix";
732 # similar test is used by lcxcontainers.c: list_active_containers
733 my $fh = IO
::File-
>new ($filename, "r");
736 while (defined(my $line = <$fh>)) {
737 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
739 if ($path =~ m!^@/\S+/$veid/command$!) {
750 my ($self, $cmd, $input) = @_;
752 my $veid = $self->{veid
};
753 my $conffile = $self->{veconffile
};
755 if (ref ($cmd) eq 'ARRAY') {
756 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
757 $self->run_command ($cmd, $input);
759 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
763 # like ve_command, but pipes stdin correctly
765 my ($self, @cmd) = @_;
767 my $veid = $self->{veid
};
768 my $conffile = $self->{veconffile
};
771 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
772 'defenv', @cmd) || die "unable to exec command";
774 while (defined (my $line = <$reader>)) {
775 $self->logmsg ($line);
781 die "ve_exec failed - status $rc\n" if $rc != 0;
785 my ($self, $filename) = @_;
787 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
788 "--rename '$filename'");
790 sub ve_divert_remove
{
791 my ($self, $filename) = @_;
793 my $rootdir = $self->{rootfs
};
795 unlink "$rootdir/$filename";
796 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
799 sub ve_debconfig_set
{
800 my ($self, $dcdata) = @_;
802 my $rootdir = $self->{rootfs
};
803 my $cfgfile = "/tmp/debconf.txt";
804 write_file
($dcdata, "$rootdir/$cfgfile");
805 $self->ve_command ("debconf-set-selections $cfgfile");
806 unlink "$rootdir/$cfgfile";
809 sub ve_dpkg_set_selection
{
810 my ($self, $pkg, $status) = @_;
812 $self->ve_command ("dpkg --set-selections", "$pkg $status");
816 my ($self, $cmd, @pkglist) = @_;
818 return if !scalar (@pkglist);
820 my $pkginfo = $self->pkginfo();
822 my $rootdir = $self->{rootfs
};
823 my $cachedir = $self->{cachedir
};
827 foreach my $pkg (@pkglist) {
828 my $filename = $self->getpkgfile ($pkg);
829 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
830 push @files, "/$filename";
831 $self->logmsg ("$cmd: $pkg\n");
834 my $fl = join (' ', @files);
836 if ($cmd eq 'install') {
837 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
838 } elsif ($cmd eq 'unpack') {
839 $self->ve_command ("dpkg --force-depends --unpack $fl");
841 die "internal error";
844 foreach my $fn (@files) { unlink "$rootdir$fn"; }
850 my $veid = $self->{veid
}; # fixme
851 my $conffile = $self->{veconffile
};
853 my $vestat = $self->ve_status();
854 if ($vestat->{running
}) {
855 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
858 rmtree
$self->{rootfs
};
859 unlink $self->{veconffile
};
865 my $veid = $self->{veid
};
866 my $conffile = $self->{veconffile
};
868 $self->logmsg ("initialize VE $veid\n");
870 my $vestat = $self->ve_status();
871 if ($vestat->{running
}) {
872 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
875 rmtree
$self->{rootfs
};
876 mkpath
$self->{rootfs
};
879 sub __deb_version_cmp
{
880 my ($cur, $op, $new) = @_;
882 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
889 sub __parse_packages
{
890 my ($pkginfo, $filename, $src) = @_;
893 open (PKGLST
, "<$filename") ||
894 die "unable to open '$filename'";
896 while (my $rec = <PKGLST
>) {
903 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
907 my $pkg = $res->{'package'};
908 if ($pkg && $res->{'filename'}) {
910 if (my $info = $pkginfo->{$pkg}) {
911 $cur = $info->{version
};
913 my $new = $res->{version
};
914 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
916 $res->{url
} = "$src/$res->{'filename'}";
918 die "no url for package '$pkg'" if !$res->{url
};
920 $pkginfo->{$pkg} = $res;
931 return $self->{pkginfo
} if $self->{pkginfo
};
933 my $infodir = $self->{infodir
};
934 my $arch = $self->{config
}->{architecture
};
936 my $availfn = "$infodir/available";
941 # reading 'available' is faster, because it only contains latest version
942 # (no need to do slow version compares)
944 __parse_packages
($pkginfo, $availfn);
945 $self->{pkginfo
} = $pkginfo;
949 $self->logmsg ("generating available package list\n");
951 foreach my $ss (@{$self->{sources
}}) {
952 foreach my $comp (@{$ss->{comp
}}) {
953 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
954 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
956 my $src = $ss->{mirror
} || $ss->{source
};
958 __parse_packages
($pkginfo, $pkgfilelist, $src);
962 if (my $dep = $self->{config
}->{depends
}) {
963 foreach my $d (split (/,/, $dep)) {
964 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
965 my ($pkg, $op, $rver) = ($1, $3, $4);
966 $self->logmsg ("checking dependencies: $d\n");
967 my $info = $pkginfo->{$pkg};
968 die "package '$pkg' not available\n" if !$info;
970 my $cver = $info->{version
};
971 if (!__deb_version_cmp
($cver, $op, $rver)) {
972 die "detected wrong version '$cver'\n";
976 die "syntax error in depends field";
981 $self->{pkginfo
} = $pkginfo;
983 my $tmpfn = "$availfn.tmp$$";
984 my $fd = IO
::File-
>new (">$tmpfn");
985 foreach my $pkg (sort keys %$pkginfo) {
986 my $info = $pkginfo->{$pkg};
987 print $fd "package: $pkg\n";
988 foreach my $k (sort keys %$info) {
989 next if $k eq 'description';
990 next if $k eq 'package';
992 print $fd "$k: $v\n" if $v;
994 print $fd "description: $info->{description}\n" if $info->{description
};
999 rename ($tmpfn, $availfn);
1004 sub __record_provides
{
1005 my ($pkginfo, $closure, $list, $skipself) = @_;
1007 foreach my $pname (@$list) {
1008 my $info = $pkginfo->{$pname};
1009 # fixme: if someone install packages directly using dpkg, there
1010 # is no entry in 'available', only in 'status'. In that case, we
1011 # should extract info from $instpkgs
1013 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1016 if (my $prov = $info->{provides
}) {
1017 my @pl = split (',', $prov);
1018 foreach my $p (@pl) {
1020 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1025 $closure->{$pname} = 1 if !$skipself;
1030 my ($self, $closure, $list) = @_;
1032 my $pkginfo = $self->pkginfo();
1034 # first, record provided packages
1035 __record_provides
($pkginfo, $closure, $list, 1);
1040 # then resolve dependencies
1041 foreach my $pname (@$list) {
1042 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1048 sub __closure_single
{
1049 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1053 $pname =~ s/:any$//;
1055 return if $closure->{$pname};
1057 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1059 my $dep = $info->{depends
};
1060 my $predep = $info->{'pre-depends'};
1062 my $size = $info->{size
};
1063 my $url = $info->{url
};
1065 $url || die "$pname: no url for package '$pname'";
1067 if (!$pkghash->{$pname}) {
1068 unshift @$pkglist, $pname;
1069 $pkghash->{$pname} = 1;
1072 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1074 $closure->{$pname} = 1;
1080 push @l, split (/,/, $predep) if $predep;
1081 push @l, split (/,/, $dep) if $dep;
1083 DEPEND
: foreach my $p (@l) {
1084 my @l1 = split (/\|/, $p);
1085 foreach my $p1 (@l1) {
1086 if ($p1 =~ m/^\s*(\S+).*/) {
1087 #printf (STDERR "$pname: $p --> $1\n");
1088 if ($closure->{$1}) {
1089 next DEPEND
; # dependency already met
1093 # search for non-excluded alternative
1095 foreach my $p1 (@l1) {
1096 if ($p1 =~ m/^\s*(\S+).*/) {
1097 next if grep { $1 eq $_ } @$excl;
1102 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1104 #printf (STDERR "$pname: $p --> $found\n");
1106 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1110 sub cache_packages
{
1111 my ($self, $pkglist) = @_;
1113 foreach my $pkg (@$pkglist) {
1114 $self->getpkgfile ($pkg);
1119 my ($self, $pkg) = @_;
1121 my $pkginfo = $self->pkginfo();
1122 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1123 my $cachedir = $self->{cachedir
};
1125 my $url = $info->{url
};
1128 if ($url =~ m
|/([^/]+.deb
)$|) {
1131 die "internal error";
1134 return $filename if -f
"$cachedir/$filename";
1138 $self->download ($url, "$cachedir/$filename");
1143 sub install_init_script
{
1144 my ($self, $script, $runlevel, $prio) = @_;
1146 my $suite = $self->{config
}->{suite
};
1147 my $rootdir = $self->{rootfs
};
1149 my $base = basename
($script);
1150 my $target = "$rootdir/etc/init.d/$base";
1152 $self->run_command ("install -m 0755 '$script' '$target'");
1153 if ($suite eq 'etch' || $suite eq 'lenny') {
1154 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1155 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1156 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1157 $suite eq 'bionic' || $suite eq 'cosmic') {
1158 die "unable to install init script (system uses systemd)\n";
1159 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1160 die "unable to install init script (system uses upstart)\n";
1162 $self->ve_command ("insserv $base");
1169 my ($self, $opts) = @_;
1171 my $pkginfo = $self->pkginfo();
1172 my $veid = $self->{veid
};
1173 my $suite = $self->{config
}->{suite
};
1175 my $important = [ @{$self->{incl
}} ];
1179 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1181 if ($mta eq 'postfix') {
1182 push @$important, "postfix";
1185 foreach my $p (sort keys %$pkginfo) {
1186 next if grep { $p eq $_ } @{$self->{excl
}};
1187 my $pri = $pkginfo->{$p}->{priority
};
1189 next if $mta ne 'exim' && $p =~ m/exim/;
1190 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1192 push @$required, $p if $pri eq 'required';
1193 push @$important, $p if $pri eq 'important';
1194 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1198 $required = $self->closure ($closure, $required);
1199 $important = $self->closure ($closure, $important);
1201 if (!$opts->{minimal
}) {
1202 push @$standard, 'xbase-clients';
1203 $standard = $self->closure ($closure, $standard);
1206 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1207 # except those explicitly excluded
1208 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1209 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1210 foreach my $d (split (/,/, $mdeps)) {
1211 if ($d =~ m/^\s*(\S+)$/) {
1213 next if $closure->{$pkg};
1214 next if grep { $pkg eq $_ } @{$self->{excl
}};
1215 die "missing ubuntu-minimal package '$pkg'\n";
1218 if (!$opts->{minimal
}) {
1219 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1220 foreach my $d (split (/,/, $mdeps)) {
1221 if ($d =~ m/^\s*(\S+)$/) {
1223 next if $closure->{$pkg};
1224 next if grep { $pkg eq $_ } @{$self->{excl
}};
1225 die "missing ubuntu-standard package '$pkg'\n";
1231 # download/cache all files first
1232 $self->cache_packages ($required);
1233 $self->cache_packages ($important);
1234 $self->cache_packages ($standard);
1236 my $rootdir = $self->{rootfs
};
1238 # extract required packages first
1239 $self->logmsg ("create basic environment\n");
1240 foreach my $p (@$required) {
1241 my $filename = $self->getpkgfile ($p);
1242 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1243 if ($content =~ m/^data.tar.xz$/m) {
1244 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1246 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1251 my $data = "Package: dpkg\n" .
1252 "Version: $pkginfo->{dpkg}->{version}\n" .
1253 "Status: install ok installed\n";
1255 write_file
($data, "$rootdir/var/lib/dpkg/status");
1256 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1257 write_file
("", "$rootdir/var/lib/dpkg/available");
1260 foreach my $ss (@{$self->{sources
}}) {
1261 my $url = $ss->{source
};
1262 my $comp = join (' ', @{$ss->{comp
}});
1263 $data .= "deb $url $ss->{suite} $comp\n\n";
1266 write_file
($data, "$rootdir/etc/apt/sources.list");
1268 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1269 write_file
($data, "$rootdir/etc/fstab", 0644);
1271 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1273 # avoid warnings about non-existent resolv.conf
1274 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1276 if ($suite eq 'cosmic' || $suite eq 'bionic' || $suite eq 'artful' ||
1277 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1279 # no need to configure loopback device
1281 $data = "auto lo\niface lo inet loopback\n";
1282 mkdir "$rootdir/etc/network";
1283 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1287 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1289 # avoid warnings about missing default locale
1290 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1293 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1294 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1296 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1298 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1300 $self->logmsg ("initialize ld cache\n");
1301 $self->ve_command ("/sbin/ldconfig");
1302 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1304 $self->logmsg ("installing packages\n");
1306 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1308 $self->ve_dpkg ('install', 'dpkg');
1310 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1312 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1314 $self->ve_dpkg ('install', 'libc6');
1315 $self->ve_dpkg ('install', 'perl-base');
1317 unlink "$rootdir/usr/bin/awk";
1319 $self->ve_dpkg ('install', 'mawk');
1320 $self->ve_dpkg ('install', 'debconf');
1322 # unpack required packages
1323 foreach my $p (@$required) {
1324 $self->ve_dpkg ('unpack', $p);
1327 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1328 $self->ve_divert_add ("/sbin/init");
1329 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1331 # disable service activation
1332 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1333 $data = "#!/bin/sh\nexit 101\n";
1334 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1336 # disable start-stop-daemon
1337 $self->ve_divert_add ("/sbin/start-stop-daemon");
1341 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1343 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1346 $self->ve_divert_add ("/sbin/udevd");
1348 if ($suite eq 'etch') {
1349 # disable apache2 startup
1350 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1353 $self->logmsg ("configure required packages\n");
1354 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1356 # set postfix defaults
1357 if ($mta eq 'postfix') {
1358 $data = "postfix postfix/main_mailer_type select Local only\n";
1359 $self->ve_debconfig_set ($data);
1361 $data = "postmaster: root\nwebmaster: root\n";
1362 write_file
($data, "$rootdir/etc/aliases");
1365 if ($suite eq 'jaunty') {
1366 # jaunty does not create /var/run/network, so network startup fails.
1367 # so we do not use tmpfs for /var/run and /var/lock
1368 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1369 # and create the directory here
1370 $self->run_command ("mkdir $rootdir/var/run/network");
1373 # unpack base packages
1374 foreach my $p (@$important) {
1375 $self->ve_dpkg ('unpack', $p);
1379 if (-x
"$rootdir/sbin/ifconfig") {
1380 $self->ve_command ("ifconfig lo up");
1382 $self->ve_command ("ip link set lo up");
1385 $self->logmsg ("configure important packages\n");
1386 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1388 if (-d
"$rootdir/etc/event.d") {
1389 unlink <$rootdir/etc/event.d
/tty
*>;
1392 if (-f
"$rootdir/etc/inittab") {
1393 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1396 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1397 unlink "$rootdir/etc/mtab";
1398 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1401 $self->ve_command ("usermod -L root");
1403 if ($mta eq 'postfix') {
1404 $data = "postfix postfix/main_mailer_type select No configuration\n";
1405 $self->ve_debconfig_set ($data);
1407 unlink "$rootdir/etc/mailname";
1408 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1411 if (!$opts->{minimal
}) {
1412 # unpack standard packages
1413 foreach my $p (@$standard) {
1414 $self->ve_dpkg ('unpack', $p);
1417 $self->logmsg ("configure standard packages\n");
1418 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1421 # disable HWCLOCK access
1422 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1425 $self->ve_divert_add ("/usr/sbin/hald");
1427 # disable /dev/urandom init
1428 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1430 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1432 $self->ve_divert_add ("/sbin/klogd");
1435 # remove unnecessays sysctl entries to avoid warnings
1437 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1438 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1439 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1440 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1441 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1442 $self->run_command ($cmd);
1444 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1445 if (-f
$bindv6only) {
1447 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1448 $cmd .= " -i '$bindv6only'";
1449 $self->run_command ($cmd);
1452 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1453 # disable tty init (console-setup)
1455 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1456 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1457 $self->run_command ($cmd);
1460 if ($suite eq 'intrepid') {
1461 # remove sysctl setup (avoid warnings at startup)
1462 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1463 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf";
1464 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1465 $self->run_command ("rm $filelist");
1467 if ($suite eq 'jaunty') {
1468 # remove sysctl setup (avoid warnings at startup)
1469 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1470 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1471 $self->run_command ("rm $filelist");
1478 my $veid = $self->{veid
};
1479 my $conffile = $self->{veconffile
};
1481 my $vestat = $self->ve_status();
1483 if (!$vestat->{exist
}) {
1484 $self->logmsg ("Please create the appliance first (bootstrap)");
1488 if (!$vestat->{running
}) {
1489 $self->run_command ("lxc-start -n $veid -f $conffile");
1492 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1495 sub ve_mysql_command
{
1496 my ($self, $sql, $password) = @_;
1498 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1499 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1501 $self->ve_command ("mysql", $sql);
1504 sub ve_mysql_bootstrap
{
1505 my ($self, $sql, $password) = @_;
1509 my $suite = $self->{config
}->{suite
};
1511 if ($suite eq 'jessie') {
1512 my $rootdir = $self->{rootfs
};
1513 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1516 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1517 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1520 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1521 "--skip-bdb --skip-innodb --skip-ndbcluster";
1524 $self->ve_command ($cmd, $sql);
1527 sub compute_required
{
1528 my ($self, $pkglist) = @_;
1530 my $pkginfo = $self->pkginfo();
1531 my $instpkgs = $self->read_installed ();
1534 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1536 return $self->closure ($closure, $pkglist);
1540 my ($self, $opts) = @_;
1542 my @supp = ('7.4', '8.1');
1543 my $pgversion = '8.1';
1545 my $suite = $self->{config
}->{suite
};
1547 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1550 } elsif ($suite eq 'squeeze') {
1553 } elsif ($suite eq 'wheezy') {
1556 } elsif ($suite eq 'jessie') {
1559 } elsif ($suite eq 'stretch') {
1562 } elsif ($suite eq 'buster') {
1567 $pgversion = $opts->{version
} if $opts->{version
};
1569 die "unsupported postgres version '$pgversion'\n"
1570 if !grep { $pgversion eq $_; } @supp;
1572 my $rootdir = $self->{rootfs
};
1574 my $required = $self->compute_required (["postgresql-$pgversion"]);
1576 $self->cache_packages ($required);
1578 $self->ve_dpkg ('install', @$required);
1580 my $iscript = "postgresql-$pgversion";
1581 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1582 $suite eq 'stretch') {
1583 $iscript = 'postgresql';
1586 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1590 my ($self, $opts) = @_;
1592 my $password = $opts->{password
};
1593 my $rootdir = $self->{rootfs
};
1595 my $suite = $self->{config
}->{suite
};
1598 if ($suite eq 'squeeze') {
1600 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1603 die "task_mysql: unsupported suite '$suite'";
1606 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1608 $self->cache_packages ($required);
1610 $self->ve_dpkg ('install', @$required);
1612 # fix security (see /usr/bin/mysql_secure_installation)
1613 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1614 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1615 "FLUSH PRIVILEGES;\n";
1616 $self->ve_mysql_bootstrap ($sql);
1620 my $rpw = $password eq 'random' ?
'admin' : $password;
1622 my $sql = "USE mysql;\n" .
1623 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1624 "FLUSH PRIVILEGES
;\n";
1625 $self->ve_mysql_bootstrap ($sql);
1627 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1628 if ($password eq 'random') {
1629 $self->install_init_script ($script_mysql_randompw, 2, 20);
1633 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1637 my ($self, $opts) = @_;
1639 my $memlimit = $opts->{memlimit
};
1640 my $rootdir = $self->{rootfs
};
1642 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1644 $self->cache_packages ($required);
1646 $self->ve_dpkg ('install', @$required);
1649 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1654 my ($self, $pkglist, $unpack) = @_;
1656 my $required = $self->compute_required ($pkglist);
1658 $self->cache_packages ($required);
1660 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1664 my ($self, $distclean) = @_;
1666 unlink $self->{logfile
};
1667 unlink "$self->{targetname}.tar";
1668 unlink "$self->{targetname}.tar.gz";
1670 $self->ve_destroy ();
1673 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1675 rmtree
$self->{infodir
};