11 use POSIX qw
(LONG_MAX
);
15 # fixme: lock container ?
17 my $dablibdir = "/usr/lib/dab";
18 my $devicetar = "$dablibdir/devices.tar.gz";
19 my $default_env = "$dablibdir/scripts/defenv";
20 my $fake_init = "$dablibdir/scripts/init.pl";
21 my $script_ssh_init = "$dablibdir/scripts/ssh_gen_host_keys";
22 my $script_mysql_randompw = "$dablibdir/scripts/mysql_randompw";
23 my $script_init_urandom = "$dablibdir/scripts/init_urandom";
25 my $postfix_main_cf = <<EOD;
26 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
28 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
31 # appending .domain is the MUA's job.
32 append_dot_mydomain = no
34 # Uncomment the next line to generate "delayed mail" warnings
35 #delay_warning_time = 4h
37 alias_maps = hash:/etc/aliases
38 alias_database = hash:/etc/aliases
39 mydestination = \$myhostname, localhost.\$mydomain, localhost
41 mynetworks = 127.0.0.0/8
42 inet_interfaces = loopback-only
43 recipient_delimiter = +
45 compatibility_level = 2
49 # produce apt compatible filenames (/var/lib/apt/lists)
50 sub __url_to_filename
{
62 my $supported_suites = {
64 ostype
=> "debian-12",
67 ostype
=> "debian-11",
70 ostype
=> "debian-10",
73 ostype
=> "debian-9.0",
76 ostype
=> "debian-8.0",
79 ostype
=> "debian-7.0",
82 ostype
=> "debian-6.0",
85 ostype
=> "debian-5.0",
88 ostype
=> "debian-4.0",
94 ostype
=> "devuan-1.0",
98 ostype
=> "devuan-2.0",
101 ostype
=> "devuan-2.0",
104 ostype
=> "devuan-3.0",
107 ostype
=> "devuan-4.0",
112 ostype
=> "ubuntu-8.04",
116 ostype
=> "ubuntu-8.10",
120 ostype
=> "ubuntu-9.04",
124 ostype
=> "ubuntu-12.04",
128 ostype
=> "ubuntu-14.04",
132 ostype
=> "ubuntu-15.04",
136 ostype
=> "ubuntu-15.10",
140 ostype
=> "ubuntu-16.04",
144 ostype
=> "ubuntu-16.10",
148 ostype
=> "ubuntu-17.04",
152 ostype
=> "ubuntu-17.10",
156 ostype
=> "ubuntu-18.04",
160 ostype
=> "ubuntu-18.10",
164 ostype
=> "ubuntu-19.04",
168 ostype
=> "ubuntu-19.10",
172 ostype
=> "ubuntu-20.04",
176 ostype
=> "ubuntu-20.10",
180 ostype
=> "ubuntu-21.04",
184 ostype
=> "ubuntu-21.10",
192 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
195 $suiteinfo->{origin
} //= 'debian';
196 $suiteinfo->{suite
} //= $suite;
202 my ($self, $url, $path) = @_;
204 $self->logmsg ("download: $url\n");
205 my $tmpfn = "$path.tmp$$";
207 $self->run_command ("wget -q '$url' -O '$tmpfn'");
216 rename ($tmpfn, $path);
220 my ($data, $file, $perm) = @_;
222 die "no filename" if !$file;
226 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
227 die "unable to open file '$file'";
237 die "no filename" if !$file;
239 my $fh = IO
::File-
>new ($file) ||
240 die "unable to open file '$file'";
242 local $/; # slurp mode
256 my $fh = IO
::File-
>new ("<$filename") || return $res;
259 while (defined (my $line = <$fh>)) {
260 next if $line =~ m/^\#/;
261 next if $line =~ m/^\s*$/;
271 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
272 $res->{headline
} = $1;
273 chomp $res->{headline
};
276 $res->{description
} = $long;
277 chomp $res->{description
};
278 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
279 my ($key, $value) = (lc ($1), $2);
280 if ($key eq 'source' || $key eq 'mirror') {
281 push @{$res->{$key}}, $value;
283 die "duplicate key '$key'\n" if defined ($res->{$key});
284 $res->{$key} = $value;
287 die "unable to parse config file: $rec";
291 die "unable to parse config file" if $rec;
297 my ($self, $cmd, $input, $getoutput) = @_;
299 my $reader = IO
::File-
>new();
300 my $writer = IO
::File-
>new();
301 my $error = IO
::File-
>new();
305 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
309 if (ref ($cmd) eq 'ARRAY') {
310 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
312 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
319 if ($orig_pid != $$) {
320 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
327 print $writer $input if defined $input;
330 my $select = new IO
::Select
;
331 $select->add ($reader);
332 $select->add ($error);
335 my $logfd = $self->{logfd
};
337 while ($select->count) {
338 my @handles = $select->can_read ();
340 foreach my $h (@handles) {
342 my $count = sysread ($h, $buf, 4096);
343 if (!defined ($count)) {
345 die "command '$cmdstr' failed: $!";
347 $select->remove ($h) if !$count;
351 $res .= $buf if $getoutput;
358 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
366 $self->writelog (@_);
371 my $fd = $self->{logfd
};
375 sub __sample_config
{
379 my $arch = $self->{config
}->{architecture
};
381 my $ostype = $self->{config
}->{ostype
};
383 if ($ostype =~ m/^de(bi|vu)an-/) {
384 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
385 } elsif ($ostype =~ m/^ubuntu-/) {
386 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
388 die "unknown os type '$ostype'\n";
390 $data .= "lxc.uts.name = localhost\n";
391 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
400 if (my $fd = IO
::File-
>new (".veid")) {
407 $self->{working_dir
} = getcwd
;
408 $self->{veconffile
} = "$self->{working_dir}/config";
409 $self->{rootfs
} = "$self->{working_dir}/rootfs";
412 $self->{veid
} = $cid;
418 UUID
::generate
($uuid);
419 UUID
::unparse
($uuid, $uuid_str);
420 $self->{veid
} = $uuid_str;
422 my $fd = IO
::File-
>new (">.veid") ||
423 die "unable to write '.veid'\n";
424 print $fd "$self->{veid}\n";
427 my $cdata = $self->__sample_config();
429 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
430 die "unable to write lxc config file '$self->{veconffile}' - $!";
434 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
436 $self->logmsg ("allocated VE $self->{veid}\n");
438 return $self->{veid
};
442 my ($class, $config) = @_;
444 $class = ref ($class) || $class;
448 $config = read_config
('dab.conf') if !$config;
450 $self->{config
} = $config;
454 $self->{logfile
} = "logfile";
455 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
456 die "unable to open log file";
458 my $arch = $config->{architecture
};
459 die "no 'architecture' specified\n" if !$arch;
461 die "unsupported architecture '$arch'\n"
462 if $arch !~ m/^(i386|amd64)$/;
464 my $suite = $config->{suite
} || die "no 'suite' specified\n";
466 my $suiteinfo = get_suite_info
($suite);
467 $suite = $suiteinfo->{suite
};
468 $config->{ostype
} = $suiteinfo->{ostype
};
470 my $name = $config->{name
} || die "no 'name' specified\n";
472 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
473 die "illegal characters in name '$name'\n";
475 my $version = $config->{version
};
476 die "no 'version' specified\n" if !$version;
477 die "no 'section' specified\n" if !$config->{section
};
478 die "no 'description' specified\n" if !$config->{headline
};
479 die "no 'maintainer' specified\n" if !$config->{maintainer
};
481 if ($name =~ m/^$config->{ostype}/) {
482 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
484 $self->{targetname
} = "$config->{ostype}-${name}_" .
485 "${version}_$config->{architecture}";
488 if (!$config->{source
}) {
489 if (lc($suiteinfo->{origin
}) eq 'debian') {
490 if ($suite eq 'etch' || $suite eq 'lenny') {
491 push @{$config->{source
}}, (
492 'http://ftp.debian.org/debian SUITE main contrib',
493 'http://security.debian.org SUITE/updates main contrib',
495 } elsif ($suite eq 'bullseye' || $suite eq 'bookworm') {
496 push @{$config->{source
}}, (
497 "http://ftp.debian.org/debian SUITE main contrib",
498 "http://ftp.debian.org/debian SUITE-updates main contrib",
499 "http://security.debian.org SUITE-security main contrib",
502 push @{$config->{source
}}, (
503 "http://ftp.debian.org/debian SUITE main contrib",
504 "http://ftp.debian.org/debian SUITE-updates main contrib",
505 "http://security.debian.org SUITE/updates main contrib",
508 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
509 my $comp = "main restricted universe multiverse";
510 push @{$config->{source
}}, (
511 "http://archive.ubuntu.com/ubuntu SUITE $comp",
512 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
513 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
522 foreach my $s (@{$config->{source
}}) {
523 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
524 my ($url, $su, $components) = ($1, $3, $4);
525 $su =~ s/SUITE/$suite/;
526 $components =~ s/^\s+//;
527 $components =~ s/\s+$//;
529 foreach my $co (split (/\s+/, $components)) {
532 $ca = ['main'] if !$ca;
540 die "syntax error in source spezification '$s'\n";
544 foreach my $m (@{$config->{mirror
}}) {
545 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
546 my ($ms, $md) = ($1, $3);
548 foreach my $ss (@$sources) {
549 if ($ss->{source
} eq $ms) {
555 die "unusable mirror $ms\n" if !$found;
557 die "syntax error in mirror spezification '$m'\n";
561 $self->{sources
} = $sources;
563 $self->{infodir
} = "info";
565 $self->__allocate_ve ();
567 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
569 my $incl = [qw
(less ssh openssh-server logrotate
)];
571 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
572 pppoeconf nfs-common mtools ntp
)];
574 # ubuntu has too many dependencies on udev, so
575 # we cannot exclude it (instead we disable udevd)
577 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
578 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
579 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
580 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
581 || $suite eq 'hirsute' || $suite eq 'impish'
583 push @$incl, 'isc-dhcp-client';
584 push @$excl, qw(libmodule-build-perl);
585 } elsif ($suite eq 'trusty') {
586 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
587 } elsif ($suite eq 'precise') {
588 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
589 } elsif ($suite eq 'hardy') {
590 push @$excl, qw(kbd);
591 push @$excl, qw(apparmor apparmor-utils ntfs-3g
593 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
594 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
595 libntfs-3g28 ntfs-3g friendly-recovery);
596 } elsif ($suite eq 'jessie') {
597 push @$incl, 'sysvinit-core'; # avoid systemd and udev
598 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
599 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm memtest86+ parted);
600 } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye' || $suite eq 'bookworm') {
601 push @$excl, qw(module-init-tools pciutils hdparm memtest86+ parted);
603 push @$excl, qw(udev module-init-tools pciutils hdparm memtest86+ parted);
606 $self->{incl
} = $incl;
607 $self->{excl
} = $excl;
615 my $infodir = $self->{infodir
};
616 my $arch = $self->{config
}->{architecture
};
622 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
623 die "unable to open log file";
636 foreach my $ss (@{$self->{sources
}}) {
637 my $src = $ss->{mirror
} || $ss->{source
};
638 my $path = "dists/$ss->{suite}/Release";
639 my $url = "$src/$path";
640 my $target = __url_to_filename
("$ss->{source}/$path");
642 $self->download ($url, "$infodir/$target");
643 $self->download ("$url.gpg", "$infodir/$target.gpg");
644 # fixme: impl. verify (needs --keyring option)
648 warn "Release info ignored\n";
651 foreach my $comp (@{$ss->{comp
}}) {
652 foreach my $compressor (@$COMPRESSORS) {
653 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$compressor->{ext}";
654 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
655 my $pkgsrc = "$src/$path";
657 $self->download ($pkgsrc, $target);
658 $self->run_command ("$compressor->{decomp} '$target'");
661 print $logfd "could not download Packages.$compressor->{ext}\n";
671 my ($self, $filename, $size) = @_;
673 my $config = $self->{config
};
677 $data .= "Name: $config->{name}\n";
678 $data .= "Version: $config->{version}\n";
679 $data .= "Type: lxc\n";
680 $data .= "OS: $config->{ostype}\n";
681 $data .= "Section: $config->{section}\n";
682 $data .= "Maintainer: $config->{maintainer}\n";
683 $data .= "Architecture: $config->{architecture}\n";
684 $data .= "Installed-Size: $size\n";
687 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
688 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
689 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
692 $data .= "Description: $config->{headline}\n";
693 $data .= "$config->{description}\n" if $config->{description
};
695 write_file
($data, $filename, 0644);
699 my ($self, $opts) = @_;
701 my $suite = $self->{config
}->{suite
};
702 my $infodir = $self->{infodir
};
703 my $arch = $self->{config
}->{architecture
};
705 my $instpkgs = $self->read_installed ();
706 my $pkginfo = $self->pkginfo();
707 my $veid = $self->{veid
};
708 my $conffile = $self->{veconffile
};
709 my $rootdir = $self->{rootfs
};
711 my $vestat = $self->ve_status();
712 die "ve not running - unable to finalize\n" if !$vestat->{running
};
715 if (-f
"$rootdir/etc/init.d/mysql") {
716 $self->ve_command ("/etc/init.d/mysql stop");
719 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
720 unlink "$rootdir/root/.my.cnf";
723 if ($suite eq 'etch') {
724 # enable apache2 startup
725 if ($instpkgs->{apache2
}) {
726 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
728 unlink "$rootdir/etc/default/apache2";
731 $self->logmsg ("cleanup package status\n");
732 # prevent auto selection of all standard, required or important
733 # packages which are not installed
734 foreach my $pkg (keys %$pkginfo) {
735 my $pri = $pkginfo->{$pkg}->{priority
};
736 if ($pri && ($pri eq 'required' || $pri eq 'important'
737 || $pri eq 'standard')) {
738 if (!$instpkgs->{$pkg}) {
739 $self->ve_dpkg_set_selection ($pkg, 'purge');
744 $self->ve_command ("apt-get clean");
746 $self->logmsg ("update available package list\n");
748 $self->ve_command ("dpkg --clear-avail");
749 foreach my $ss (@{$self->{sources
}}) {
750 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
751 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
752 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
753 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
755 foreach my $comp (@{$ss->{comp
}}) {
756 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
757 "$comp/binary-$arch/Packages");
758 my $target = "/var/lib/apt/lists/$src";
759 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
760 $self->ve_command ("dpkg --merge-avail '$target'");
764 # set dselect default method
765 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
767 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
769 $self->ve_divert_remove ("/sbin/start-stop-daemon");
771 $self->ve_divert_remove ("/sbin/init");
773 # finally stop the VE
774 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
776 unlink "$rootdir/sbin/defenv";
778 unlink <$rootdir/root/dead.letter
*>;
780 unlink "$rootdir/var/log/init.log";
782 unlink "$rootdir/aquota.group";
784 unlink "$rootdir/aquota.user";
786 write_file
("", "$rootdir/var/log/syslog");
788 my $get_path_size = sub {
790 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
791 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
794 die "unable to detect size for '$path'\n";
798 $self->logmsg ("detecting final appliance size: ");
799 my $size = $get_path_size->($rootdir);
800 $self->logmsg ("$size MB\n");
802 $self->write_config ("$rootdir/etc/appliance.info", $size);
804 $self->logmsg ("creating final appliance archive\n");
806 my $target = "$self->{targetname}.tar";
808 my $compressor = $opts->{compressor
} // 'gz';
809 my $compressor2cmd_map = {
814 'zstd-max' => 'zstd -19 -T0', # maximal level where the decompressor can still run efficiently
816 my $compressor2ending = {
821 my $compressor_cmd = $compressor2cmd_map->{$compressor};
822 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
823 if !defined($compressor_cmd);
825 my $ending = $compressor2ending->{$compressor} // $compressor;
826 my $final_archive = "${target}.${ending}";
828 unlink $final_archive;
830 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
831 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
832 $self->run_command ("$compressor_cmd $target");
834 $self->logmsg ("detecting final commpressed appliance size: ");
835 $size = $get_path_size->($final_archive);
836 $self->logmsg ("$size MB\n");
838 $self->logmsg ("appliance archive: $final_archive\n");
844 my $rootdir = $self->{rootfs
};
846 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
848 open (PKGLST
, "<$pkgfilelist") ||
849 die "unable to open '$pkgfilelist'";
853 while (my $rec = <PKGLST
>) {
859 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
863 my $pkg = $res->{'package'};
864 if (my $status = $res->{status
}) {
865 my @sa = split (/\s+/, $status);
867 if ($stat && ($stat ne 'purge')) {
868 $pkglist->{$pkg} = $res;
881 my $veid = $self->{veid
};
883 my $res = { running
=> 0 };
885 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
887 my $filename = "/proc/net/unix";
889 # similar test is used by lcxcontainers.c: list_active_containers
890 my $fh = IO
::File-
>new ($filename, "r");
893 while (defined(my $line = <$fh>)) {
894 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
896 if ($path =~ m!^@/\S+/$veid/command$!) {
907 my ($self, $cmd, $input) = @_;
909 my $veid = $self->{veid
};
910 my $conffile = $self->{veconffile
};
912 if (ref ($cmd) eq 'ARRAY') {
913 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
914 $self->run_command ($cmd, $input);
916 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
920 # like ve_command, but pipes stdin correctly
922 my ($self, @cmd) = @_;
924 my $veid = $self->{veid
};
925 my $conffile = $self->{veconffile
};
928 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
929 'defenv', @cmd) || die "unable to exec command";
931 while (defined (my $line = <$reader>)) {
932 $self->logmsg ($line);
938 die "ve_exec failed - status $rc\n" if $rc != 0;
942 my ($self, $filename) = @_;
944 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
945 "--rename '$filename'");
947 sub ve_divert_remove
{
948 my ($self, $filename) = @_;
950 my $rootdir = $self->{rootfs
};
952 unlink "$rootdir/$filename";
953 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
956 sub ve_debconfig_set
{
957 my ($self, $dcdata) = @_;
959 my $rootdir = $self->{rootfs
};
960 my $cfgfile = "/tmp/debconf.txt";
961 write_file
($dcdata, "$rootdir/$cfgfile");
962 $self->ve_command ("debconf-set-selections $cfgfile");
963 unlink "$rootdir/$cfgfile";
966 sub ve_dpkg_set_selection
{
967 my ($self, $pkg, $status) = @_;
969 $self->ve_command ("dpkg --set-selections", "$pkg $status");
973 my ($self, $cmd, @pkglist) = @_;
975 return if !scalar (@pkglist);
977 my $pkginfo = $self->pkginfo();
979 my $rootdir = $self->{rootfs
};
980 my $cachedir = $self->{cachedir
};
984 foreach my $pkg (@pkglist) {
985 my $filename = $self->getpkgfile ($pkg);
986 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
987 push @files, "/$filename";
988 $self->logmsg ("$cmd: $pkg\n");
991 my $fl = join (' ', @files);
993 if ($cmd eq 'install') {
994 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
995 } elsif ($cmd eq 'unpack') {
996 $self->ve_command ("dpkg --force-depends --unpack $fl");
998 die "internal error";
1001 foreach my $fn (@files) { unlink "$rootdir$fn"; }
1007 my $veid = $self->{veid
}; # fixme
1008 my $conffile = $self->{veconffile
};
1010 my $vestat = $self->ve_status();
1011 if ($vestat->{running
}) {
1012 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1015 rmtree
$self->{rootfs
};
1016 unlink $self->{veconffile
};
1022 my $veid = $self->{veid
};
1023 my $conffile = $self->{veconffile
};
1025 $self->logmsg ("initialize VE $veid\n");
1027 my $vestat = $self->ve_status();
1028 if ($vestat->{running
}) {
1029 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1032 rmtree
$self->{rootfs
};
1033 mkpath
$self->{rootfs
};
1036 sub __deb_version_cmp
{
1037 my ($cur, $op, $new) = @_;
1039 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
1046 sub __parse_packages
{
1047 my ($pkginfo, $filename, $src) = @_;
1050 open (PKGLST
, "<$filename") ||
1051 die "unable to open '$filename'";
1053 while (my $rec = <PKGLST
>) {
1054 $rec =~ s/\n\s+/ /g;
1060 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
1064 my $pkg = $res->{'package'};
1065 if ($pkg && $res->{'filename'}) {
1067 if (my $info = $pkginfo->{$pkg}) {
1068 $cur = $info->{version
};
1070 my $new = $res->{version
};
1071 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1073 $res->{url
} = "$src/$res->{'filename'}";
1075 die "no url for package '$pkg'" if !$res->{url
};
1077 $pkginfo->{$pkg} = $res;
1088 return $self->{pkginfo
} if $self->{pkginfo
};
1090 my $infodir = $self->{infodir
};
1091 my $arch = $self->{config
}->{architecture
};
1093 my $availfn = "$infodir/available";
1098 # reading 'available' is faster, because it only contains latest version
1099 # (no need to do slow version compares)
1101 __parse_packages
($pkginfo, $availfn);
1102 $self->{pkginfo
} = $pkginfo;
1106 $self->logmsg ("generating available package list\n");
1108 foreach my $ss (@{$self->{sources
}}) {
1109 foreach my $comp (@{$ss->{comp
}}) {
1110 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1111 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1113 my $src = $ss->{mirror
} || $ss->{source
};
1115 __parse_packages
($pkginfo, $pkgfilelist, $src);
1119 if (my $dep = $self->{config
}->{depends
}) {
1120 foreach my $d (split (/,/, $dep)) {
1121 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1122 my ($pkg, $op, $rver) = ($1, $3, $4);
1123 $self->logmsg ("checking dependencies: $d\n");
1124 my $info = $pkginfo->{$pkg};
1125 die "package '$pkg' not available\n" if !$info;
1127 my $cver = $info->{version
};
1128 if (!__deb_version_cmp
($cver, $op, $rver)) {
1129 die "detected wrong version '$cver'\n";
1133 die "syntax error in depends field";
1138 $self->{pkginfo
} = $pkginfo;
1140 my $tmpfn = "$availfn.tmp$$";
1141 my $fd = IO
::File-
>new (">$tmpfn");
1142 foreach my $pkg (sort keys %$pkginfo) {
1143 my $info = $pkginfo->{$pkg};
1144 print $fd "package: $pkg\n";
1145 foreach my $k (sort keys %$info) {
1146 next if $k eq 'description';
1147 next if $k eq 'package';
1148 my $v = $info->{$k};
1149 print $fd "$k: $v\n" if $v;
1151 print $fd "description: $info->{description}\n" if $info->{description
};
1156 rename ($tmpfn, $availfn);
1161 sub __record_provides
{
1162 my ($pkginfo, $closure, $list, $skipself) = @_;
1164 foreach my $pname (@$list) {
1165 my $info = $pkginfo->{$pname};
1166 # fixme: if someone install packages directly using dpkg, there
1167 # is no entry in 'available', only in 'status'. In that case, we
1168 # should extract info from $instpkgs
1170 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1173 if (my $prov = $info->{provides
}) {
1174 my @pl = split (',', $prov);
1175 foreach my $p (@pl) {
1177 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1182 $closure->{$pname} = 1 if !$skipself;
1187 my ($self, $closure, $list) = @_;
1189 my $pkginfo = $self->pkginfo();
1191 # first, record provided packages
1192 __record_provides
($pkginfo, $closure, $list, 1);
1197 # then resolve dependencies
1198 foreach my $pname (@$list) {
1199 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1205 sub __closure_single
{
1206 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1210 $pname =~ s/:any$//;
1212 return if $closure->{$pname};
1214 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1216 my $dep = $info->{depends
};
1217 my $predep = $info->{'pre-depends'};
1219 my $size = $info->{size
};
1220 my $url = $info->{url
};
1222 $url || die "$pname: no url for package '$pname'";
1224 if (!$pkghash->{$pname}) {
1225 unshift @$pkglist, $pname;
1226 $pkghash->{$pname} = 1;
1229 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1231 $closure->{$pname} = 1;
1237 push @l, split (/,/, $predep) if $predep;
1238 push @l, split (/,/, $dep) if $dep;
1240 DEPEND
: foreach my $p (@l) {
1241 my @l1 = split (/\|/, $p);
1242 foreach my $p1 (@l1) {
1243 if ($p1 =~ m/^\s*(\S+).*/) {
1244 #printf (STDERR "$pname: $p --> $1\n");
1245 if ($closure->{$1}) {
1246 next DEPEND
; # dependency already met
1250 # search for non-excluded alternative
1252 foreach my $p1 (@l1) {
1253 if ($p1 =~ m/^\s*(\S+).*/) {
1254 next if grep { $1 eq $_ } @$excl;
1259 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1261 #printf (STDERR "$pname: $p --> $found\n");
1263 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1267 sub cache_packages
{
1268 my ($self, $pkglist) = @_;
1270 foreach my $pkg (@$pkglist) {
1271 $self->getpkgfile ($pkg);
1276 my ($self, $pkg) = @_;
1278 my $pkginfo = $self->pkginfo();
1279 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1280 my $cachedir = $self->{cachedir
};
1282 my $url = $info->{url
};
1285 if ($url =~ m
|/([^/]+.deb
)$|) {
1288 die "internal error";
1291 return $filename if -f
"$cachedir/$filename";
1295 $self->download ($url, "$cachedir/$filename");
1300 sub install_init_script
{
1301 my ($self, $script, $runlevel, $prio) = @_;
1303 my $suite = $self->{config
}->{suite
};
1304 my $rootdir = $self->{rootfs
};
1306 my $base = basename
($script);
1307 my $target = "$rootdir/etc/init.d/$base";
1309 $self->run_command ("install -m 0755 '$script' '$target'");
1310 if ($suite eq 'etch' || $suite eq 'lenny') {
1311 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1312 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1313 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1314 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1315 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
1316 || $suite eq 'hirsute' || $suite eq 'impish'
1318 die "unable to install init script (system uses systemd)\n";
1319 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1320 die "unable to install init script (system uses upstart)\n";
1322 $self->ve_command ("insserv $base");
1329 my ($self, $opts) = @_;
1331 my $pkginfo = $self->pkginfo();
1332 my $veid = $self->{veid
};
1333 my $suite = $self->{config
}->{suite
};
1335 my $important = [ @{$self->{incl
}} ];
1339 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1341 if ($mta eq 'postfix') {
1342 push @$important, "postfix";
1345 foreach my $p (sort keys %$pkginfo) {
1346 next if grep { $p eq $_ } @{$self->{excl
}};
1347 my $pri = $pkginfo->{$p}->{priority
};
1349 next if $mta ne 'exim' && $p =~ m/exim/;
1350 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1352 push @$required, $p if $pri eq 'required';
1353 push @$important, $p if $pri eq 'important';
1354 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1358 $required = $self->closure ($closure, $required);
1359 $important = $self->closure ($closure, $important);
1361 if (!$opts->{minimal
}) {
1362 push @$standard, 'xbase-clients';
1363 $standard = $self->closure ($closure, $standard);
1366 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1367 # except those explicitly excluded
1368 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1369 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1370 foreach my $d (split (/,/, $mdeps)) {
1371 if ($d =~ m/^\s*(\S+)$/) {
1373 next if $closure->{$pkg};
1374 next if grep { $pkg eq $_ } @{$self->{excl
}};
1375 die "missing ubuntu-minimal package '$pkg'\n";
1378 if (!$opts->{minimal
}) {
1379 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1380 foreach my $d (split (/,/, $mdeps)) {
1381 if ($d =~ m/^\s*(\S+)$/) {
1383 next if $closure->{$pkg};
1384 next if grep { $pkg eq $_ } @{$self->{excl
}};
1385 die "missing ubuntu-standard package '$pkg'\n";
1391 # download/cache all files first
1392 $self->cache_packages ($required);
1393 $self->cache_packages ($important);
1394 $self->cache_packages ($standard);
1396 my $rootdir = $self->{rootfs
};
1398 # extract required packages first
1399 $self->logmsg ("create basic environment\n");
1400 foreach my $p (@$required) {
1401 my $filename = $self->getpkgfile ($p);
1402 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1403 if ($content =~ m/^data.tar.xz$/m) {
1404 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1406 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1411 my $data = "Package: dpkg\n" .
1412 "Version: $pkginfo->{dpkg}->{version}\n" .
1413 "Status: install ok installed\n";
1415 write_file
($data, "$rootdir/var/lib/dpkg/status");
1416 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1417 write_file
("", "$rootdir/var/lib/dpkg/available");
1420 foreach my $ss (@{$self->{sources
}}) {
1421 my $url = $ss->{source
};
1422 my $comp = join (' ', @{$ss->{comp
}});
1423 $data .= "deb $url $ss->{suite} $comp\n\n";
1426 write_file
($data, "$rootdir/etc/apt/sources.list");
1428 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1429 write_file
($data, "$rootdir/etc/fstab", 0644);
1431 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1433 # avoid warnings about non-existent resolv.conf
1434 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1437 $suite eq 'impish' ||
1438 $suite eq 'hirsute' || $suite eq 'groovy' || $suite eq 'focal' ||
1439 $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1440 $suite eq 'bionic' || $suite eq 'artful' ||
1441 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1444 # no need to configure loopback device
1446 $data = "auto lo\niface lo inet loopback\n";
1447 mkdir "$rootdir/etc/network";
1448 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1452 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1454 # avoid warnings about missing default locale
1455 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1458 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1459 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1461 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1463 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1465 $self->logmsg ("initialize ld cache\n");
1466 $self->ve_command ("/sbin/ldconfig");
1467 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1469 $self->logmsg ("installing packages\n");
1471 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1473 $self->ve_dpkg ('install', 'dpkg');
1475 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1477 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1479 $self->ve_dpkg ('install', 'libc6');
1480 $self->ve_dpkg ('install', 'perl-base');
1482 unlink "$rootdir/usr/bin/awk";
1484 $self->ve_dpkg ('install', 'mawk');
1485 $self->ve_dpkg ('install', 'debconf');
1487 # unpack required packages
1488 foreach my $p (@$required) {
1489 $self->ve_dpkg ('unpack', $p);
1492 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1493 $self->ve_divert_add ("/sbin/init");
1494 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1496 # disable service activation
1497 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1498 $data = "#!/bin/sh\nexit 101\n";
1499 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1501 # disable start-stop-daemon
1502 $self->ve_divert_add ("/sbin/start-stop-daemon");
1506 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1508 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1511 $self->ve_divert_add ("/sbin/udevd");
1513 if ($suite eq 'etch') {
1514 # disable apache2 startup
1515 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1518 $self->logmsg ("configure required packages\n");
1519 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1521 # set postfix defaults
1522 if ($mta eq 'postfix') {
1523 $data = "postfix postfix/main_mailer_type select Local only\n";
1524 $self->ve_debconfig_set ($data);
1526 $data = "postmaster: root\nwebmaster: root\n";
1527 write_file
($data, "$rootdir/etc/aliases");
1530 if ($suite eq 'jaunty') {
1531 # jaunty does not create /var/run/network, so network startup fails.
1532 # so we do not use tmpfs for /var/run and /var/lock
1533 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1534 # and create the directory here
1535 $self->run_command ("mkdir $rootdir/var/run/network");
1538 # unpack base packages
1539 foreach my $p (@$important) {
1540 $self->ve_dpkg ('unpack', $p);
1544 if (-x
"$rootdir/sbin/ifconfig") {
1545 $self->ve_command ("ifconfig lo up");
1547 $self->ve_command ("ip link set lo up");
1550 $self->logmsg ("configure important packages\n");
1551 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1553 if (-d
"$rootdir/etc/event.d") {
1554 unlink <$rootdir/etc/event.d
/tty
*>;
1557 if (-f
"$rootdir/etc/inittab") {
1558 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1561 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1562 unlink "$rootdir/etc/mtab";
1563 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1566 $self->ve_command ("usermod -L root");
1568 if ($mta eq 'postfix') {
1569 $data = "postfix postfix/main_mailer_type select No configuration\n";
1570 $self->ve_debconfig_set ($data);
1572 unlink "$rootdir/etc/mailname";
1573 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1576 if (!$opts->{minimal
}) {
1577 # unpack standard packages
1578 foreach my $p (@$standard) {
1579 $self->ve_dpkg ('unpack', $p);
1582 $self->logmsg ("configure standard packages\n");
1583 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1586 # disable HWCLOCK access
1587 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1590 $self->ve_divert_add ("/usr/sbin/hald");
1592 # disable /dev/urandom init
1593 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1595 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1597 $self->ve_divert_add ("/sbin/klogd");
1600 # remove unnecessays sysctl entries to avoid warnings
1602 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1603 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1604 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1605 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1606 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1607 $self->run_command ($cmd);
1609 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1610 if (-f
$bindv6only) {
1612 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1613 $cmd .= " -i '$bindv6only'";
1614 $self->run_command ($cmd);
1617 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1618 # disable tty init (console-setup)
1620 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1621 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1622 $self->run_command ($cmd);
1625 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1626 # remove sysctl setup (avoid warnings at startup)
1627 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1628 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1629 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1630 $self->run_command ("rm $filelist");
1633 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1634 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1641 my $veid = $self->{veid
};
1642 my $conffile = $self->{veconffile
};
1644 my $vestat = $self->ve_status();
1646 if (!$vestat->{exist
}) {
1647 $self->logmsg ("Please create the appliance first (bootstrap)");
1651 if (!$vestat->{running
}) {
1652 $self->run_command ("lxc-start -n $veid -f $conffile");
1655 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1658 sub ve_mysql_command
{
1659 my ($self, $sql, $password) = @_;
1661 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1662 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1664 $self->ve_command ("mysql", $sql);
1667 sub ve_mysql_bootstrap
{
1668 my ($self, $sql, $password) = @_;
1672 my $suite = $self->{config
}->{suite
};
1674 if ($suite eq 'jessie') {
1675 my $rootdir = $self->{rootfs
};
1676 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1679 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1680 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1683 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1684 "--skip-bdb --skip-innodb --skip-ndbcluster";
1687 $self->ve_command ($cmd, $sql);
1690 sub compute_required
{
1691 my ($self, $pkglist) = @_;
1693 my $pkginfo = $self->pkginfo();
1694 my $instpkgs = $self->read_installed ();
1697 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1699 return $self->closure ($closure, $pkglist);
1703 my ($self, $opts) = @_;
1705 my @supp = ('7.4', '8.1');
1706 my $pgversion = '8.1';
1708 my $suite = $self->{config
}->{suite
};
1710 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1713 } elsif ($suite eq 'squeeze') {
1716 } elsif ($suite eq 'wheezy') {
1719 } elsif ($suite eq 'jessie') {
1722 } elsif ($suite eq 'stretch') {
1725 } elsif ($suite eq 'buster') {
1728 } elsif ($suite eq 'bullseye') {
1731 } elsif ($suite eq 'bookworm') {
1732 # FIXME: update once froozen
1737 $pgversion = $opts->{version
} if $opts->{version
};
1739 die "unsupported postgres version '$pgversion'\n"
1740 if !grep { $pgversion eq $_; } @supp;
1742 my $rootdir = $self->{rootfs
};
1744 my $required = $self->compute_required (["postgresql-$pgversion"]);
1746 $self->cache_packages ($required);
1748 $self->ve_dpkg ('install', @$required);
1750 my $iscript = "postgresql-$pgversion";
1751 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1752 $suite eq 'stretch') {
1753 $iscript = 'postgresql';
1756 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1760 my ($self, $opts) = @_;
1762 my $password = $opts->{password
};
1763 my $rootdir = $self->{rootfs
};
1765 my $suite = $self->{config
}->{suite
};
1768 if ($suite eq 'squeeze') {
1770 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1773 die "task_mysql: unsupported suite '$suite'";
1776 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1778 $self->cache_packages ($required);
1780 $self->ve_dpkg ('install', @$required);
1782 # fix security (see /usr/bin/mysql_secure_installation)
1783 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1784 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1785 "FLUSH PRIVILEGES;\n";
1786 $self->ve_mysql_bootstrap ($sql);
1790 my $rpw = $password eq 'random' ?
'admin' : $password;
1792 my $sql = "USE mysql;\n" .
1793 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1794 "FLUSH PRIVILEGES
;\n";
1795 $self->ve_mysql_bootstrap ($sql);
1797 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1798 if ($password eq 'random') {
1799 $self->install_init_script ($script_mysql_randompw, 2, 20);
1803 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1807 my ($self, $opts) = @_;
1809 my $memlimit = $opts->{memlimit
};
1810 my $rootdir = $self->{rootfs
};
1812 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1814 $self->cache_packages ($required);
1816 $self->ve_dpkg ('install', @$required);
1819 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1824 my ($self, $pkglist, $unpack) = @_;
1826 my $required = $self->compute_required ($pkglist);
1828 $self->cache_packages ($required);
1830 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1834 my ($self, $distclean) = @_;
1836 unlink $self->{logfile
};
1837 unlink "$self->{targetname}.tar";
1838 unlink "$self->{targetname}.tar.gz";
1840 $self->ve_destroy ();
1843 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1845 rmtree
$self->{infodir
};