11 use POSIX qw
(LONG_MAX
);
15 # fixme: lock container ?
17 my $dablibdir = "/usr/lib/dab";
18 my $devicetar = "$dablibdir/devices.tar.gz";
19 my $default_env = "$dablibdir/scripts/defenv";
20 my $fake_init = "$dablibdir/scripts/init.pl";
21 my $script_ssh_init = "$dablibdir/scripts/ssh_gen_host_keys";
22 my $script_mysql_randompw = "$dablibdir/scripts/mysql_randompw";
23 my $script_init_urandom = "$dablibdir/scripts/init_urandom";
25 my $postfix_main_cf = <<EOD;
26 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
28 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
31 # appending .domain is the MUA's job.
32 append_dot_mydomain = no
34 # Uncomment the next line to generate "delayed mail" warnings
35 #delay_warning_time = 4h
37 alias_maps = hash:/etc/aliases
38 alias_database = hash:/etc/aliases
39 mydestination = \$myhostname, localhost.\$mydomain, localhost
41 mynetworks = 127.0.0.0/8
42 inet_interfaces = loopback-only
43 recipient_delimiter = +
45 compatibility_level = 2
49 # produce apt compatible filenames (/var/lib/apt/lists)
50 sub __url_to_filename
{
62 my $supported_suites = {
64 ostype
=> "debian-11.0",
67 ostype
=> "debian-10.0",
70 ostype
=> "debian-9.0",
73 ostype
=> "debian-8.0",
76 ostype
=> "debian-7.0",
79 ostype
=> "debian-6.0",
82 ostype
=> "debian-5.0",
85 ostype
=> "debian-4.0",
91 ostype
=> "devuan-1.0",
95 ostype
=> "devuan-2.0",
98 ostype
=> "devuan-2.0",
103 ostype
=> "ubuntu-8.04",
107 ostype
=> "ubuntu-8.10",
111 ostype
=> "ubuntu-9.04",
115 ostype
=> "ubuntu-12.04",
119 ostype
=> "ubuntu-14.04",
123 ostype
=> "ubuntu-15.04",
127 ostype
=> "ubuntu-15.10",
131 ostype
=> "ubuntu-16.04",
135 ostype
=> "ubuntu-16.10",
139 ostype
=> "ubuntu-17.04",
143 ostype
=> "ubuntu-17.10",
147 ostype
=> "ubuntu-18.04",
151 ostype
=> "ubuntu-18.10",
155 ostype
=> "ubuntu-19.04",
159 ostype
=> "ubuntu-19.10",
163 ostype
=> "ubuntu-20.04",
171 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
174 $suiteinfo->{origin
} //= 'debian';
175 $suiteinfo->{suite
} //= $suite;
181 my ($self, $url, $path) = @_;
183 $self->logmsg ("download: $url\n");
184 my $tmpfn = "$path.tmp$$";
186 $self->run_command ("wget -q '$url' -O '$tmpfn'");
195 rename ($tmpfn, $path);
199 my ($data, $file, $perm) = @_;
201 die "no filename" if !$file;
205 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
206 die "unable to open file '$file'";
216 die "no filename" if !$file;
218 my $fh = IO
::File-
>new ($file) ||
219 die "unable to open file '$file'";
221 local $/; # slurp mode
235 my $fh = IO
::File-
>new ("<$filename") || return $res;
238 while (defined (my $line = <$fh>)) {
239 next if $line =~ m/^\#/;
240 next if $line =~ m/^\s*$/;
250 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
251 $res->{headline
} = $1;
252 chomp $res->{headline
};
255 $res->{description
} = $long;
256 chomp $res->{description
};
257 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
258 my ($key, $value) = (lc ($1), $2);
259 if ($key eq 'source' || $key eq 'mirror') {
260 push @{$res->{$key}}, $value;
262 die "duplicate key '$key'\n" if defined ($res->{$key});
263 $res->{$key} = $value;
266 die "unable to parse config file: $rec";
270 die "unable to parse config file" if $rec;
276 my ($self, $cmd, $input, $getoutput) = @_;
278 my $reader = IO
::File-
>new();
279 my $writer = IO
::File-
>new();
280 my $error = IO
::File-
>new();
284 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
288 if (ref ($cmd) eq 'ARRAY') {
289 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
291 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
298 if ($orig_pid != $$) {
299 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
306 print $writer $input if defined $input;
309 my $select = new IO
::Select
;
310 $select->add ($reader);
311 $select->add ($error);
314 my $logfd = $self->{logfd
};
316 while ($select->count) {
317 my @handles = $select->can_read ();
319 foreach my $h (@handles) {
321 my $count = sysread ($h, $buf, 4096);
322 if (!defined ($count)) {
324 die "command '$cmdstr' failed: $!";
326 $select->remove ($h) if !$count;
330 $res .= $buf if $getoutput;
337 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
345 $self->writelog (@_);
350 my $fd = $self->{logfd
};
354 sub __sample_config
{
358 my $arch = $self->{config
}->{architecture
};
360 my $ostype = $self->{config
}->{ostype
};
362 if ($ostype =~ m/^de(bi|vu)an-/) {
363 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
364 } elsif ($ostype =~ m/^ubuntu-/) {
365 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
367 die "unknown os type '$ostype'\n";
369 $data .= "lxc.uts.name = localhost\n";
370 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
379 if (my $fd = IO
::File-
>new (".veid")) {
386 $self->{working_dir
} = getcwd
;
387 $self->{veconffile
} = "$self->{working_dir}/config";
388 $self->{rootfs
} = "$self->{working_dir}/rootfs";
391 $self->{veid
} = $cid;
397 UUID
::generate
($uuid);
398 UUID
::unparse
($uuid, $uuid_str);
399 $self->{veid
} = $uuid_str;
401 my $fd = IO
::File-
>new (">.veid") ||
402 die "unable to write '.veid'\n";
403 print $fd "$self->{veid}\n";
406 my $cdata = $self->__sample_config();
408 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
409 die "unable to write lxc config file '$self->{veconffile}' - $!";
413 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
415 $self->logmsg ("allocated VE $self->{veid}\n");
417 return $self->{veid
};
421 my ($class, $config) = @_;
423 $class = ref ($class) || $class;
427 $config = read_config
('dab.conf') if !$config;
429 $self->{config
} = $config;
433 $self->{logfile
} = "logfile";
434 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
435 die "unable to open log file";
437 my $arch = $config->{architecture
};
438 die "no 'architecture' specified\n" if !$arch;
440 die "unsupported architecture '$arch'\n"
441 if $arch !~ m/^(i386|amd64)$/;
443 my $suite = $config->{suite
} || die "no 'suite' specified\n";
445 my $suiteinfo = get_suite_info
($suite);
446 $suite = $suiteinfo->{suite
};
447 $config->{ostype
} = $suiteinfo->{ostype
};
449 my $name = $config->{name
} || die "no 'name' specified\n";
451 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
452 die "illegal characters in name '$name'\n";
454 my $version = $config->{version
};
455 die "no 'version' specified\n" if !$version;
456 die "no 'section' specified\n" if !$config->{section
};
457 die "no 'description' specified\n" if !$config->{headline
};
458 die "no 'maintainer' specified\n" if !$config->{maintainer
};
460 if ($name =~ m/^$config->{ostype}/) {
461 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
463 $self->{targetname
} = "$config->{ostype}-${name}_" .
464 "${version}_$config->{architecture}";
467 if (!$config->{source
}) {
468 if (lc($suiteinfo->{origin
}) eq 'debian') {
469 if ($suite eq 'etch' || $suite eq 'lenny') {
470 push @{$config->{source
}}, (
471 'http://ftp.debian.org/debian SUITE main contrib',
472 'http://security.debian.org SUITE/updates main contrib',
474 } elsif ($suite eq 'bullseye') {
475 push @{$config->{source
}}, (
476 "http://ftp.debian.org/debian SUITE main contrib",
477 "http://ftp.debian.org/debian SUITE-updates main contrib",
478 "http://security.debian.org SUITE-security main contrib",
481 push @{$config->{source
}}, (
482 "http://ftp.debian.org/debian SUITE main contrib",
483 "http://ftp.debian.org/debian SUITE-updates main contrib",
484 "http://security.debian.org SUITE/updates main contrib",
487 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
488 my $comp = "main restricted universe multiverse";
489 push @{$config->{source
}}, (
490 "http://archive.ubuntu.com/ubuntu SUITE $comp",
491 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
492 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
501 foreach my $s (@{$config->{source
}}) {
502 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
503 my ($url, $su, $components) = ($1, $3, $4);
504 $su =~ s/SUITE/$suite/;
505 $components =~ s/^\s+//;
506 $components =~ s/\s+$//;
508 foreach my $co (split (/\s+/, $components)) {
511 $ca = ['main'] if !$ca;
519 die "syntax error in source spezification '$s'\n";
523 foreach my $m (@{$config->{mirror
}}) {
524 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
525 my ($ms, $md) = ($1, $3);
527 foreach my $ss (@$sources) {
528 if ($ss->{source
} eq $ms) {
534 die "unusable mirror $ms\n" if !$found;
536 die "syntax error in mirror spezification '$m'\n";
540 $self->{sources
} = $sources;
542 $self->{infodir
} = "info";
544 $self->__allocate_ve ();
546 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
548 my $incl = [qw
(less ssh openssh-server logrotate
)];
550 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
551 pppoeconf nfs-common mtools ntp
)];
553 # ubuntu has too many dependencies on udev, so
554 # we cannot exclude it (instead we disable udevd)
556 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
557 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
558 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
559 $suite eq 'eoan' || $suite eq 'focal') {
560 push @$incl, 'isc-dhcp-client';
561 push @$excl, qw(libmodule-build-perl);
562 } elsif ($suite eq 'trusty') {
563 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
564 } elsif ($suite eq 'precise') {
565 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
566 } elsif ($suite eq 'hardy') {
567 push @$excl, qw(kbd);
568 push @$excl, qw(apparmor apparmor-utils ntfs-3g
570 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
571 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
572 libntfs-3g28 ntfs-3g friendly-recovery);
573 } elsif ($suite eq 'jessie') {
574 push @$incl, 'sysvinit-core'; # avoid systemd and udev
575 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
576 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm
578 } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye') {
579 push @$excl, qw(module-init-tools pciutils hdparm
582 push @$excl, qw(udev module-init-tools pciutils hdparm
586 $self->{incl
} = $incl;
587 $self->{excl
} = $excl;
595 my $infodir = $self->{infodir
};
596 my $arch = $self->{config
}->{architecture
};
602 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
603 die "unable to open log file";
605 # FIXME: seems a bit like a hacky way??
610 if ($self->{config
}->{suite
} eq 'bullseye') {
617 foreach my $ss (@{$self->{sources
}}) {
618 my $src = $ss->{mirror
} || $ss->{source
};
619 my $path = "dists/$ss->{suite}/Release";
620 my $url = "$src/$path";
621 my $target = __url_to_filename
("$ss->{source}/$path");
623 $self->download ($url, "$infodir/$target");
624 $self->download ("$url.gpg", "$infodir/$target.gpg");
625 # fixme: impl. verify (needs --keyring option)
629 warn "Release info ignored\n";
632 foreach my $comp (@{$ss->{comp
}}) {
633 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
634 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
635 my $pkgsrc = "$src/$path";
636 $self->download ($pkgsrc, $target);
637 $self->run_command ("$COMPRESSOR->{decomp} '$target'");
643 my ($self, $filename, $size) = @_;
645 my $config = $self->{config
};
649 $data .= "Name: $config->{name}\n";
650 $data .= "Version: $config->{version}\n";
651 $data .= "Type: lxc\n";
652 $data .= "OS: $config->{ostype}\n";
653 $data .= "Section: $config->{section}\n";
654 $data .= "Maintainer: $config->{maintainer}\n";
655 $data .= "Architecture: $config->{architecture}\n";
656 $data .= "Installed-Size: $size\n";
659 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
660 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
661 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
664 $data .= "Description: $config->{headline}\n";
665 $data .= "$config->{description}\n" if $config->{description
};
667 write_file
($data, $filename, 0644);
671 my ($self, $opts) = @_;
673 my $suite = $self->{config
}->{suite
};
674 my $infodir = $self->{infodir
};
675 my $arch = $self->{config
}->{architecture
};
677 my $instpkgs = $self->read_installed ();
678 my $pkginfo = $self->pkginfo();
679 my $veid = $self->{veid
};
680 my $conffile = $self->{veconffile
};
681 my $rootdir = $self->{rootfs
};
683 my $vestat = $self->ve_status();
684 die "ve not running - unable to finalize\n" if !$vestat->{running
};
687 if (-f
"$rootdir/etc/init.d/mysql") {
688 $self->ve_command ("/etc/init.d/mysql stop");
691 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
692 unlink "$rootdir/root/.my.cnf";
695 if ($suite eq 'etch') {
696 # enable apache2 startup
697 if ($instpkgs->{apache2
}) {
698 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
700 unlink "$rootdir/etc/default/apache2";
703 $self->logmsg ("cleanup package status\n");
704 # prevent auto selection of all standard, required or important
705 # packages which are not installed
706 foreach my $pkg (keys %$pkginfo) {
707 my $pri = $pkginfo->{$pkg}->{priority
};
708 if ($pri && ($pri eq 'required' || $pri eq 'important'
709 || $pri eq 'standard')) {
710 if (!$instpkgs->{$pkg}) {
711 $self->ve_dpkg_set_selection ($pkg, 'purge');
716 $self->ve_command ("apt-get clean");
718 $self->logmsg ("update available package list\n");
720 $self->ve_command ("dpkg --clear-avail");
721 foreach my $ss (@{$self->{sources
}}) {
722 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
723 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
724 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
725 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
727 foreach my $comp (@{$ss->{comp
}}) {
728 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
729 "$comp/binary-$arch/Packages");
730 my $target = "/var/lib/apt/lists/$src";
731 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
732 $self->ve_command ("dpkg --merge-avail '$target'");
736 # set dselect default method
737 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
739 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
741 $self->ve_divert_remove ("/sbin/start-stop-daemon");
743 $self->ve_divert_remove ("/sbin/init");
745 # finally stop the VE
746 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
748 unlink "$rootdir/sbin/defenv";
750 unlink <$rootdir/root/dead.letter
*>;
752 unlink "$rootdir/var/log/init.log";
754 unlink "$rootdir/aquota.group";
756 unlink "$rootdir/aquota.user";
758 write_file
("", "$rootdir/var/log/syslog");
760 my $get_path_size = sub {
762 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
763 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
766 die "unable to detect size for '$path'\n";
770 $self->logmsg ("detecting final appliance size: ");
771 my $size = $get_path_size->($rootdir);
772 $self->logmsg ("$size MB\n");
774 $self->write_config ("$rootdir/etc/appliance.info", $size);
776 $self->logmsg ("creating final appliance archive\n");
778 my $target = "$self->{targetname}.tar";
779 my $final_archive = "${target}.gz";
781 unlink $final_archive;
783 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
784 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
785 $self->run_command ("gzip $target");
787 $self->logmsg ("detecting final commpressed appliance size: ");
788 $size = $get_path_size->($final_archive);
789 $self->logmsg ("$size MB\n");
791 $self->logmsg ("appliance archive: $final_archive\n");
797 my $rootdir = $self->{rootfs
};
799 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
801 open (PKGLST
, "<$pkgfilelist") ||
802 die "unable to open '$pkgfilelist'";
806 while (my $rec = <PKGLST
>) {
812 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
816 my $pkg = $res->{'package'};
817 if (my $status = $res->{status
}) {
818 my @sa = split (/\s+/, $status);
820 if ($stat && ($stat ne 'purge')) {
821 $pkglist->{$pkg} = $res;
834 my $veid = $self->{veid
};
836 my $res = { running
=> 0 };
838 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
840 my $filename = "/proc/net/unix";
842 # similar test is used by lcxcontainers.c: list_active_containers
843 my $fh = IO
::File-
>new ($filename, "r");
846 while (defined(my $line = <$fh>)) {
847 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
849 if ($path =~ m!^@/\S+/$veid/command$!) {
860 my ($self, $cmd, $input) = @_;
862 my $veid = $self->{veid
};
863 my $conffile = $self->{veconffile
};
865 if (ref ($cmd) eq 'ARRAY') {
866 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
867 $self->run_command ($cmd, $input);
869 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
873 # like ve_command, but pipes stdin correctly
875 my ($self, @cmd) = @_;
877 my $veid = $self->{veid
};
878 my $conffile = $self->{veconffile
};
881 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
882 'defenv', @cmd) || die "unable to exec command";
884 while (defined (my $line = <$reader>)) {
885 $self->logmsg ($line);
891 die "ve_exec failed - status $rc\n" if $rc != 0;
895 my ($self, $filename) = @_;
897 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
898 "--rename '$filename'");
900 sub ve_divert_remove
{
901 my ($self, $filename) = @_;
903 my $rootdir = $self->{rootfs
};
905 unlink "$rootdir/$filename";
906 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
909 sub ve_debconfig_set
{
910 my ($self, $dcdata) = @_;
912 my $rootdir = $self->{rootfs
};
913 my $cfgfile = "/tmp/debconf.txt";
914 write_file
($dcdata, "$rootdir/$cfgfile");
915 $self->ve_command ("debconf-set-selections $cfgfile");
916 unlink "$rootdir/$cfgfile";
919 sub ve_dpkg_set_selection
{
920 my ($self, $pkg, $status) = @_;
922 $self->ve_command ("dpkg --set-selections", "$pkg $status");
926 my ($self, $cmd, @pkglist) = @_;
928 return if !scalar (@pkglist);
930 my $pkginfo = $self->pkginfo();
932 my $rootdir = $self->{rootfs
};
933 my $cachedir = $self->{cachedir
};
937 foreach my $pkg (@pkglist) {
938 my $filename = $self->getpkgfile ($pkg);
939 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
940 push @files, "/$filename";
941 $self->logmsg ("$cmd: $pkg\n");
944 my $fl = join (' ', @files);
946 if ($cmd eq 'install') {
947 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
948 } elsif ($cmd eq 'unpack') {
949 $self->ve_command ("dpkg --force-depends --unpack $fl");
951 die "internal error";
954 foreach my $fn (@files) { unlink "$rootdir$fn"; }
960 my $veid = $self->{veid
}; # fixme
961 my $conffile = $self->{veconffile
};
963 my $vestat = $self->ve_status();
964 if ($vestat->{running
}) {
965 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
968 rmtree
$self->{rootfs
};
969 unlink $self->{veconffile
};
975 my $veid = $self->{veid
};
976 my $conffile = $self->{veconffile
};
978 $self->logmsg ("initialize VE $veid\n");
980 my $vestat = $self->ve_status();
981 if ($vestat->{running
}) {
982 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
985 rmtree
$self->{rootfs
};
986 mkpath
$self->{rootfs
};
989 sub __deb_version_cmp
{
990 my ($cur, $op, $new) = @_;
992 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
999 sub __parse_packages
{
1000 my ($pkginfo, $filename, $src) = @_;
1003 open (PKGLST
, "<$filename") ||
1004 die "unable to open '$filename'";
1006 while (my $rec = <PKGLST
>) {
1007 $rec =~ s/\n\s+/ /g;
1013 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
1017 my $pkg = $res->{'package'};
1018 if ($pkg && $res->{'filename'}) {
1020 if (my $info = $pkginfo->{$pkg}) {
1021 $cur = $info->{version
};
1023 my $new = $res->{version
};
1024 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1026 $res->{url
} = "$src/$res->{'filename'}";
1028 die "no url for package '$pkg'" if !$res->{url
};
1030 $pkginfo->{$pkg} = $res;
1041 return $self->{pkginfo
} if $self->{pkginfo
};
1043 my $infodir = $self->{infodir
};
1044 my $arch = $self->{config
}->{architecture
};
1046 my $availfn = "$infodir/available";
1051 # reading 'available' is faster, because it only contains latest version
1052 # (no need to do slow version compares)
1054 __parse_packages
($pkginfo, $availfn);
1055 $self->{pkginfo
} = $pkginfo;
1059 $self->logmsg ("generating available package list\n");
1061 foreach my $ss (@{$self->{sources
}}) {
1062 foreach my $comp (@{$ss->{comp
}}) {
1063 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1064 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1066 my $src = $ss->{mirror
} || $ss->{source
};
1068 __parse_packages
($pkginfo, $pkgfilelist, $src);
1072 if (my $dep = $self->{config
}->{depends
}) {
1073 foreach my $d (split (/,/, $dep)) {
1074 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1075 my ($pkg, $op, $rver) = ($1, $3, $4);
1076 $self->logmsg ("checking dependencies: $d\n");
1077 my $info = $pkginfo->{$pkg};
1078 die "package '$pkg' not available\n" if !$info;
1080 my $cver = $info->{version
};
1081 if (!__deb_version_cmp
($cver, $op, $rver)) {
1082 die "detected wrong version '$cver'\n";
1086 die "syntax error in depends field";
1091 $self->{pkginfo
} = $pkginfo;
1093 my $tmpfn = "$availfn.tmp$$";
1094 my $fd = IO
::File-
>new (">$tmpfn");
1095 foreach my $pkg (sort keys %$pkginfo) {
1096 my $info = $pkginfo->{$pkg};
1097 print $fd "package: $pkg\n";
1098 foreach my $k (sort keys %$info) {
1099 next if $k eq 'description';
1100 next if $k eq 'package';
1101 my $v = $info->{$k};
1102 print $fd "$k: $v\n" if $v;
1104 print $fd "description: $info->{description}\n" if $info->{description
};
1109 rename ($tmpfn, $availfn);
1114 sub __record_provides
{
1115 my ($pkginfo, $closure, $list, $skipself) = @_;
1117 foreach my $pname (@$list) {
1118 my $info = $pkginfo->{$pname};
1119 # fixme: if someone install packages directly using dpkg, there
1120 # is no entry in 'available', only in 'status'. In that case, we
1121 # should extract info from $instpkgs
1123 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1126 if (my $prov = $info->{provides
}) {
1127 my @pl = split (',', $prov);
1128 foreach my $p (@pl) {
1130 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1135 $closure->{$pname} = 1 if !$skipself;
1140 my ($self, $closure, $list) = @_;
1142 my $pkginfo = $self->pkginfo();
1144 # first, record provided packages
1145 __record_provides
($pkginfo, $closure, $list, 1);
1150 # then resolve dependencies
1151 foreach my $pname (@$list) {
1152 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1158 sub __closure_single
{
1159 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1163 $pname =~ s/:any$//;
1165 return if $closure->{$pname};
1167 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1169 my $dep = $info->{depends
};
1170 my $predep = $info->{'pre-depends'};
1172 my $size = $info->{size
};
1173 my $url = $info->{url
};
1175 $url || die "$pname: no url for package '$pname'";
1177 if (!$pkghash->{$pname}) {
1178 unshift @$pkglist, $pname;
1179 $pkghash->{$pname} = 1;
1182 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1184 $closure->{$pname} = 1;
1190 push @l, split (/,/, $predep) if $predep;
1191 push @l, split (/,/, $dep) if $dep;
1193 DEPEND
: foreach my $p (@l) {
1194 my @l1 = split (/\|/, $p);
1195 foreach my $p1 (@l1) {
1196 if ($p1 =~ m/^\s*(\S+).*/) {
1197 #printf (STDERR "$pname: $p --> $1\n");
1198 if ($closure->{$1}) {
1199 next DEPEND
; # dependency already met
1203 # search for non-excluded alternative
1205 foreach my $p1 (@l1) {
1206 if ($p1 =~ m/^\s*(\S+).*/) {
1207 next if grep { $1 eq $_ } @$excl;
1212 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1214 #printf (STDERR "$pname: $p --> $found\n");
1216 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1220 sub cache_packages
{
1221 my ($self, $pkglist) = @_;
1223 foreach my $pkg (@$pkglist) {
1224 $self->getpkgfile ($pkg);
1229 my ($self, $pkg) = @_;
1231 my $pkginfo = $self->pkginfo();
1232 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1233 my $cachedir = $self->{cachedir
};
1235 my $url = $info->{url
};
1238 if ($url =~ m
|/([^/]+.deb
)$|) {
1241 die "internal error";
1244 return $filename if -f
"$cachedir/$filename";
1248 $self->download ($url, "$cachedir/$filename");
1253 sub install_init_script
{
1254 my ($self, $script, $runlevel, $prio) = @_;
1256 my $suite = $self->{config
}->{suite
};
1257 my $rootdir = $self->{rootfs
};
1259 my $base = basename
($script);
1260 my $target = "$rootdir/etc/init.d/$base";
1262 $self->run_command ("install -m 0755 '$script' '$target'");
1263 if ($suite eq 'etch' || $suite eq 'lenny') {
1264 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1265 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1266 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1267 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1268 $suite eq 'eoan' || $suite eq 'focal') {
1269 die "unable to install init script (system uses systemd)\n";
1270 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1271 die "unable to install init script (system uses upstart)\n";
1273 $self->ve_command ("insserv $base");
1280 my ($self, $opts) = @_;
1282 my $pkginfo = $self->pkginfo();
1283 my $veid = $self->{veid
};
1284 my $suite = $self->{config
}->{suite
};
1286 my $important = [ @{$self->{incl
}} ];
1290 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1292 if ($mta eq 'postfix') {
1293 push @$important, "postfix";
1296 foreach my $p (sort keys %$pkginfo) {
1297 next if grep { $p eq $_ } @{$self->{excl
}};
1298 my $pri = $pkginfo->{$p}->{priority
};
1300 next if $mta ne 'exim' && $p =~ m/exim/;
1301 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1303 push @$required, $p if $pri eq 'required';
1304 push @$important, $p if $pri eq 'important';
1305 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1309 $required = $self->closure ($closure, $required);
1310 $important = $self->closure ($closure, $important);
1312 if (!$opts->{minimal
}) {
1313 push @$standard, 'xbase-clients';
1314 $standard = $self->closure ($closure, $standard);
1317 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1318 # except those explicitly excluded
1319 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1320 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1321 foreach my $d (split (/,/, $mdeps)) {
1322 if ($d =~ m/^\s*(\S+)$/) {
1324 next if $closure->{$pkg};
1325 next if grep { $pkg eq $_ } @{$self->{excl
}};
1326 die "missing ubuntu-minimal package '$pkg'\n";
1329 if (!$opts->{minimal
}) {
1330 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1331 foreach my $d (split (/,/, $mdeps)) {
1332 if ($d =~ m/^\s*(\S+)$/) {
1334 next if $closure->{$pkg};
1335 next if grep { $pkg eq $_ } @{$self->{excl
}};
1336 die "missing ubuntu-standard package '$pkg'\n";
1342 # download/cache all files first
1343 $self->cache_packages ($required);
1344 $self->cache_packages ($important);
1345 $self->cache_packages ($standard);
1347 my $rootdir = $self->{rootfs
};
1349 # extract required packages first
1350 $self->logmsg ("create basic environment\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.xz$/m) {
1355 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1357 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1362 my $data = "Package: dpkg\n" .
1363 "Version: $pkginfo->{dpkg}->{version}\n" .
1364 "Status: install ok installed\n";
1366 write_file
($data, "$rootdir/var/lib/dpkg/status");
1367 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1368 write_file
("", "$rootdir/var/lib/dpkg/available");
1371 foreach my $ss (@{$self->{sources
}}) {
1372 my $url = $ss->{source
};
1373 my $comp = join (' ', @{$ss->{comp
}});
1374 $data .= "deb $url $ss->{suite} $comp\n\n";
1377 write_file
($data, "$rootdir/etc/apt/sources.list");
1379 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1380 write_file
($data, "$rootdir/etc/fstab", 0644);
1382 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1384 # avoid warnings about non-existent resolv.conf
1385 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1387 if ($suite eq 'focal' || $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1388 $suite eq 'bionic' || $suite eq 'artful' ||
1389 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1391 # no need to configure loopback device
1393 $data = "auto lo\niface lo inet loopback\n";
1394 mkdir "$rootdir/etc/network";
1395 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1399 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1401 # avoid warnings about missing default locale
1402 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1405 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1406 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1408 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1410 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1412 $self->logmsg ("initialize ld cache\n");
1413 $self->ve_command ("/sbin/ldconfig");
1414 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1416 $self->logmsg ("installing packages\n");
1418 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1420 $self->ve_dpkg ('install', 'dpkg');
1422 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1424 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1426 $self->ve_dpkg ('install', 'libc6');
1427 $self->ve_dpkg ('install', 'perl-base');
1429 unlink "$rootdir/usr/bin/awk";
1431 $self->ve_dpkg ('install', 'mawk');
1432 $self->ve_dpkg ('install', 'debconf');
1434 # unpack required packages
1435 foreach my $p (@$required) {
1436 $self->ve_dpkg ('unpack', $p);
1439 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1440 $self->ve_divert_add ("/sbin/init");
1441 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1443 # disable service activation
1444 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1445 $data = "#!/bin/sh\nexit 101\n";
1446 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1448 # disable start-stop-daemon
1449 $self->ve_divert_add ("/sbin/start-stop-daemon");
1453 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1455 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1458 $self->ve_divert_add ("/sbin/udevd");
1460 if ($suite eq 'etch') {
1461 # disable apache2 startup
1462 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
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') {
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";
1576 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1577 $self->run_command ("rm $filelist");
1579 if ($suite eq 'jaunty') {
1580 # remove sysctl setup (avoid warnings at startup)
1581 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1582 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1583 $self->run_command ("rm $filelist");
1590 my $veid = $self->{veid
};
1591 my $conffile = $self->{veconffile
};
1593 my $vestat = $self->ve_status();
1595 if (!$vestat->{exist
}) {
1596 $self->logmsg ("Please create the appliance first (bootstrap)");
1600 if (!$vestat->{running
}) {
1601 $self->run_command ("lxc-start -n $veid -f $conffile");
1604 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1607 sub ve_mysql_command
{
1608 my ($self, $sql, $password) = @_;
1610 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1611 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1613 $self->ve_command ("mysql", $sql);
1616 sub ve_mysql_bootstrap
{
1617 my ($self, $sql, $password) = @_;
1621 my $suite = $self->{config
}->{suite
};
1623 if ($suite eq 'jessie') {
1624 my $rootdir = $self->{rootfs
};
1625 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1628 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1629 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1632 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1633 "--skip-bdb --skip-innodb --skip-ndbcluster";
1636 $self->ve_command ($cmd, $sql);
1639 sub compute_required
{
1640 my ($self, $pkglist) = @_;
1642 my $pkginfo = $self->pkginfo();
1643 my $instpkgs = $self->read_installed ();
1646 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1648 return $self->closure ($closure, $pkglist);
1652 my ($self, $opts) = @_;
1654 my @supp = ('7.4', '8.1');
1655 my $pgversion = '8.1';
1657 my $suite = $self->{config
}->{suite
};
1659 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1662 } elsif ($suite eq 'squeeze') {
1665 } elsif ($suite eq 'wheezy') {
1668 } elsif ($suite eq 'jessie') {
1671 } elsif ($suite eq 'stretch') {
1674 } elsif ($suite eq 'buster') {
1677 } elsif ($suite eq 'bullseye') {
1678 # FIXME update on freeze!
1683 $pgversion = $opts->{version
} if $opts->{version
};
1685 die "unsupported postgres version '$pgversion'\n"
1686 if !grep { $pgversion eq $_; } @supp;
1688 my $rootdir = $self->{rootfs
};
1690 my $required = $self->compute_required (["postgresql-$pgversion"]);
1692 $self->cache_packages ($required);
1694 $self->ve_dpkg ('install', @$required);
1696 my $iscript = "postgresql-$pgversion";
1697 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1698 $suite eq 'stretch') {
1699 $iscript = 'postgresql';
1702 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1706 my ($self, $opts) = @_;
1708 my $password = $opts->{password
};
1709 my $rootdir = $self->{rootfs
};
1711 my $suite = $self->{config
}->{suite
};
1714 if ($suite eq 'squeeze') {
1716 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1719 die "task_mysql: unsupported suite '$suite'";
1722 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1724 $self->cache_packages ($required);
1726 $self->ve_dpkg ('install', @$required);
1728 # fix security (see /usr/bin/mysql_secure_installation)
1729 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1730 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1731 "FLUSH PRIVILEGES;\n";
1732 $self->ve_mysql_bootstrap ($sql);
1736 my $rpw = $password eq 'random' ?
'admin' : $password;
1738 my $sql = "USE mysql;\n" .
1739 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1740 "FLUSH PRIVILEGES
;\n";
1741 $self->ve_mysql_bootstrap ($sql);
1743 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1744 if ($password eq 'random') {
1745 $self->install_init_script ($script_mysql_randompw, 2, 20);
1749 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1753 my ($self, $opts) = @_;
1755 my $memlimit = $opts->{memlimit
};
1756 my $rootdir = $self->{rootfs
};
1758 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1760 $self->cache_packages ($required);
1762 $self->ve_dpkg ('install', @$required);
1765 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1770 my ($self, $pkglist, $unpack) = @_;
1772 my $required = $self->compute_required ($pkglist);
1774 $self->cache_packages ($required);
1776 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1780 my ($self, $distclean) = @_;
1782 unlink $self->{logfile
};
1783 unlink "$self->{targetname}.tar";
1784 unlink "$self->{targetname}.tar.gz";
1786 $self->ve_destroy ();
1789 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1791 rmtree
$self->{infodir
};