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",
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",
167 ostype
=> "ubuntu-20.10",
175 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
178 $suiteinfo->{origin
} //= 'debian';
179 $suiteinfo->{suite
} //= $suite;
185 my ($self, $url, $path) = @_;
187 $self->logmsg ("download: $url\n");
188 my $tmpfn = "$path.tmp$$";
190 $self->run_command ("wget -q '$url' -O '$tmpfn'");
199 rename ($tmpfn, $path);
203 my ($data, $file, $perm) = @_;
205 die "no filename" if !$file;
209 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
210 die "unable to open file '$file'";
220 die "no filename" if !$file;
222 my $fh = IO
::File-
>new ($file) ||
223 die "unable to open file '$file'";
225 local $/; # slurp mode
239 my $fh = IO
::File-
>new ("<$filename") || return $res;
242 while (defined (my $line = <$fh>)) {
243 next if $line =~ m/^\#/;
244 next if $line =~ m/^\s*$/;
254 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
255 $res->{headline
} = $1;
256 chomp $res->{headline
};
259 $res->{description
} = $long;
260 chomp $res->{description
};
261 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
262 my ($key, $value) = (lc ($1), $2);
263 if ($key eq 'source' || $key eq 'mirror') {
264 push @{$res->{$key}}, $value;
266 die "duplicate key '$key'\n" if defined ($res->{$key});
267 $res->{$key} = $value;
270 die "unable to parse config file: $rec";
274 die "unable to parse config file" if $rec;
280 my ($self, $cmd, $input, $getoutput) = @_;
282 my $reader = IO
::File-
>new();
283 my $writer = IO
::File-
>new();
284 my $error = IO
::File-
>new();
288 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
292 if (ref ($cmd) eq 'ARRAY') {
293 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
295 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
302 if ($orig_pid != $$) {
303 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
310 print $writer $input if defined $input;
313 my $select = new IO
::Select
;
314 $select->add ($reader);
315 $select->add ($error);
318 my $logfd = $self->{logfd
};
320 while ($select->count) {
321 my @handles = $select->can_read ();
323 foreach my $h (@handles) {
325 my $count = sysread ($h, $buf, 4096);
326 if (!defined ($count)) {
328 die "command '$cmdstr' failed: $!";
330 $select->remove ($h) if !$count;
334 $res .= $buf if $getoutput;
341 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
349 $self->writelog (@_);
354 my $fd = $self->{logfd
};
358 sub __sample_config
{
362 my $arch = $self->{config
}->{architecture
};
364 my $ostype = $self->{config
}->{ostype
};
366 if ($ostype =~ m/^de(bi|vu)an-/) {
367 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
368 } elsif ($ostype =~ m/^ubuntu-/) {
369 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
371 die "unknown os type '$ostype'\n";
373 $data .= "lxc.uts.name = localhost\n";
374 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
383 if (my $fd = IO
::File-
>new (".veid")) {
390 $self->{working_dir
} = getcwd
;
391 $self->{veconffile
} = "$self->{working_dir}/config";
392 $self->{rootfs
} = "$self->{working_dir}/rootfs";
395 $self->{veid
} = $cid;
401 UUID
::generate
($uuid);
402 UUID
::unparse
($uuid, $uuid_str);
403 $self->{veid
} = $uuid_str;
405 my $fd = IO
::File-
>new (">.veid") ||
406 die "unable to write '.veid'\n";
407 print $fd "$self->{veid}\n";
410 my $cdata = $self->__sample_config();
412 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
413 die "unable to write lxc config file '$self->{veconffile}' - $!";
417 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
419 $self->logmsg ("allocated VE $self->{veid}\n");
421 return $self->{veid
};
425 my ($class, $config) = @_;
427 $class = ref ($class) || $class;
431 $config = read_config
('dab.conf') if !$config;
433 $self->{config
} = $config;
437 $self->{logfile
} = "logfile";
438 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
439 die "unable to open log file";
441 my $arch = $config->{architecture
};
442 die "no 'architecture' specified\n" if !$arch;
444 die "unsupported architecture '$arch'\n"
445 if $arch !~ m/^(i386|amd64)$/;
447 my $suite = $config->{suite
} || die "no 'suite' specified\n";
449 my $suiteinfo = get_suite_info
($suite);
450 $suite = $suiteinfo->{suite
};
451 $config->{ostype
} = $suiteinfo->{ostype
};
453 my $name = $config->{name
} || die "no 'name' specified\n";
455 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
456 die "illegal characters in name '$name'\n";
458 my $version = $config->{version
};
459 die "no 'version' specified\n" if !$version;
460 die "no 'section' specified\n" if !$config->{section
};
461 die "no 'description' specified\n" if !$config->{headline
};
462 die "no 'maintainer' specified\n" if !$config->{maintainer
};
464 if ($name =~ m/^$config->{ostype}/) {
465 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
467 $self->{targetname
} = "$config->{ostype}-${name}_" .
468 "${version}_$config->{architecture}";
471 if (!$config->{source
}) {
472 if (lc($suiteinfo->{origin
}) eq 'debian') {
473 if ($suite eq 'etch' || $suite eq 'lenny') {
474 push @{$config->{source
}}, (
475 'http://ftp.debian.org/debian SUITE main contrib',
476 'http://security.debian.org SUITE/updates main contrib',
478 } elsif ($suite eq 'bullseye') {
479 push @{$config->{source
}}, (
480 "http://ftp.debian.org/debian SUITE main contrib",
481 "http://ftp.debian.org/debian SUITE-updates main contrib",
482 "http://security.debian.org SUITE-security main contrib",
485 push @{$config->{source
}}, (
486 "http://ftp.debian.org/debian SUITE main contrib",
487 "http://ftp.debian.org/debian SUITE-updates main contrib",
488 "http://security.debian.org SUITE/updates main contrib",
491 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
492 my $comp = "main restricted universe multiverse";
493 push @{$config->{source
}}, (
494 "http://archive.ubuntu.com/ubuntu SUITE $comp",
495 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
496 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
505 foreach my $s (@{$config->{source
}}) {
506 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
507 my ($url, $su, $components) = ($1, $3, $4);
508 $su =~ s/SUITE/$suite/;
509 $components =~ s/^\s+//;
510 $components =~ s/\s+$//;
512 foreach my $co (split (/\s+/, $components)) {
515 $ca = ['main'] if !$ca;
523 die "syntax error in source spezification '$s'\n";
527 foreach my $m (@{$config->{mirror
}}) {
528 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
529 my ($ms, $md) = ($1, $3);
531 foreach my $ss (@$sources) {
532 if ($ss->{source
} eq $ms) {
538 die "unusable mirror $ms\n" if !$found;
540 die "syntax error in mirror spezification '$m'\n";
544 $self->{sources
} = $sources;
546 $self->{infodir
} = "info";
548 $self->__allocate_ve ();
550 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
552 my $incl = [qw
(less ssh openssh-server logrotate
)];
554 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
555 pppoeconf nfs-common mtools ntp
)];
557 # ubuntu has too many dependencies on udev, so
558 # we cannot exclude it (instead we disable udevd)
560 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
561 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
562 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
563 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy') {
564 push @$incl, 'isc-dhcp-client';
565 push @$excl, qw(libmodule-build-perl);
566 } elsif ($suite eq 'trusty') {
567 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
568 } elsif ($suite eq 'precise') {
569 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
570 } elsif ($suite eq 'hardy') {
571 push @$excl, qw(kbd);
572 push @$excl, qw(apparmor apparmor-utils ntfs-3g
574 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
575 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
576 libntfs-3g28 ntfs-3g friendly-recovery);
577 } elsif ($suite eq 'jessie') {
578 push @$incl, 'sysvinit-core'; # avoid systemd and udev
579 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
580 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm
582 } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye') {
583 push @$excl, qw(module-init-tools pciutils hdparm
586 push @$excl, qw(udev module-init-tools pciutils hdparm
590 $self->{incl
} = $incl;
591 $self->{excl
} = $excl;
599 my $infodir = $self->{infodir
};
600 my $arch = $self->{config
}->{architecture
};
606 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
607 die "unable to open log file";
609 # FIXME: seems a bit like a hacky way??
614 if ($self->{config
}->{suite
} eq 'bullseye') {
621 foreach my $ss (@{$self->{sources
}}) {
622 my $src = $ss->{mirror
} || $ss->{source
};
623 my $path = "dists/$ss->{suite}/Release";
624 my $url = "$src/$path";
625 my $target = __url_to_filename
("$ss->{source}/$path");
627 $self->download ($url, "$infodir/$target");
628 $self->download ("$url.gpg", "$infodir/$target.gpg");
629 # fixme: impl. verify (needs --keyring option)
633 warn "Release info ignored\n";
636 foreach my $comp (@{$ss->{comp
}}) {
637 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
638 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
639 my $pkgsrc = "$src/$path";
640 $self->download ($pkgsrc, $target);
641 $self->run_command ("$COMPRESSOR->{decomp} '$target'");
647 my ($self, $filename, $size) = @_;
649 my $config = $self->{config
};
653 $data .= "Name: $config->{name}\n";
654 $data .= "Version: $config->{version}\n";
655 $data .= "Type: lxc\n";
656 $data .= "OS: $config->{ostype}\n";
657 $data .= "Section: $config->{section}\n";
658 $data .= "Maintainer: $config->{maintainer}\n";
659 $data .= "Architecture: $config->{architecture}\n";
660 $data .= "Installed-Size: $size\n";
663 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
664 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
665 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
668 $data .= "Description: $config->{headline}\n";
669 $data .= "$config->{description}\n" if $config->{description
};
671 write_file
($data, $filename, 0644);
675 my ($self, $opts) = @_;
677 my $suite = $self->{config
}->{suite
};
678 my $infodir = $self->{infodir
};
679 my $arch = $self->{config
}->{architecture
};
681 my $instpkgs = $self->read_installed ();
682 my $pkginfo = $self->pkginfo();
683 my $veid = $self->{veid
};
684 my $conffile = $self->{veconffile
};
685 my $rootdir = $self->{rootfs
};
687 my $vestat = $self->ve_status();
688 die "ve not running - unable to finalize\n" if !$vestat->{running
};
691 if (-f
"$rootdir/etc/init.d/mysql") {
692 $self->ve_command ("/etc/init.d/mysql stop");
695 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
696 unlink "$rootdir/root/.my.cnf";
699 if ($suite eq 'etch') {
700 # enable apache2 startup
701 if ($instpkgs->{apache2
}) {
702 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
704 unlink "$rootdir/etc/default/apache2";
707 $self->logmsg ("cleanup package status\n");
708 # prevent auto selection of all standard, required or important
709 # packages which are not installed
710 foreach my $pkg (keys %$pkginfo) {
711 my $pri = $pkginfo->{$pkg}->{priority
};
712 if ($pri && ($pri eq 'required' || $pri eq 'important'
713 || $pri eq 'standard')) {
714 if (!$instpkgs->{$pkg}) {
715 $self->ve_dpkg_set_selection ($pkg, 'purge');
720 $self->ve_command ("apt-get clean");
722 $self->logmsg ("update available package list\n");
724 $self->ve_command ("dpkg --clear-avail");
725 foreach my $ss (@{$self->{sources
}}) {
726 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
727 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
728 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
729 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
731 foreach my $comp (@{$ss->{comp
}}) {
732 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
733 "$comp/binary-$arch/Packages");
734 my $target = "/var/lib/apt/lists/$src";
735 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
736 $self->ve_command ("dpkg --merge-avail '$target'");
740 # set dselect default method
741 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
743 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
745 $self->ve_divert_remove ("/sbin/start-stop-daemon");
747 $self->ve_divert_remove ("/sbin/init");
749 # finally stop the VE
750 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
752 unlink "$rootdir/sbin/defenv";
754 unlink <$rootdir/root/dead.letter
*>;
756 unlink "$rootdir/var/log/init.log";
758 unlink "$rootdir/aquota.group";
760 unlink "$rootdir/aquota.user";
762 write_file
("", "$rootdir/var/log/syslog");
764 my $get_path_size = sub {
766 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
767 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
770 die "unable to detect size for '$path'\n";
774 $self->logmsg ("detecting final appliance size: ");
775 my $size = $get_path_size->($rootdir);
776 $self->logmsg ("$size MB\n");
778 $self->write_config ("$rootdir/etc/appliance.info", $size);
780 $self->logmsg ("creating final appliance archive\n");
782 my $target = "$self->{targetname}.tar";
784 my $compressor = $opts->{compressor
} // 'gz';
785 my $compressor2cmd_map = {
789 my $compressor_cmd = $compressor2cmd_map->{$compressor};
790 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
791 if !defined($compressor_cmd);
793 my $final_archive = "${target}.${compressor}";
795 unlink $final_archive;
797 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
798 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
799 $self->run_command ("$compressor_cmd $target");
801 $self->logmsg ("detecting final commpressed appliance size: ");
802 $size = $get_path_size->($final_archive);
803 $self->logmsg ("$size MB\n");
805 $self->logmsg ("appliance archive: $final_archive\n");
811 my $rootdir = $self->{rootfs
};
813 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
815 open (PKGLST
, "<$pkgfilelist") ||
816 die "unable to open '$pkgfilelist'";
820 while (my $rec = <PKGLST
>) {
826 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
830 my $pkg = $res->{'package'};
831 if (my $status = $res->{status
}) {
832 my @sa = split (/\s+/, $status);
834 if ($stat && ($stat ne 'purge')) {
835 $pkglist->{$pkg} = $res;
848 my $veid = $self->{veid
};
850 my $res = { running
=> 0 };
852 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
854 my $filename = "/proc/net/unix";
856 # similar test is used by lcxcontainers.c: list_active_containers
857 my $fh = IO
::File-
>new ($filename, "r");
860 while (defined(my $line = <$fh>)) {
861 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
863 if ($path =~ m!^@/\S+/$veid/command$!) {
874 my ($self, $cmd, $input) = @_;
876 my $veid = $self->{veid
};
877 my $conffile = $self->{veconffile
};
879 if (ref ($cmd) eq 'ARRAY') {
880 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
881 $self->run_command ($cmd, $input);
883 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
887 # like ve_command, but pipes stdin correctly
889 my ($self, @cmd) = @_;
891 my $veid = $self->{veid
};
892 my $conffile = $self->{veconffile
};
895 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
896 'defenv', @cmd) || die "unable to exec command";
898 while (defined (my $line = <$reader>)) {
899 $self->logmsg ($line);
905 die "ve_exec failed - status $rc\n" if $rc != 0;
909 my ($self, $filename) = @_;
911 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
912 "--rename '$filename'");
914 sub ve_divert_remove
{
915 my ($self, $filename) = @_;
917 my $rootdir = $self->{rootfs
};
919 unlink "$rootdir/$filename";
920 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
923 sub ve_debconfig_set
{
924 my ($self, $dcdata) = @_;
926 my $rootdir = $self->{rootfs
};
927 my $cfgfile = "/tmp/debconf.txt";
928 write_file
($dcdata, "$rootdir/$cfgfile");
929 $self->ve_command ("debconf-set-selections $cfgfile");
930 unlink "$rootdir/$cfgfile";
933 sub ve_dpkg_set_selection
{
934 my ($self, $pkg, $status) = @_;
936 $self->ve_command ("dpkg --set-selections", "$pkg $status");
940 my ($self, $cmd, @pkglist) = @_;
942 return if !scalar (@pkglist);
944 my $pkginfo = $self->pkginfo();
946 my $rootdir = $self->{rootfs
};
947 my $cachedir = $self->{cachedir
};
951 foreach my $pkg (@pkglist) {
952 my $filename = $self->getpkgfile ($pkg);
953 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
954 push @files, "/$filename";
955 $self->logmsg ("$cmd: $pkg\n");
958 my $fl = join (' ', @files);
960 if ($cmd eq 'install') {
961 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
962 } elsif ($cmd eq 'unpack') {
963 $self->ve_command ("dpkg --force-depends --unpack $fl");
965 die "internal error";
968 foreach my $fn (@files) { unlink "$rootdir$fn"; }
974 my $veid = $self->{veid
}; # fixme
975 my $conffile = $self->{veconffile
};
977 my $vestat = $self->ve_status();
978 if ($vestat->{running
}) {
979 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
982 rmtree
$self->{rootfs
};
983 unlink $self->{veconffile
};
989 my $veid = $self->{veid
};
990 my $conffile = $self->{veconffile
};
992 $self->logmsg ("initialize VE $veid\n");
994 my $vestat = $self->ve_status();
995 if ($vestat->{running
}) {
996 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
999 rmtree
$self->{rootfs
};
1000 mkpath
$self->{rootfs
};
1003 sub __deb_version_cmp
{
1004 my ($cur, $op, $new) = @_;
1006 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
1013 sub __parse_packages
{
1014 my ($pkginfo, $filename, $src) = @_;
1017 open (PKGLST
, "<$filename") ||
1018 die "unable to open '$filename'";
1020 while (my $rec = <PKGLST
>) {
1021 $rec =~ s/\n\s+/ /g;
1027 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
1031 my $pkg = $res->{'package'};
1032 if ($pkg && $res->{'filename'}) {
1034 if (my $info = $pkginfo->{$pkg}) {
1035 $cur = $info->{version
};
1037 my $new = $res->{version
};
1038 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1040 $res->{url
} = "$src/$res->{'filename'}";
1042 die "no url for package '$pkg'" if !$res->{url
};
1044 $pkginfo->{$pkg} = $res;
1055 return $self->{pkginfo
} if $self->{pkginfo
};
1057 my $infodir = $self->{infodir
};
1058 my $arch = $self->{config
}->{architecture
};
1060 my $availfn = "$infodir/available";
1065 # reading 'available' is faster, because it only contains latest version
1066 # (no need to do slow version compares)
1068 __parse_packages
($pkginfo, $availfn);
1069 $self->{pkginfo
} = $pkginfo;
1073 $self->logmsg ("generating available package list\n");
1075 foreach my $ss (@{$self->{sources
}}) {
1076 foreach my $comp (@{$ss->{comp
}}) {
1077 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1078 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1080 my $src = $ss->{mirror
} || $ss->{source
};
1082 __parse_packages
($pkginfo, $pkgfilelist, $src);
1086 if (my $dep = $self->{config
}->{depends
}) {
1087 foreach my $d (split (/,/, $dep)) {
1088 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1089 my ($pkg, $op, $rver) = ($1, $3, $4);
1090 $self->logmsg ("checking dependencies: $d\n");
1091 my $info = $pkginfo->{$pkg};
1092 die "package '$pkg' not available\n" if !$info;
1094 my $cver = $info->{version
};
1095 if (!__deb_version_cmp
($cver, $op, $rver)) {
1096 die "detected wrong version '$cver'\n";
1100 die "syntax error in depends field";
1105 $self->{pkginfo
} = $pkginfo;
1107 my $tmpfn = "$availfn.tmp$$";
1108 my $fd = IO
::File-
>new (">$tmpfn");
1109 foreach my $pkg (sort keys %$pkginfo) {
1110 my $info = $pkginfo->{$pkg};
1111 print $fd "package: $pkg\n";
1112 foreach my $k (sort keys %$info) {
1113 next if $k eq 'description';
1114 next if $k eq 'package';
1115 my $v = $info->{$k};
1116 print $fd "$k: $v\n" if $v;
1118 print $fd "description: $info->{description}\n" if $info->{description
};
1123 rename ($tmpfn, $availfn);
1128 sub __record_provides
{
1129 my ($pkginfo, $closure, $list, $skipself) = @_;
1131 foreach my $pname (@$list) {
1132 my $info = $pkginfo->{$pname};
1133 # fixme: if someone install packages directly using dpkg, there
1134 # is no entry in 'available', only in 'status'. In that case, we
1135 # should extract info from $instpkgs
1137 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1140 if (my $prov = $info->{provides
}) {
1141 my @pl = split (',', $prov);
1142 foreach my $p (@pl) {
1144 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1149 $closure->{$pname} = 1 if !$skipself;
1154 my ($self, $closure, $list) = @_;
1156 my $pkginfo = $self->pkginfo();
1158 # first, record provided packages
1159 __record_provides
($pkginfo, $closure, $list, 1);
1164 # then resolve dependencies
1165 foreach my $pname (@$list) {
1166 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1172 sub __closure_single
{
1173 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1177 $pname =~ s/:any$//;
1179 return if $closure->{$pname};
1181 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1183 my $dep = $info->{depends
};
1184 my $predep = $info->{'pre-depends'};
1186 my $size = $info->{size
};
1187 my $url = $info->{url
};
1189 $url || die "$pname: no url for package '$pname'";
1191 if (!$pkghash->{$pname}) {
1192 unshift @$pkglist, $pname;
1193 $pkghash->{$pname} = 1;
1196 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1198 $closure->{$pname} = 1;
1204 push @l, split (/,/, $predep) if $predep;
1205 push @l, split (/,/, $dep) if $dep;
1207 DEPEND
: foreach my $p (@l) {
1208 my @l1 = split (/\|/, $p);
1209 foreach my $p1 (@l1) {
1210 if ($p1 =~ m/^\s*(\S+).*/) {
1211 #printf (STDERR "$pname: $p --> $1\n");
1212 if ($closure->{$1}) {
1213 next DEPEND
; # dependency already met
1217 # search for non-excluded alternative
1219 foreach my $p1 (@l1) {
1220 if ($p1 =~ m/^\s*(\S+).*/) {
1221 next if grep { $1 eq $_ } @$excl;
1226 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1228 #printf (STDERR "$pname: $p --> $found\n");
1230 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1234 sub cache_packages
{
1235 my ($self, $pkglist) = @_;
1237 foreach my $pkg (@$pkglist) {
1238 $self->getpkgfile ($pkg);
1243 my ($self, $pkg) = @_;
1245 my $pkginfo = $self->pkginfo();
1246 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1247 my $cachedir = $self->{cachedir
};
1249 my $url = $info->{url
};
1252 if ($url =~ m
|/([^/]+.deb
)$|) {
1255 die "internal error";
1258 return $filename if -f
"$cachedir/$filename";
1262 $self->download ($url, "$cachedir/$filename");
1267 sub install_init_script
{
1268 my ($self, $script, $runlevel, $prio) = @_;
1270 my $suite = $self->{config
}->{suite
};
1271 my $rootdir = $self->{rootfs
};
1273 my $base = basename
($script);
1274 my $target = "$rootdir/etc/init.d/$base";
1276 $self->run_command ("install -m 0755 '$script' '$target'");
1277 if ($suite eq 'etch' || $suite eq 'lenny') {
1278 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1279 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1280 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1281 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1282 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy') {
1283 die "unable to install init script (system uses systemd)\n";
1284 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1285 die "unable to install init script (system uses upstart)\n";
1287 $self->ve_command ("insserv $base");
1294 my ($self, $opts) = @_;
1296 my $pkginfo = $self->pkginfo();
1297 my $veid = $self->{veid
};
1298 my $suite = $self->{config
}->{suite
};
1300 my $important = [ @{$self->{incl
}} ];
1304 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1306 if ($mta eq 'postfix') {
1307 push @$important, "postfix";
1310 foreach my $p (sort keys %$pkginfo) {
1311 next if grep { $p eq $_ } @{$self->{excl
}};
1312 my $pri = $pkginfo->{$p}->{priority
};
1314 next if $mta ne 'exim' && $p =~ m/exim/;
1315 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1317 push @$required, $p if $pri eq 'required';
1318 push @$important, $p if $pri eq 'important';
1319 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1323 $required = $self->closure ($closure, $required);
1324 $important = $self->closure ($closure, $important);
1326 if (!$opts->{minimal
}) {
1327 push @$standard, 'xbase-clients';
1328 $standard = $self->closure ($closure, $standard);
1331 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1332 # except those explicitly excluded
1333 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1334 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1335 foreach my $d (split (/,/, $mdeps)) {
1336 if ($d =~ m/^\s*(\S+)$/) {
1338 next if $closure->{$pkg};
1339 next if grep { $pkg eq $_ } @{$self->{excl
}};
1340 die "missing ubuntu-minimal package '$pkg'\n";
1343 if (!$opts->{minimal
}) {
1344 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1345 foreach my $d (split (/,/, $mdeps)) {
1346 if ($d =~ m/^\s*(\S+)$/) {
1348 next if $closure->{$pkg};
1349 next if grep { $pkg eq $_ } @{$self->{excl
}};
1350 die "missing ubuntu-standard package '$pkg'\n";
1356 # download/cache all files first
1357 $self->cache_packages ($required);
1358 $self->cache_packages ($important);
1359 $self->cache_packages ($standard);
1361 my $rootdir = $self->{rootfs
};
1363 # extract required packages first
1364 $self->logmsg ("create basic environment\n");
1365 foreach my $p (@$required) {
1366 my $filename = $self->getpkgfile ($p);
1367 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1368 if ($content =~ m/^data.tar.xz$/m) {
1369 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1371 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1376 my $data = "Package: dpkg\n" .
1377 "Version: $pkginfo->{dpkg}->{version}\n" .
1378 "Status: install ok installed\n";
1380 write_file
($data, "$rootdir/var/lib/dpkg/status");
1381 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1382 write_file
("", "$rootdir/var/lib/dpkg/available");
1385 foreach my $ss (@{$self->{sources
}}) {
1386 my $url = $ss->{source
};
1387 my $comp = join (' ', @{$ss->{comp
}});
1388 $data .= "deb $url $ss->{suite} $comp\n\n";
1391 write_file
($data, "$rootdir/etc/apt/sources.list");
1393 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1394 write_file
($data, "$rootdir/etc/fstab", 0644);
1396 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1398 # avoid warnings about non-existent resolv.conf
1399 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1401 if ($suite eq 'groovy' || $suite eq 'focal' ||
1402 $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1403 $suite eq 'bionic' || $suite eq 'artful' ||
1404 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1406 # no need to configure loopback device
1408 $data = "auto lo\niface lo inet loopback\n";
1409 mkdir "$rootdir/etc/network";
1410 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1414 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1416 # avoid warnings about missing default locale
1417 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1420 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1421 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1423 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1425 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1427 $self->logmsg ("initialize ld cache\n");
1428 $self->ve_command ("/sbin/ldconfig");
1429 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1431 $self->logmsg ("installing packages\n");
1433 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1435 $self->ve_dpkg ('install', 'dpkg');
1437 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1439 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1441 $self->ve_dpkg ('install', 'libc6');
1442 $self->ve_dpkg ('install', 'perl-base');
1444 unlink "$rootdir/usr/bin/awk";
1446 $self->ve_dpkg ('install', 'mawk');
1447 $self->ve_dpkg ('install', 'debconf');
1449 # unpack required packages
1450 foreach my $p (@$required) {
1451 $self->ve_dpkg ('unpack', $p);
1454 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1455 $self->ve_divert_add ("/sbin/init");
1456 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1458 # disable service activation
1459 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1460 $data = "#!/bin/sh\nexit 101\n";
1461 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1463 # disable start-stop-daemon
1464 $self->ve_divert_add ("/sbin/start-stop-daemon");
1468 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1470 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1473 $self->ve_divert_add ("/sbin/udevd");
1475 if ($suite eq 'etch') {
1476 # disable apache2 startup
1477 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1480 $self->logmsg ("configure required packages\n");
1481 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1483 # set postfix defaults
1484 if ($mta eq 'postfix') {
1485 $data = "postfix postfix/main_mailer_type select Local only\n";
1486 $self->ve_debconfig_set ($data);
1488 $data = "postmaster: root\nwebmaster: root\n";
1489 write_file
($data, "$rootdir/etc/aliases");
1492 if ($suite eq 'jaunty') {
1493 # jaunty does not create /var/run/network, so network startup fails.
1494 # so we do not use tmpfs for /var/run and /var/lock
1495 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1496 # and create the directory here
1497 $self->run_command ("mkdir $rootdir/var/run/network");
1500 # unpack base packages
1501 foreach my $p (@$important) {
1502 $self->ve_dpkg ('unpack', $p);
1506 if (-x
"$rootdir/sbin/ifconfig") {
1507 $self->ve_command ("ifconfig lo up");
1509 $self->ve_command ("ip link set lo up");
1512 $self->logmsg ("configure important packages\n");
1513 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1515 if (-d
"$rootdir/etc/event.d") {
1516 unlink <$rootdir/etc/event.d
/tty
*>;
1519 if (-f
"$rootdir/etc/inittab") {
1520 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1523 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1524 unlink "$rootdir/etc/mtab";
1525 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1528 $self->ve_command ("usermod -L root");
1530 if ($mta eq 'postfix') {
1531 $data = "postfix postfix/main_mailer_type select No configuration\n";
1532 $self->ve_debconfig_set ($data);
1534 unlink "$rootdir/etc/mailname";
1535 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1538 if (!$opts->{minimal
}) {
1539 # unpack standard packages
1540 foreach my $p (@$standard) {
1541 $self->ve_dpkg ('unpack', $p);
1544 $self->logmsg ("configure standard packages\n");
1545 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1548 # disable HWCLOCK access
1549 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1552 $self->ve_divert_add ("/usr/sbin/hald");
1554 # disable /dev/urandom init
1555 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1557 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1559 $self->ve_divert_add ("/sbin/klogd");
1562 # remove unnecessays sysctl entries to avoid warnings
1564 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1565 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1566 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1567 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1568 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1569 $self->run_command ($cmd);
1571 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1572 if (-f
$bindv6only) {
1574 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1575 $cmd .= " -i '$bindv6only'";
1576 $self->run_command ($cmd);
1579 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1580 # disable tty init (console-setup)
1582 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1583 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1584 $self->run_command ($cmd);
1587 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1588 # remove sysctl setup (avoid warnings at startup)
1589 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1590 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1591 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1592 $self->run_command ("rm $filelist");
1595 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1596 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1603 my $veid = $self->{veid
};
1604 my $conffile = $self->{veconffile
};
1606 my $vestat = $self->ve_status();
1608 if (!$vestat->{exist
}) {
1609 $self->logmsg ("Please create the appliance first (bootstrap)");
1613 if (!$vestat->{running
}) {
1614 $self->run_command ("lxc-start -n $veid -f $conffile");
1617 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1620 sub ve_mysql_command
{
1621 my ($self, $sql, $password) = @_;
1623 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1624 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1626 $self->ve_command ("mysql", $sql);
1629 sub ve_mysql_bootstrap
{
1630 my ($self, $sql, $password) = @_;
1634 my $suite = $self->{config
}->{suite
};
1636 if ($suite eq 'jessie') {
1637 my $rootdir = $self->{rootfs
};
1638 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1641 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1642 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1645 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1646 "--skip-bdb --skip-innodb --skip-ndbcluster";
1649 $self->ve_command ($cmd, $sql);
1652 sub compute_required
{
1653 my ($self, $pkglist) = @_;
1655 my $pkginfo = $self->pkginfo();
1656 my $instpkgs = $self->read_installed ();
1659 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1661 return $self->closure ($closure, $pkglist);
1665 my ($self, $opts) = @_;
1667 my @supp = ('7.4', '8.1');
1668 my $pgversion = '8.1';
1670 my $suite = $self->{config
}->{suite
};
1672 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1675 } elsif ($suite eq 'squeeze') {
1678 } elsif ($suite eq 'wheezy') {
1681 } elsif ($suite eq 'jessie') {
1684 } elsif ($suite eq 'stretch') {
1687 } elsif ($suite eq 'buster') {
1690 } elsif ($suite eq 'bullseye') {
1691 # FIXME update on freeze!
1696 $pgversion = $opts->{version
} if $opts->{version
};
1698 die "unsupported postgres version '$pgversion'\n"
1699 if !grep { $pgversion eq $_; } @supp;
1701 my $rootdir = $self->{rootfs
};
1703 my $required = $self->compute_required (["postgresql-$pgversion"]);
1705 $self->cache_packages ($required);
1707 $self->ve_dpkg ('install', @$required);
1709 my $iscript = "postgresql-$pgversion";
1710 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1711 $suite eq 'stretch') {
1712 $iscript = 'postgresql';
1715 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1719 my ($self, $opts) = @_;
1721 my $password = $opts->{password
};
1722 my $rootdir = $self->{rootfs
};
1724 my $suite = $self->{config
}->{suite
};
1727 if ($suite eq 'squeeze') {
1729 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1732 die "task_mysql: unsupported suite '$suite'";
1735 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1737 $self->cache_packages ($required);
1739 $self->ve_dpkg ('install', @$required);
1741 # fix security (see /usr/bin/mysql_secure_installation)
1742 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1743 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1744 "FLUSH PRIVILEGES;\n";
1745 $self->ve_mysql_bootstrap ($sql);
1749 my $rpw = $password eq 'random' ?
'admin' : $password;
1751 my $sql = "USE mysql;\n" .
1752 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1753 "FLUSH PRIVILEGES
;\n";
1754 $self->ve_mysql_bootstrap ($sql);
1756 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1757 if ($password eq 'random') {
1758 $self->install_init_script ($script_mysql_randompw, 2, 20);
1762 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1766 my ($self, $opts) = @_;
1768 my $memlimit = $opts->{memlimit
};
1769 my $rootdir = $self->{rootfs
};
1771 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1773 $self->cache_packages ($required);
1775 $self->ve_dpkg ('install', @$required);
1778 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1783 my ($self, $pkglist, $unpack) = @_;
1785 my $required = $self->compute_required ($pkglist);
1787 $self->cache_packages ($required);
1789 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1793 my ($self, $distclean) = @_;
1795 unlink $self->{logfile
};
1796 unlink "$self->{targetname}.tar";
1797 unlink "$self->{targetname}.tar.gz";
1799 $self->ve_destroy ();
1802 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1804 rmtree
$self->{infodir
};