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
{
61 my ($self, $url, $path) = @_;
63 $self->logmsg ("download: $url\n");
64 my $tmpfn = "$path.tmp$$";
66 $self->run_command ("wget -q '$url' -O '$tmpfn'");
75 rename ($tmpfn, $path);
79 my ($data, $file, $perm) = @_;
81 die "no filename" if !$file;
85 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
86 die "unable to open file '$file'";
96 die "no filename" if !$file;
98 my $fh = IO
::File-
>new ($file) ||
99 die "unable to open file '$file'";
101 local $/; # slurp mode
115 my $fh = IO
::File-
>new ("<$filename") || return $res;
118 while (defined (my $line = <$fh>)) {
119 next if $line =~ m/^\#/;
120 next if $line =~ m/^\s*$/;
130 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
131 $res->{headline
} = $1;
132 chomp $res->{headline
};
135 $res->{description
} = $long;
136 chomp $res->{description
};
137 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
138 my ($key, $value) = (lc ($1), $2);
139 if ($key eq 'source' || $key eq 'mirror') {
140 push @{$res->{$key}}, $value;
142 die "duplicate key '$key'\n" if defined ($res->{$key});
143 $res->{$key} = $value;
146 die "unable to parse config file: $rec";
150 die "unable to parse config file" if $rec;
156 my ($self, $cmd, $input, $getoutput) = @_;
158 my $reader = IO
::File-
>new();
159 my $writer = IO
::File-
>new();
160 my $error = IO
::File-
>new();
164 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
168 if (ref ($cmd) eq 'ARRAY') {
169 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
171 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
178 if ($orig_pid != $$) {
179 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
186 print $writer $input if defined $input;
189 my $select = new IO
::Select
;
190 $select->add ($reader);
191 $select->add ($error);
194 my $logfd = $self->{logfd
};
196 while ($select->count) {
197 my @handles = $select->can_read ();
199 foreach my $h (@handles) {
201 my $count = sysread ($h, $buf, 4096);
202 if (!defined ($count)) {
204 die "command '$cmdstr' failed: $!";
206 $select->remove ($h) if !$count;
210 $res .= $buf if $getoutput;
217 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
225 $self->writelog (@_);
230 my $fd = $self->{logfd
};
234 sub __sample_config
{
238 my $arch = $self->{config
}->{architecture
};
240 my $ostype = $self->{config
}->{ostype
};
242 if ($ostype =~ m/^de(bi|vu)an-/) {
243 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
244 } elsif ($ostype =~ m/^ubuntu-/) {
245 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
247 die "unknown os type '$ostype'\n";
249 $data .= "lxc.uts.name = localhost\n";
250 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
259 if (my $fd = IO
::File-
>new (".veid")) {
266 $self->{working_dir
} = getcwd
;
267 $self->{veconffile
} = "$self->{working_dir}/config";
268 $self->{rootfs
} = "$self->{working_dir}/rootfs";
271 $self->{veid
} = $cid;
277 UUID
::generate
($uuid);
278 UUID
::unparse
($uuid, $uuid_str);
279 $self->{veid
} = $uuid_str;
281 my $fd = IO
::File-
>new (">.veid") ||
282 die "unable to write '.veid'\n";
283 print $fd "$self->{veid}\n";
286 my $cdata = $self->__sample_config();
288 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
289 die "unable to write lxc config file '$self->{veconffile}' - $!";
293 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
295 $self->logmsg ("allocated VE $self->{veid}\n");
297 return $self->{veid
};
301 my ($class, $config) = @_;
303 $class = ref ($class) || $class;
307 $config = read_config
('dab.conf') if !$config;
309 $self->{config
} = $config;
313 $self->{logfile
} = "logfile";
314 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
315 die "unable to open log file";
317 my $arch = $config->{architecture
};
318 die "no 'architecture' specified\n" if !$arch;
320 die "unsupported architecture '$arch'\n"
321 if $arch !~ m/^(i386|amd64)$/;
323 my $suite = $config->{suite
} || die "no 'suite' specified\n";
324 if ($suite eq 'buster') {
325 $config->{ostype
} = "debian-10.0";
326 } elsif ($suite eq 'stretch') {
327 $config->{ostype
} = "debian-9.0";
328 } elsif ($suite eq 'jessie') {
329 $config->{ostype
} = "debian-8.0";
330 } elsif ($suite eq 'wheezy') {
331 $config->{ostype
} = "debian-7.0";
332 } elsif ($suite eq 'squeeze') {
333 $config->{ostype
} = "debian-6.0";
334 } elsif ($suite eq 'lenny') {
335 $config->{ostype
} = "debian-5.0";
336 } elsif ($suite eq 'etch') {
337 $config->{ostype
} = "debian-4.0";
338 } elsif ($suite eq 'devuan-jessie') {
340 $config->{ostype
} = "devuan-1.0";
341 } elsif ($suite eq 'devuan-ascii' || $suite eq 'ascii') {
343 $config->{ostype
} = "devuan-2.0";
344 } elsif ($suite eq 'hardy') {
345 $config->{ostype
} = "ubuntu-8.04";
346 } elsif ($suite eq 'intrepid') {
347 $config->{ostype
} = "ubuntu-8.10";
348 } elsif ($suite eq 'jaunty') {
349 $config->{ostype
} = "ubuntu-9.04";
350 } elsif ($suite eq 'precise') {
351 $config->{ostype
} = "ubuntu-12.04";
352 } elsif ($suite eq 'trusty') {
353 $config->{ostype
} = "ubuntu-14.04";
354 } elsif ($suite eq 'vivid') {
355 $config->{ostype
} = "ubuntu-15.04";
356 } elsif ($suite eq 'wily') {
357 $config->{ostype
} = "ubuntu-15.10";
358 } elsif ($suite eq 'xenial') {
359 $config->{ostype
} = "ubuntu-16.04";
360 } elsif ($suite eq 'yakkety') {
361 $config->{ostype
} = "ubuntu-16.10";
362 } elsif ($suite eq 'zesty') {
363 $config->{ostype
} = "ubuntu-17.04";
364 } elsif ($suite eq 'artful') {
365 $config->{ostype
} = "ubuntu-17.10";
366 } elsif ($suite eq 'bionic') {
367 $config->{ostype
} = "ubuntu-18.04";
368 } elsif ($suite eq 'cosmic') {
369 $config->{ostype
} = "ubuntu-18.10";
370 } elsif ($suite eq 'disco') {
371 $config->{ostype
} = "ubuntu-19.04";
372 } elsif ($suite eq 'eoan') {
373 $config->{ostype
} = "ubuntu-19.10";
375 die "unsupported debian suite '$suite'\n";
378 my $name = $config->{name
} || die "no 'name' specified\n";
380 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
381 die "illegal characters in name '$name'\n";
383 my $version = $config->{version
};
384 die "no 'version' specified\n" if !$version;
385 die "no 'section' specified\n" if !$config->{section
};
386 die "no 'description' specified\n" if !$config->{headline
};
387 die "no 'maintainer' specified\n" if !$config->{maintainer
};
389 if ($name =~ m/^$config->{ostype}/) {
390 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
392 $self->{targetname
} = "$config->{ostype}-${name}_" .
393 "${version}_$config->{architecture}";
396 if (!$config->{source
}) {
397 if ($suite eq 'etch' || $suite eq 'lenny') {
398 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE main contrib";
399 push @{$config->{source
}}, "http://security.debian.org SUITE/updates main contrib";
400 } elsif ($suite eq 'squeeze' || $suite eq 'stretch' ||
401 $suite eq 'jessie' || $suite eq 'buster' ) {
402 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE main contrib";
403 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE-updates main contrib";
404 push @{$config->{source
}}, "http://security.debian.org SUITE/updates main contrib";
405 } elsif ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty' ||
406 $suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
407 $suite eq 'trusty' || $suite eq 'precise' || $suite eq 'yakkety' ||
408 $suite eq 'zesty' || $suite eq 'artful' || $suite eq 'bionic' ||
409 $suite eq 'cosmic' || $suite eq 'disco' || $suite eq 'eoan' ) {
410 my $comp = "main restricted universe multiverse";
411 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE $comp";
412 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE-updates $comp";
413 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE-security $comp";
421 foreach my $s (@{$config->{source
}}) {
422 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
423 my ($url, $su, $components) = ($1, $3, $4);
424 $su =~ s/SUITE/$suite/;
425 $components =~ s/^\s+//;
426 $components =~ s/\s+$//;
428 foreach my $co (split (/\s+/, $components)) {
431 $ca = ['main'] if !$ca;
439 die "syntax error in source spezification '$s'\n";
443 foreach my $m (@{$config->{mirror
}}) {
444 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
445 my ($ms, $md) = ($1, $3);
447 foreach my $ss (@$sources) {
448 if ($ss->{source
} eq $ms) {
454 die "unusable mirror $ms\n" if !$found;
456 die "syntax error in mirror spezification '$m'\n";
460 $self->{sources
} = $sources;
462 $self->{infodir
} = "info";
464 $self->__allocate_ve ();
466 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
468 my $incl = [qw
(less ssh openssh-server logrotate
)];
470 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
471 pppoeconf nfs-common mtools ntp
)];
473 # ubuntu has too many dependencies on udev, so
474 # we cannot exclude it (instead we disable udevd)
476 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
477 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
478 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
480 push @$incl, 'isc-dhcp-client';
481 push @$excl, qw(libmodule-build-perl);
482 } elsif ($suite eq 'trusty') {
483 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
484 } elsif ($suite eq 'precise') {
485 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
486 } elsif ($suite eq 'hardy') {
487 push @$excl, qw(kbd);
488 push @$excl, qw(apparmor apparmor-utils ntfs-3g
490 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
491 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
492 libntfs-3g28 ntfs-3g friendly-recovery);
493 } elsif ($suite eq 'jessie') {
494 push @$incl, 'sysvinit-core'; # avoid systemd and udev
495 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
496 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm
498 } elsif ($suite eq 'stretch' || $suite eq 'buster') {
499 push @$excl, qw(module-init-tools pciutils hdparm
502 push @$excl, qw(udev module-init-tools pciutils hdparm
506 $self->{incl
} = $incl;
507 $self->{excl
} = $excl;
515 my $infodir = $self->{infodir
};
516 my $arch = $self->{config
}->{architecture
};
522 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
523 die "unable to open log file";
525 foreach my $ss (@{$self->{sources
}}) {
526 my $src = $ss->{mirror
} || $ss->{source
};
527 my $path = "dists/$ss->{suite}/Release";
528 my $url = "$src/$path";
529 my $target = __url_to_filename
("$ss->{source}/$path");
531 $self->download ($url, "$infodir/$target");
532 $self->download ("$url.gpg", "$infodir/$target.gpg");
533 # fixme: impl. verify (needs --keyring option)
537 warn "Release info ignored\n";
539 foreach my $comp (@{$ss->{comp
}}) {
540 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.gz";
541 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
542 my $pkgsrc = "$src/$path";
543 $self->download ($pkgsrc, $target);
544 $self->run_command ("gzip -d '$target'");
550 my ($self, $filename, $size) = @_;
552 my $config = $self->{config
};
556 $data .= "Name: $config->{name}\n";
557 $data .= "Version: $config->{version}\n";
558 $data .= "Type: lxc\n";
559 $data .= "OS: $config->{ostype}\n";
560 $data .= "Section: $config->{section}\n";
561 $data .= "Maintainer: $config->{maintainer}\n";
562 $data .= "Architecture: $config->{architecture}\n";
563 $data .= "Installed-Size: $size\n";
566 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
567 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
568 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
571 $data .= "Description: $config->{headline}\n";
572 $data .= "$config->{description}\n" if $config->{description
};
574 write_file
($data, $filename, 0644);
578 my ($self, $opts) = @_;
580 my $suite = $self->{config
}->{suite
};
581 my $infodir = $self->{infodir
};
582 my $arch = $self->{config
}->{architecture
};
584 my $instpkgs = $self->read_installed ();
585 my $pkginfo = $self->pkginfo();
586 my $veid = $self->{veid
};
587 my $conffile = $self->{veconffile
};
588 my $rootdir = $self->{rootfs
};
590 my $vestat = $self->ve_status();
591 die "ve not running - unable to finalize\n" if !$vestat->{running
};
594 if (-f
"$rootdir/etc/init.d/mysql") {
595 $self->ve_command ("/etc/init.d/mysql stop");
598 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
599 unlink "$rootdir/root/.my.cnf";
602 if ($suite eq 'etch') {
603 # enable apache2 startup
604 if ($instpkgs->{apache2
}) {
605 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
607 unlink "$rootdir/etc/default/apache2";
610 $self->logmsg ("cleanup package status\n");
611 # prevent auto selection of all standard, required or important
612 # packages which are not installed
613 foreach my $pkg (keys %$pkginfo) {
614 my $pri = $pkginfo->{$pkg}->{priority
};
615 if ($pri && ($pri eq 'required' || $pri eq 'important'
616 || $pri eq 'standard')) {
617 if (!$instpkgs->{$pkg}) {
618 $self->ve_dpkg_set_selection ($pkg, 'purge');
623 $self->ve_command ("apt-get clean");
625 $self->logmsg ("update available package list\n");
627 $self->ve_command ("dpkg --clear-avail");
628 foreach my $ss (@{$self->{sources
}}) {
629 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
630 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
631 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
632 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
634 foreach my $comp (@{$ss->{comp
}}) {
635 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
636 "$comp/binary-$arch/Packages");
637 my $target = "/var/lib/apt/lists/$src";
638 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
639 $self->ve_command ("dpkg --merge-avail '$target'");
643 # set dselect default method
644 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
646 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
648 $self->ve_divert_remove ("/sbin/start-stop-daemon");
650 $self->ve_divert_remove ("/sbin/init");
652 # finally stop the VE
653 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
655 unlink "$rootdir/sbin/defenv";
657 unlink <$rootdir/root/dead.letter
*>;
659 unlink "$rootdir/var/log/init.log";
661 unlink "$rootdir/aquota.group";
663 unlink "$rootdir/aquota.user";
665 write_file
("", "$rootdir/var/log/syslog");
667 $self->logmsg ("detecting final size: ");
669 my $sizestr = $self->run_command ("du -sm $rootdir", undef, 1);
671 if ($sizestr =~ m/^(\d+)\s+\Q$rootdir\E$/) {
674 die "unable to detect size\n";
676 $self->logmsg ("$size MB\n");
678 $self->write_config ("$rootdir/etc/appliance.info", $size);
680 $self->logmsg ("creating final appliance archive\n");
682 my $target = "$self->{targetname}.tar";
686 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
687 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
688 $self->run_command ("gzip $target");
694 my $rootdir = $self->{rootfs
};
696 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
698 open (PKGLST
, "<$pkgfilelist") ||
699 die "unable to open '$pkgfilelist'";
703 while (my $rec = <PKGLST
>) {
709 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
713 my $pkg = $res->{'package'};
714 if (my $status = $res->{status
}) {
715 my @sa = split (/\s+/, $status);
717 if ($stat && ($stat ne 'purge')) {
718 $pkglist->{$pkg} = $res;
731 my $veid = $self->{veid
};
733 my $res = { running
=> 0 };
735 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
737 my $filename = "/proc/net/unix";
739 # similar test is used by lcxcontainers.c: list_active_containers
740 my $fh = IO
::File-
>new ($filename, "r");
743 while (defined(my $line = <$fh>)) {
744 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
746 if ($path =~ m!^@/\S+/$veid/command$!) {
757 my ($self, $cmd, $input) = @_;
759 my $veid = $self->{veid
};
760 my $conffile = $self->{veconffile
};
762 if (ref ($cmd) eq 'ARRAY') {
763 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
764 $self->run_command ($cmd, $input);
766 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
770 # like ve_command, but pipes stdin correctly
772 my ($self, @cmd) = @_;
774 my $veid = $self->{veid
};
775 my $conffile = $self->{veconffile
};
778 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
779 'defenv', @cmd) || die "unable to exec command";
781 while (defined (my $line = <$reader>)) {
782 $self->logmsg ($line);
788 die "ve_exec failed - status $rc\n" if $rc != 0;
792 my ($self, $filename) = @_;
794 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
795 "--rename '$filename'");
797 sub ve_divert_remove
{
798 my ($self, $filename) = @_;
800 my $rootdir = $self->{rootfs
};
802 unlink "$rootdir/$filename";
803 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
806 sub ve_debconfig_set
{
807 my ($self, $dcdata) = @_;
809 my $rootdir = $self->{rootfs
};
810 my $cfgfile = "/tmp/debconf.txt";
811 write_file
($dcdata, "$rootdir/$cfgfile");
812 $self->ve_command ("debconf-set-selections $cfgfile");
813 unlink "$rootdir/$cfgfile";
816 sub ve_dpkg_set_selection
{
817 my ($self, $pkg, $status) = @_;
819 $self->ve_command ("dpkg --set-selections", "$pkg $status");
823 my ($self, $cmd, @pkglist) = @_;
825 return if !scalar (@pkglist);
827 my $pkginfo = $self->pkginfo();
829 my $rootdir = $self->{rootfs
};
830 my $cachedir = $self->{cachedir
};
834 foreach my $pkg (@pkglist) {
835 my $filename = $self->getpkgfile ($pkg);
836 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
837 push @files, "/$filename";
838 $self->logmsg ("$cmd: $pkg\n");
841 my $fl = join (' ', @files);
843 if ($cmd eq 'install') {
844 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
845 } elsif ($cmd eq 'unpack') {
846 $self->ve_command ("dpkg --force-depends --unpack $fl");
848 die "internal error";
851 foreach my $fn (@files) { unlink "$rootdir$fn"; }
857 my $veid = $self->{veid
}; # fixme
858 my $conffile = $self->{veconffile
};
860 my $vestat = $self->ve_status();
861 if ($vestat->{running
}) {
862 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
865 rmtree
$self->{rootfs
};
866 unlink $self->{veconffile
};
872 my $veid = $self->{veid
};
873 my $conffile = $self->{veconffile
};
875 $self->logmsg ("initialize VE $veid\n");
877 my $vestat = $self->ve_status();
878 if ($vestat->{running
}) {
879 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
882 rmtree
$self->{rootfs
};
883 mkpath
$self->{rootfs
};
886 sub __deb_version_cmp
{
887 my ($cur, $op, $new) = @_;
889 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
896 sub __parse_packages
{
897 my ($pkginfo, $filename, $src) = @_;
900 open (PKGLST
, "<$filename") ||
901 die "unable to open '$filename'";
903 while (my $rec = <PKGLST
>) {
910 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
914 my $pkg = $res->{'package'};
915 if ($pkg && $res->{'filename'}) {
917 if (my $info = $pkginfo->{$pkg}) {
918 $cur = $info->{version
};
920 my $new = $res->{version
};
921 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
923 $res->{url
} = "$src/$res->{'filename'}";
925 die "no url for package '$pkg'" if !$res->{url
};
927 $pkginfo->{$pkg} = $res;
938 return $self->{pkginfo
} if $self->{pkginfo
};
940 my $infodir = $self->{infodir
};
941 my $arch = $self->{config
}->{architecture
};
943 my $availfn = "$infodir/available";
948 # reading 'available' is faster, because it only contains latest version
949 # (no need to do slow version compares)
951 __parse_packages
($pkginfo, $availfn);
952 $self->{pkginfo
} = $pkginfo;
956 $self->logmsg ("generating available package list\n");
958 foreach my $ss (@{$self->{sources
}}) {
959 foreach my $comp (@{$ss->{comp
}}) {
960 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
961 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
963 my $src = $ss->{mirror
} || $ss->{source
};
965 __parse_packages
($pkginfo, $pkgfilelist, $src);
969 if (my $dep = $self->{config
}->{depends
}) {
970 foreach my $d (split (/,/, $dep)) {
971 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
972 my ($pkg, $op, $rver) = ($1, $3, $4);
973 $self->logmsg ("checking dependencies: $d\n");
974 my $info = $pkginfo->{$pkg};
975 die "package '$pkg' not available\n" if !$info;
977 my $cver = $info->{version
};
978 if (!__deb_version_cmp
($cver, $op, $rver)) {
979 die "detected wrong version '$cver'\n";
983 die "syntax error in depends field";
988 $self->{pkginfo
} = $pkginfo;
990 my $tmpfn = "$availfn.tmp$$";
991 my $fd = IO
::File-
>new (">$tmpfn");
992 foreach my $pkg (sort keys %$pkginfo) {
993 my $info = $pkginfo->{$pkg};
994 print $fd "package: $pkg\n";
995 foreach my $k (sort keys %$info) {
996 next if $k eq 'description';
997 next if $k eq 'package';
999 print $fd "$k: $v\n" if $v;
1001 print $fd "description: $info->{description}\n" if $info->{description
};
1006 rename ($tmpfn, $availfn);
1011 sub __record_provides
{
1012 my ($pkginfo, $closure, $list, $skipself) = @_;
1014 foreach my $pname (@$list) {
1015 my $info = $pkginfo->{$pname};
1016 # fixme: if someone install packages directly using dpkg, there
1017 # is no entry in 'available', only in 'status'. In that case, we
1018 # should extract info from $instpkgs
1020 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1023 if (my $prov = $info->{provides
}) {
1024 my @pl = split (',', $prov);
1025 foreach my $p (@pl) {
1027 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1032 $closure->{$pname} = 1 if !$skipself;
1037 my ($self, $closure, $list) = @_;
1039 my $pkginfo = $self->pkginfo();
1041 # first, record provided packages
1042 __record_provides
($pkginfo, $closure, $list, 1);
1047 # then resolve dependencies
1048 foreach my $pname (@$list) {
1049 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1055 sub __closure_single
{
1056 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1060 $pname =~ s/:any$//;
1062 return if $closure->{$pname};
1064 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1066 my $dep = $info->{depends
};
1067 my $predep = $info->{'pre-depends'};
1069 my $size = $info->{size
};
1070 my $url = $info->{url
};
1072 $url || die "$pname: no url for package '$pname'";
1074 if (!$pkghash->{$pname}) {
1075 unshift @$pkglist, $pname;
1076 $pkghash->{$pname} = 1;
1079 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1081 $closure->{$pname} = 1;
1087 push @l, split (/,/, $predep) if $predep;
1088 push @l, split (/,/, $dep) if $dep;
1090 DEPEND
: foreach my $p (@l) {
1091 my @l1 = split (/\|/, $p);
1092 foreach my $p1 (@l1) {
1093 if ($p1 =~ m/^\s*(\S+).*/) {
1094 #printf (STDERR "$pname: $p --> $1\n");
1095 if ($closure->{$1}) {
1096 next DEPEND
; # dependency already met
1100 # search for non-excluded alternative
1102 foreach my $p1 (@l1) {
1103 if ($p1 =~ m/^\s*(\S+).*/) {
1104 next if grep { $1 eq $_ } @$excl;
1109 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1111 #printf (STDERR "$pname: $p --> $found\n");
1113 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1117 sub cache_packages
{
1118 my ($self, $pkglist) = @_;
1120 foreach my $pkg (@$pkglist) {
1121 $self->getpkgfile ($pkg);
1126 my ($self, $pkg) = @_;
1128 my $pkginfo = $self->pkginfo();
1129 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1130 my $cachedir = $self->{cachedir
};
1132 my $url = $info->{url
};
1135 if ($url =~ m
|/([^/]+.deb
)$|) {
1138 die "internal error";
1141 return $filename if -f
"$cachedir/$filename";
1145 $self->download ($url, "$cachedir/$filename");
1150 sub install_init_script
{
1151 my ($self, $script, $runlevel, $prio) = @_;
1153 my $suite = $self->{config
}->{suite
};
1154 my $rootdir = $self->{rootfs
};
1156 my $base = basename
($script);
1157 my $target = "$rootdir/etc/init.d/$base";
1159 $self->run_command ("install -m 0755 '$script' '$target'");
1160 if ($suite eq 'etch' || $suite eq 'lenny') {
1161 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1162 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1163 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1164 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1166 die "unable to install init script (system uses systemd)\n";
1167 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1168 die "unable to install init script (system uses upstart)\n";
1170 $self->ve_command ("insserv $base");
1177 my ($self, $opts) = @_;
1179 my $pkginfo = $self->pkginfo();
1180 my $veid = $self->{veid
};
1181 my $suite = $self->{config
}->{suite
};
1183 my $important = [ @{$self->{incl
}} ];
1187 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1189 if ($mta eq 'postfix') {
1190 push @$important, "postfix";
1193 foreach my $p (sort keys %$pkginfo) {
1194 next if grep { $p eq $_ } @{$self->{excl
}};
1195 my $pri = $pkginfo->{$p}->{priority
};
1197 next if $mta ne 'exim' && $p =~ m/exim/;
1198 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1200 push @$required, $p if $pri eq 'required';
1201 push @$important, $p if $pri eq 'important';
1202 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1206 $required = $self->closure ($closure, $required);
1207 $important = $self->closure ($closure, $important);
1209 if (!$opts->{minimal
}) {
1210 push @$standard, 'xbase-clients';
1211 $standard = $self->closure ($closure, $standard);
1214 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1215 # except those explicitly excluded
1216 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1217 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1218 foreach my $d (split (/,/, $mdeps)) {
1219 if ($d =~ m/^\s*(\S+)$/) {
1221 next if $closure->{$pkg};
1222 next if grep { $pkg eq $_ } @{$self->{excl
}};
1223 die "missing ubuntu-minimal package '$pkg'\n";
1226 if (!$opts->{minimal
}) {
1227 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1228 foreach my $d (split (/,/, $mdeps)) {
1229 if ($d =~ m/^\s*(\S+)$/) {
1231 next if $closure->{$pkg};
1232 next if grep { $pkg eq $_ } @{$self->{excl
}};
1233 die "missing ubuntu-standard package '$pkg'\n";
1239 # download/cache all files first
1240 $self->cache_packages ($required);
1241 $self->cache_packages ($important);
1242 $self->cache_packages ($standard);
1244 my $rootdir = $self->{rootfs
};
1246 # extract required packages first
1247 $self->logmsg ("create basic environment\n");
1248 foreach my $p (@$required) {
1249 my $filename = $self->getpkgfile ($p);
1250 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1251 if ($content =~ m/^data.tar.xz$/m) {
1252 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1254 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1259 my $data = "Package: dpkg\n" .
1260 "Version: $pkginfo->{dpkg}->{version}\n" .
1261 "Status: install ok installed\n";
1263 write_file
($data, "$rootdir/var/lib/dpkg/status");
1264 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1265 write_file
("", "$rootdir/var/lib/dpkg/available");
1268 foreach my $ss (@{$self->{sources
}}) {
1269 my $url = $ss->{source
};
1270 my $comp = join (' ', @{$ss->{comp
}});
1271 $data .= "deb $url $ss->{suite} $comp\n\n";
1274 write_file
($data, "$rootdir/etc/apt/sources.list");
1276 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1277 write_file
($data, "$rootdir/etc/fstab", 0644);
1279 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1281 # avoid warnings about non-existent resolv.conf
1282 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1284 if ($suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1285 $suite eq 'bionic' || $suite eq 'artful' ||
1286 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1288 # no need to configure loopback device
1290 $data = "auto lo\niface lo inet loopback\n";
1291 mkdir "$rootdir/etc/network";
1292 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1296 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1298 # avoid warnings about missing default locale
1299 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1302 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1303 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1305 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1307 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1309 $self->logmsg ("initialize ld cache\n");
1310 $self->ve_command ("/sbin/ldconfig");
1311 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1313 $self->logmsg ("installing packages\n");
1315 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1317 $self->ve_dpkg ('install', 'dpkg');
1319 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1321 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1323 $self->ve_dpkg ('install', 'libc6');
1324 $self->ve_dpkg ('install', 'perl-base');
1326 unlink "$rootdir/usr/bin/awk";
1328 $self->ve_dpkg ('install', 'mawk');
1329 $self->ve_dpkg ('install', 'debconf');
1331 # unpack required packages
1332 foreach my $p (@$required) {
1333 $self->ve_dpkg ('unpack', $p);
1336 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1337 $self->ve_divert_add ("/sbin/init");
1338 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1340 # disable service activation
1341 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1342 $data = "#!/bin/sh\nexit 101\n";
1343 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1345 # disable start-stop-daemon
1346 $self->ve_divert_add ("/sbin/start-stop-daemon");
1350 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1352 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1355 $self->ve_divert_add ("/sbin/udevd");
1357 if ($suite eq 'etch') {
1358 # disable apache2 startup
1359 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1362 $self->logmsg ("configure required packages\n");
1363 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1365 # set postfix defaults
1366 if ($mta eq 'postfix') {
1367 $data = "postfix postfix/main_mailer_type select Local only\n";
1368 $self->ve_debconfig_set ($data);
1370 $data = "postmaster: root\nwebmaster: root\n";
1371 write_file
($data, "$rootdir/etc/aliases");
1374 if ($suite eq 'jaunty') {
1375 # jaunty does not create /var/run/network, so network startup fails.
1376 # so we do not use tmpfs for /var/run and /var/lock
1377 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1378 # and create the directory here
1379 $self->run_command ("mkdir $rootdir/var/run/network");
1382 # unpack base packages
1383 foreach my $p (@$important) {
1384 $self->ve_dpkg ('unpack', $p);
1388 if (-x
"$rootdir/sbin/ifconfig") {
1389 $self->ve_command ("ifconfig lo up");
1391 $self->ve_command ("ip link set lo up");
1394 $self->logmsg ("configure important packages\n");
1395 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1397 if (-d
"$rootdir/etc/event.d") {
1398 unlink <$rootdir/etc/event.d
/tty
*>;
1401 if (-f
"$rootdir/etc/inittab") {
1402 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1405 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1406 unlink "$rootdir/etc/mtab";
1407 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1410 $self->ve_command ("usermod -L root");
1412 if ($mta eq 'postfix') {
1413 $data = "postfix postfix/main_mailer_type select No configuration\n";
1414 $self->ve_debconfig_set ($data);
1416 unlink "$rootdir/etc/mailname";
1417 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1420 if (!$opts->{minimal
}) {
1421 # unpack standard packages
1422 foreach my $p (@$standard) {
1423 $self->ve_dpkg ('unpack', $p);
1426 $self->logmsg ("configure standard packages\n");
1427 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1430 # disable HWCLOCK access
1431 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1434 $self->ve_divert_add ("/usr/sbin/hald");
1436 # disable /dev/urandom init
1437 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1439 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1441 $self->ve_divert_add ("/sbin/klogd");
1444 # remove unnecessays sysctl entries to avoid warnings
1446 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1447 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1448 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1449 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1450 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1451 $self->run_command ($cmd);
1453 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1454 if (-f
$bindv6only) {
1456 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1457 $cmd .= " -i '$bindv6only'";
1458 $self->run_command ($cmd);
1461 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1462 # disable tty init (console-setup)
1464 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1465 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1466 $self->run_command ($cmd);
1469 if ($suite eq 'intrepid') {
1470 # remove sysctl setup (avoid warnings at startup)
1471 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1472 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf";
1473 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1474 $self->run_command ("rm $filelist");
1476 if ($suite eq 'jaunty') {
1477 # remove sysctl setup (avoid warnings at startup)
1478 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1479 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1480 $self->run_command ("rm $filelist");
1487 my $veid = $self->{veid
};
1488 my $conffile = $self->{veconffile
};
1490 my $vestat = $self->ve_status();
1492 if (!$vestat->{exist
}) {
1493 $self->logmsg ("Please create the appliance first (bootstrap)");
1497 if (!$vestat->{running
}) {
1498 $self->run_command ("lxc-start -n $veid -f $conffile");
1501 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1504 sub ve_mysql_command
{
1505 my ($self, $sql, $password) = @_;
1507 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1508 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1510 $self->ve_command ("mysql", $sql);
1513 sub ve_mysql_bootstrap
{
1514 my ($self, $sql, $password) = @_;
1518 my $suite = $self->{config
}->{suite
};
1520 if ($suite eq 'jessie') {
1521 my $rootdir = $self->{rootfs
};
1522 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1525 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1526 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1529 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1530 "--skip-bdb --skip-innodb --skip-ndbcluster";
1533 $self->ve_command ($cmd, $sql);
1536 sub compute_required
{
1537 my ($self, $pkglist) = @_;
1539 my $pkginfo = $self->pkginfo();
1540 my $instpkgs = $self->read_installed ();
1543 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1545 return $self->closure ($closure, $pkglist);
1549 my ($self, $opts) = @_;
1551 my @supp = ('7.4', '8.1');
1552 my $pgversion = '8.1';
1554 my $suite = $self->{config
}->{suite
};
1556 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1559 } elsif ($suite eq 'squeeze') {
1562 } elsif ($suite eq 'wheezy') {
1565 } elsif ($suite eq 'jessie') {
1568 } elsif ($suite eq 'stretch') {
1571 } elsif ($suite eq 'buster') {
1576 $pgversion = $opts->{version
} if $opts->{version
};
1578 die "unsupported postgres version '$pgversion'\n"
1579 if !grep { $pgversion eq $_; } @supp;
1581 my $rootdir = $self->{rootfs
};
1583 my $required = $self->compute_required (["postgresql-$pgversion"]);
1585 $self->cache_packages ($required);
1587 $self->ve_dpkg ('install', @$required);
1589 my $iscript = "postgresql-$pgversion";
1590 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1591 $suite eq 'stretch') {
1592 $iscript = 'postgresql';
1595 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1599 my ($self, $opts) = @_;
1601 my $password = $opts->{password
};
1602 my $rootdir = $self->{rootfs
};
1604 my $suite = $self->{config
}->{suite
};
1607 if ($suite eq 'squeeze') {
1609 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1612 die "task_mysql: unsupported suite '$suite'";
1615 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1617 $self->cache_packages ($required);
1619 $self->ve_dpkg ('install', @$required);
1621 # fix security (see /usr/bin/mysql_secure_installation)
1622 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1623 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1624 "FLUSH PRIVILEGES;\n";
1625 $self->ve_mysql_bootstrap ($sql);
1629 my $rpw = $password eq 'random' ?
'admin' : $password;
1631 my $sql = "USE mysql;\n" .
1632 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1633 "FLUSH PRIVILEGES
;\n";
1634 $self->ve_mysql_bootstrap ($sql);
1636 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1637 if ($password eq 'random') {
1638 $self->install_init_script ($script_mysql_randompw, 2, 20);
1642 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1646 my ($self, $opts) = @_;
1648 my $memlimit = $opts->{memlimit
};
1649 my $rootdir = $self->{rootfs
};
1651 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1653 $self->cache_packages ($required);
1655 $self->ve_dpkg ('install', @$required);
1658 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1663 my ($self, $pkglist, $unpack) = @_;
1665 my $required = $self->compute_required ($pkglist);
1667 $self->cache_packages ($required);
1669 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1673 my ($self, $distclean) = @_;
1675 unlink $self->{logfile
};
1676 unlink "$self->{targetname}.tar";
1677 unlink "$self->{targetname}.tar.gz";
1679 $self->ve_destroy ();
1682 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1684 rmtree
$self->{infodir
};