11 use POSIX qw
(LONG_MAX
);
15 # fixme: lock container ?
17 my $dablibdir = "/usr/lib/dab";
18 my $devicetar = "$dablibdir/devices.tar.gz";
19 my $default_env = "$dablibdir/scripts/defenv";
20 my $fake_init = "$dablibdir/scripts/init.pl";
21 my $script_ssh_init = "$dablibdir/scripts/ssh_gen_host_keys";
22 my $script_mysql_randompw = "$dablibdir/scripts/mysql_randompw";
23 my $script_init_urandom = "$dablibdir/scripts/init_urandom";
25 my $postfix_main_cf = <<EOD;
26 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
28 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
31 # appending .domain is the MUA's job.
32 append_dot_mydomain = no
34 # Uncomment the next line to generate "delayed mail" warnings
35 #delay_warning_time = 4h
37 alias_maps = hash:/etc/aliases
38 alias_database = hash:/etc/aliases
39 mydestination = \$myhostname, localhost.\$mydomain, localhost
41 mynetworks = 127.0.0.0/8
42 inet_interfaces = loopback-only
43 recipient_delimiter = +
47 # produce apt compatible filenames (/var/lib/apt/lists)
48 sub __url_to_filename
{
59 my ($self, $url, $path) = @_;
61 $self->logmsg ("download: $url\n");
62 my $tmpfn = "$path.tmp$$";
64 $self->run_command ("wget -q '$url' -O '$tmpfn'");
73 rename ($tmpfn, $path);
77 my ($data, $file, $perm) = @_;
79 die "no filename" if !$file;
83 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
84 die "unable to open file '$file'";
94 die "no filename" if !$file;
96 my $fh = IO
::File-
>new ($file) ||
97 die "unable to open file '$file'";
99 local $/; # slurp mode
113 my $fh = IO
::File-
>new ("<$filename") || return $res;
116 while (defined (my $line = <$fh>)) {
117 next if $line =~ m/^\#/;
118 next if $line =~ m/^\s*$/;
128 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
129 $res->{headline
} = $1;
130 chomp $res->{headline
};
133 $res->{description
} = $long;
134 chomp $res->{description
};
135 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
136 my ($key, $value) = (lc ($1), $2);
137 if ($key eq 'source' || $key eq 'mirror') {
138 push @{$res->{$key}}, $value;
140 die "duplicate key '$key'\n" if defined ($res->{$key});
141 $res->{$key} = $value;
144 die "unable to parse config file: $rec";
148 die "unable to parse config file" if $rec;
154 my ($self, $cmd, $input, $getoutput) = @_;
156 my $reader = IO
::File-
>new();
157 my $writer = IO
::File-
>new();
158 my $error = IO
::File-
>new();
162 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
166 if (ref ($cmd) eq 'ARRAY') {
167 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
169 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
176 if ($orig_pid != $$) {
177 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
184 print $writer $input if defined $input;
187 my $select = new IO
::Select
;
188 $select->add ($reader);
189 $select->add ($error);
192 my $logfd = $self->{logfd
};
194 while ($select->count) {
195 my @handles = $select->can_read ();
197 foreach my $h (@handles) {
199 my $count = sysread ($h, $buf, 4096);
200 if (!defined ($count)) {
202 die "command '$cmdstr' failed: $!";
204 $select->remove ($h) if !$count;
208 $res .= $buf if $getoutput;
215 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
223 $self->writelog (@_);
228 my $fd = $self->{logfd
};
232 sub __sample_config
{
236 my $arch = $self->{config
}->{architecture
};
238 my $ostype = $self->{config
}->{ostype
};
240 if ($ostype =~ m/^debian-/) {
241 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
242 } elsif ($ostype =~ m/^ubuntu-/) {
243 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
245 die "unknown os type '$ostype'\n";
247 $data .= "lxc.utsname = localhost\n";
248 $data .= "lxc.rootfs = $self->{rootfs}\n";
257 if (my $fd = IO
::File-
>new (".veid")) {
264 $self->{working_dir
} = getcwd
;
265 $self->{veconffile
} = "$self->{working_dir}/config";
266 $self->{rootfs
} = "$self->{working_dir}/rootfs";
269 $self->{veid
} = $cid;
275 UUID
::generate
($uuid);
276 UUID
::unparse
($uuid, $uuid_str);
277 $self->{veid
} = $uuid_str;
279 my $fd = IO
::File-
>new (">.veid") ||
280 die "unable to write '.veid'\n";
281 print $fd "$self->{veid}\n";
284 my $cdata = $self->__sample_config();
286 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
287 die "unable to write lxc config file '$self->{veconffile}' - $!";
291 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
293 $self->logmsg ("allocated VE $self->{veid}\n");
295 return $self->{veid
};
299 my ($class, $config) = @_;
301 $class = ref ($class) || $class;
305 $config = read_config
('dab.conf') if !$config;
307 $self->{config
} = $config;
311 $self->{logfile
} = "logfile";
312 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
313 die "unable to open log file";
315 my $arch = $config->{architecture
};
316 die "no 'architecture' specified\n" if !$arch;
318 die "unsupported architecture '$arch'\n"
319 if $arch !~ m/^(i386|amd64)$/;
321 my $suite = $config->{suite
} || die "no 'suite' specified\n";
322 if ($suite eq 'stretch') {
323 $config->{ostype
} = "debian-9.0";
324 } elsif ($suite eq 'jessie') {
325 $config->{ostype
} = "debian-8.0";
326 } elsif ($suite eq 'wheezy') {
327 $config->{ostype
} = "debian-7.0";
328 } elsif ($suite eq 'squeeze') {
329 $config->{ostype
} = "debian-6.0";
330 } elsif ($suite eq 'lenny') {
331 $config->{ostype
} = "debian-5.0";
332 } elsif ($suite eq 'etch') {
333 $config->{ostype
} = "debian-4.0";
334 } elsif ($suite eq 'hardy') {
335 $config->{ostype
} = "ubuntu-8.04";
336 } elsif ($suite eq 'intrepid') {
337 $config->{ostype
} = "ubuntu-8.10";
338 } elsif ($suite eq 'jaunty') {
339 $config->{ostype
} = "ubuntu-9.04";
340 } elsif ($suite eq 'precise') {
341 $config->{ostype
} = "ubuntu-12.04";
342 } elsif ($suite eq 'trusty') {
343 $config->{ostype
} = "ubuntu-14.04";
344 } elsif ($suite eq 'vivid') {
345 $config->{ostype
} = "ubuntu-15.04";
346 } elsif ($suite eq 'wily') {
347 $config->{ostype
} = "ubuntu-15.10";
348 } elsif ($suite eq 'xenial') {
349 $config->{ostype
} = "ubuntu-16.04";
350 } elsif ($suite eq 'yakkety') {
351 $config->{ostype
} = "ubuntu-16.10";
352 } elsif ($suite eq 'zesty') {
353 $config->{ostype
} = "ubuntu-17.04";
355 die "unsupported debian suite '$suite'\n";
358 my $name = $config->{name
} || die "no 'name' specified\n";
360 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
361 die "illegal characters in name '$name'\n";
363 my $version = $config->{version
};
364 die "no 'version' specified\n" if !$version;
365 die "no 'section' specified\n" if !$config->{section
};
366 die "no 'description' specified\n" if !$config->{headline
};
367 die "no 'maintainer' specified\n" if !$config->{maintainer
};
369 if ($name =~ m/^$config->{ostype}/) {
370 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
372 $self->{targetname
} = "$config->{ostype}-${name}_" .
373 "${version}_$config->{architecture}";
376 if (!$config->{source
}) {
377 if ($suite eq 'etch' || $suite eq 'lenny') {
378 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE main contrib";
379 push @{$config->{source
}}, "http://security.debian.org SUITE/updates main contrib";
380 } elsif ($suite eq 'squeeze' || $suite eq 'wheezy' ||
381 $suite eq 'jessie' || $suite eq 'stretch' ) {
382 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE main contrib";
383 push @{$config->{source
}}, "http://ftp.debian.org/debian SUITE-updates main contrib";
384 push @{$config->{source
}}, "http://security.debian.org SUITE/updates main contrib";
385 } elsif ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty' ||
386 $suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
387 $suite eq 'trusty' || $suite eq 'precise' || $suite eq 'yakkety' ||
389 my $comp = "main restricted universe multiverse";
390 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE $comp";
391 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE-updates $comp";
392 push @{$config->{source
}}, "http://archive.ubuntu.com/ubuntu SUITE-security $comp";
400 foreach my $s (@{$config->{source
}}) {
401 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
402 my ($url, $su, $components) = ($1, $3, $4);
403 $su =~ s/SUITE/$suite/;
404 $components =~ s/^\s+//;
405 $components =~ s/\s+$//;
407 foreach my $co (split (/\s+/, $components)) {
410 $ca = ['main'] if !$ca;
418 die "syntax error in source spezification '$s'\n";
422 foreach my $m (@{$config->{mirror
}}) {
423 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
424 my ($ms, $md) = ($1, $3);
426 foreach my $ss (@$sources) {
427 if ($ss->{source
} eq $ms) {
433 die "unusable mirror $ms\n" if !$found;
435 die "syntax error in mirror spezification '$m'\n";
439 $self->{sources
} = $sources;
441 $self->{infodir
} = "info";
443 $self->__allocate_ve ();
445 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
447 my $incl = [qw
(less ssh openssh-server logrotate
)];
449 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
450 pppoeconf nfs-common mtools ntp
)];
452 # ubuntu has too many dependencies on udev, so
453 # we cannot exclude it (instead we disable udevd)
455 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
456 $suite eq 'yakkety' || $suite eq 'zesty') {
457 push @$incl, 'isc-dhcp-client';
458 push @$excl, qw(libmodule-build-perl);
459 } elsif ($suite eq 'trusty') {
460 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
461 } elsif ($suite eq 'precise') {
462 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
463 } elsif ($suite eq 'hardy') {
464 push @$excl, qw(kbd);
465 push @$excl, qw(apparmor apparmor-utils ntfs-3g
467 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
468 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
469 libntfs-3g28 ntfs-3g friendly-recovery);
470 } elsif ($suite eq 'jessie') {
471 push @$incl, 'sysvinit-core'; # avoid systemd and udev
472 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
473 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm
475 } elsif ($suite eq 'stretch') {
476 push @$excl, qw(module-init-tools pciutils hdparm
479 push @$excl, qw(udev module-init-tools pciutils hdparm
483 $self->{incl
} = $incl;
484 $self->{excl
} = $excl;
492 my $infodir = $self->{infodir
};
493 my $arch = $self->{config
}->{architecture
};
499 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
500 die "unable to open log file";
502 foreach my $ss (@{$self->{sources
}}) {
503 my $src = $ss->{mirror
} || $ss->{source
};
504 my $path = "dists/$ss->{suite}/Release";
505 my $url = "$src/$path";
506 my $target = __url_to_filename
("$ss->{source}/$path");
508 $self->download ($url, "$infodir/$target");
509 $self->download ("$url.gpg", "$infodir/$target.gpg");
510 # fixme: impl. verify (needs --keyring option)
514 warn "Release info ignored\n";
516 foreach my $comp (@{$ss->{comp
}}) {
517 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.gz";
518 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
519 my $pkgsrc = "$src/$path";
520 $self->download ($pkgsrc, $target);
521 $self->run_command ("gzip -d '$target'");
527 my ($self, $filename, $size) = @_;
529 my $config = $self->{config
};
533 $data .= "Name: $config->{name}\n";
534 $data .= "Version: $config->{version}\n";
535 $data .= "Type: lxc\n";
536 $data .= "OS: $config->{ostype}\n";
537 $data .= "Section: $config->{section}\n";
538 $data .= "Maintainer: $config->{maintainer}\n";
539 $data .= "Architecture: $config->{architecture}\n";
540 $data .= "Installed-Size: $size\n";
543 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
544 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
545 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
548 $data .= "Description: $config->{headline}\n";
549 $data .= "$config->{description}\n" if $config->{description
};
551 write_file
($data, $filename, 0644);
555 my ($self, $opts) = @_;
557 my $suite = $self->{config
}->{suite
};
558 my $infodir = $self->{infodir
};
559 my $arch = $self->{config
}->{architecture
};
561 my $instpkgs = $self->read_installed ();
562 my $pkginfo = $self->pkginfo();
563 my $veid = $self->{veid
};
564 my $conffile = $self->{veconffile
};
565 my $rootdir = $self->{rootfs
};
567 my $vestat = $self->ve_status();
568 die "ve not running - unable to finalize\n" if !$vestat->{running
};
571 if (-f
"$rootdir/etc/init.d/mysql") {
572 $self->ve_command ("/etc/init.d/mysql stop");
575 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
576 unlink "$rootdir/root/.my.cnf";
579 if ($suite eq 'etch') {
580 # enable apache2 startup
581 if ($instpkgs->{apache2
}) {
582 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
584 unlink "$rootdir/etc/default/apache2";
587 $self->logmsg ("cleanup package status\n");
588 # prevent auto selection of all standard, required or important
589 # packages which are not installed
590 foreach my $pkg (keys %$pkginfo) {
591 my $pri = $pkginfo->{$pkg}->{priority
};
592 if ($pri && ($pri eq 'required' || $pri eq 'important'
593 || $pri eq 'standard')) {
594 if (!$instpkgs->{$pkg}) {
595 $self->ve_dpkg_set_selection ($pkg, 'purge');
600 $self->ve_command ("apt-get clean");
602 $self->logmsg ("update available package list\n");
604 $self->ve_command ("dpkg --clear-avail");
605 foreach my $ss (@{$self->{sources
}}) {
606 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
607 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
608 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
609 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
611 foreach my $comp (@{$ss->{comp
}}) {
612 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
613 "$comp/binary-$arch/Packages");
614 my $target = "/var/lib/apt/lists/$src";
615 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
616 $self->ve_command ("dpkg --merge-avail '$target'");
620 # set dselect default method
621 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
623 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
625 $self->ve_divert_remove ("/sbin/start-stop-daemon");
627 $self->ve_divert_remove ("/sbin/init");
629 # finally stop the VE
630 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
632 unlink "$rootdir/sbin/defenv";
634 unlink <$rootdir/root/dead.letter
*>;
636 unlink "$rootdir/var/log/init.log";
638 unlink "$rootdir/aquota.group";
640 unlink "$rootdir/aquota.user";
642 write_file
("", "$rootdir/var/log/syslog");
644 $self->logmsg ("detecting final size: ");
646 my $sizestr = $self->run_command ("du -sm $rootdir", undef, 1);
648 if ($sizestr =~ m/^(\d+)\s+\Q$rootdir\E$/) {
651 die "unable to detect size\n";
653 $self->logmsg ("$size MB\n");
655 $self->write_config ("$rootdir/etc/appliance.info", $size);
657 $self->logmsg ("creating final appliance archive\n");
659 my $target = "$self->{targetname}.tar";
663 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
664 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
665 $self->run_command ("gzip $target");
671 my $rootdir = $self->{rootfs
};
673 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
675 open (PKGLST
, "<$pkgfilelist") ||
676 die "unable to open '$pkgfilelist'";
680 while (my $rec = <PKGLST
>) {
686 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
690 my $pkg = $res->{'package'};
691 if (my $status = $res->{status
}) {
692 my @sa = split (/\s+/, $status);
694 if ($stat && ($stat ne 'purge')) {
695 $pkglist->{$pkg} = $res;
708 my $veid = $self->{veid
};
710 my $res = { running
=> 0 };
712 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
714 my $filename = "/proc/net/unix";
716 # similar test is used by lcxcontainers.c: list_active_containers
717 my $fh = IO
::File-
>new ($filename, "r");
720 while (defined(my $line = <$fh>)) {
721 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
723 if ($path =~ m!^@/\S+/$veid/command$!) {
734 my ($self, $cmd, $input) = @_;
736 my $veid = $self->{veid
};
737 my $conffile = $self->{veconffile
};
739 if (ref ($cmd) eq 'ARRAY') {
740 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
741 $self->run_command ($cmd, $input);
743 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
747 # like ve_command, but pipes stdin correctly
749 my ($self, @cmd) = @_;
751 my $veid = $self->{veid
};
752 my $conffile = $self->{veconffile
};
755 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
756 'defenv', @cmd) || die "unable to exec command";
758 while (defined (my $line = <$reader>)) {
759 $self->logmsg ($line);
765 die "ve_exec failed - status $rc\n" if $rc != 0;
769 my ($self, $filename) = @_;
771 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
772 "--rename '$filename'");
774 sub ve_divert_remove
{
775 my ($self, $filename) = @_;
777 my $rootdir = $self->{rootfs
};
779 unlink "$rootdir/$filename";
780 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
783 sub ve_debconfig_set
{
784 my ($self, $dcdata) = @_;
786 my $rootdir = $self->{rootfs
};
787 my $cfgfile = "/tmp/debconf.txt";
788 write_file
($dcdata, "$rootdir/$cfgfile");
789 $self->ve_command ("debconf-set-selections $cfgfile");
790 unlink "$rootdir/$cfgfile";
793 sub ve_dpkg_set_selection
{
794 my ($self, $pkg, $status) = @_;
796 $self->ve_command ("dpkg --set-selections", "$pkg $status");
800 my ($self, $cmd, @pkglist) = @_;
802 return if !scalar (@pkglist);
804 my $pkginfo = $self->pkginfo();
806 my $rootdir = $self->{rootfs
};
807 my $cachedir = $self->{cachedir
};
811 foreach my $pkg (@pkglist) {
812 my $filename = $self->getpkgfile ($pkg);
813 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
814 push @files, "/$filename";
815 $self->logmsg ("$cmd: $pkg\n");
818 my $fl = join (' ', @files);
820 if ($cmd eq 'install') {
821 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
822 } elsif ($cmd eq 'unpack') {
823 $self->ve_command ("dpkg --force-depends --unpack $fl");
825 die "internal error";
828 foreach my $fn (@files) { unlink "$rootdir$fn"; }
834 my $veid = $self->{veid
}; # fixme
835 my $conffile = $self->{veconffile
};
837 my $vestat = $self->ve_status();
838 if ($vestat->{running
}) {
839 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
842 rmtree
$self->{rootfs
};
843 unlink $self->{veconffile
};
849 my $veid = $self->{veid
};
850 my $conffile = $self->{veconffile
};
852 $self->logmsg ("initialize VE $veid\n");
854 my $vestat = $self->ve_status();
855 if ($vestat->{running
}) {
856 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
859 rmtree
$self->{rootfs
};
860 mkpath
$self->{rootfs
};
863 sub __deb_version_cmp
{
864 my ($cur, $op, $new) = @_;
866 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
873 sub __parse_packages
{
874 my ($pkginfo, $filename, $src) = @_;
877 open (PKGLST
, "<$filename") ||
878 die "unable to open '$filename'";
880 while (my $rec = <PKGLST
>) {
887 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
891 my $pkg = $res->{'package'};
892 if ($pkg && $res->{'filename'}) {
894 if (my $info = $pkginfo->{$pkg}) {
895 $cur = $info->{version
};
897 my $new = $res->{version
};
898 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
900 $res->{url
} = "$src/$res->{'filename'}";
902 die "no url for package '$pkg'" if !$res->{url
};
904 $pkginfo->{$pkg} = $res;
915 return $self->{pkginfo
} if $self->{pkginfo
};
917 my $infodir = $self->{infodir
};
918 my $arch = $self->{config
}->{architecture
};
920 my $availfn = "$infodir/available";
925 # reading 'available' is faster, because it only contains latest version
926 # (no need to do slow version compares)
928 __parse_packages
($pkginfo, $availfn);
929 $self->{pkginfo
} = $pkginfo;
933 $self->logmsg ("generating available package list\n");
935 foreach my $ss (@{$self->{sources
}}) {
936 foreach my $comp (@{$ss->{comp
}}) {
937 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
938 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
940 my $src = $ss->{mirror
} || $ss->{source
};
942 __parse_packages
($pkginfo, $pkgfilelist, $src);
946 if (my $dep = $self->{config
}->{depends
}) {
947 foreach my $d (split (/,/, $dep)) {
948 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
949 my ($pkg, $op, $rver) = ($1, $3, $4);
950 $self->logmsg ("checking dependencies: $d\n");
951 my $info = $pkginfo->{$pkg};
952 die "package '$pkg' not available\n" if !$info;
954 my $cver = $info->{version
};
955 if (!__deb_version_cmp
($cver, $op, $rver)) {
956 die "detected wrong version '$cver'\n";
960 die "syntax error in depends field";
965 $self->{pkginfo
} = $pkginfo;
967 my $tmpfn = "$availfn.tmp$$";
968 my $fd = IO
::File-
>new (">$tmpfn");
969 foreach my $pkg (sort keys %$pkginfo) {
970 my $info = $pkginfo->{$pkg};
971 print $fd "package: $pkg\n";
972 foreach my $k (sort keys %$info) {
973 next if $k eq 'description';
974 next if $k eq 'package';
976 print $fd "$k: $v\n" if $v;
978 print $fd "description: $info->{description}\n" if $info->{description
};
983 rename ($tmpfn, $availfn);
988 sub __record_provides
{
989 my ($pkginfo, $closure, $list, $skipself) = @_;
991 foreach my $pname (@$list) {
992 my $info = $pkginfo->{$pname};
993 # fixme: if someone install packages directly using dpkg, there
994 # is no entry in 'available', only in 'status'. In that case, we
995 # should extract info from $instpkgs
997 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1000 if (my $prov = $info->{provides
}) {
1001 my @pl = split (',', $prov);
1002 foreach my $p (@pl) {
1004 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1009 $closure->{$pname} = 1 if !$skipself;
1014 my ($self, $closure, $list) = @_;
1016 my $pkginfo = $self->pkginfo();
1018 # first, record provided packages
1019 __record_provides
($pkginfo, $closure, $list, 1);
1023 # then resolve dependencies
1024 foreach my $pname (@$list) {
1025 __closure_single
($pkginfo, $closure, $pkgs, $pname, $self->{excl
});
1028 return [ keys %$pkgs ];
1031 sub __closure_single
{
1032 my ($pkginfo, $closure, $pkgs, $pname, $excl) = @_;
1036 $pname =~ s/:any$//;
1038 return if $closure->{$pname};
1040 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1042 my $dep = $info->{depends
};
1043 my $predep = $info->{'pre-depends'};
1045 my $size = $info->{size
};
1046 my $url = $info->{url
};
1048 $url || die "$pname: no url for package '$pname'";
1050 $pkgs->{$pname} = 1;
1052 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1054 $closure->{$pname} = 1;
1060 push @l, split (/,/, $predep) if $predep;
1061 push @l, split (/,/, $dep) if $dep;
1063 DEPEND
: foreach my $p (@l) {
1064 my @l1 = split (/\|/, $p);
1065 foreach my $p1 (@l1) {
1066 if ($p1 =~ m/^\s*(\S+).*/) {
1067 #printf (STDERR "$pname: $p --> $1\n");
1068 if ($closure->{$1}) {
1069 next DEPEND
; # dependency already met
1073 # search for non-excluded alternative
1075 foreach my $p1 (@l1) {
1076 if ($p1 =~ m/^\s*(\S+).*/) {
1077 next if grep { $1 eq $_ } @$excl;
1082 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1084 #printf (STDERR "$pname: $p --> $found\n");
1086 __closure_single
($pkginfo, $closure, $pkgs, $found, $excl);
1090 sub cache_packages
{
1091 my ($self, $pkglist) = @_;
1093 foreach my $pkg (@$pkglist) {
1094 $self->getpkgfile ($pkg);
1099 my ($self, $pkg) = @_;
1101 my $pkginfo = $self->pkginfo();
1102 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1103 my $cachedir = $self->{cachedir
};
1105 my $url = $info->{url
};
1108 if ($url =~ m
|/([^/]+.deb
)$|) {
1111 die "internal error";
1114 return $filename if -f
"$cachedir/$filename";
1118 $self->download ($url, "$cachedir/$filename");
1123 sub install_init_script
{
1124 my ($self, $script, $runlevel, $prio) = @_;
1126 my $suite = $self->{config
}->{suite
};
1127 my $rootdir = $self->{rootfs
};
1129 my $base = basename
($script);
1130 my $target = "$rootdir/etc/init.d/$base";
1132 $self->run_command ("install -m 0755 '$script' '$target'");
1133 if ($suite eq 'etch' || $suite eq 'lenny') {
1134 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1135 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1136 $suite eq 'yakkety' || $suite eq 'zesty') {
1137 die "unable to install init script (system uses systemd)\n";
1138 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1139 die "unable to install init script (system uses upstart)\n";
1141 $self->ve_command ("insserv $base");
1148 my ($self, $opts) = @_;
1150 my $pkginfo = $self->pkginfo();
1151 my $veid = $self->{veid
};
1152 my $suite = $self->{config
}->{suite
};
1154 my $important = [ @{$self->{incl
}} ];
1158 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1160 if ($mta eq 'postfix') {
1161 push @$important, "postfix";
1164 foreach my $p (keys %$pkginfo) {
1165 next if grep { $p eq $_ } @{$self->{excl
}};
1166 my $pri = $pkginfo->{$p}->{priority
};
1168 next if $mta ne 'exim' && $p =~ m/exim/;
1169 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1171 push @$required, $p if $pri eq 'required';
1172 push @$important, $p if $pri eq 'important';
1173 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1177 $required = $self->closure ($closure, $required);
1178 $important = $self->closure ($closure, $important);
1180 if (!$opts->{minimal
}) {
1181 push @$standard, 'xbase-clients';
1182 $standard = $self->closure ($closure, $standard);
1185 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1186 # except those explicitly excluded
1187 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1188 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1189 foreach my $d (split (/,/, $mdeps)) {
1190 if ($d =~ m/^\s*(\S+)$/) {
1192 next if $closure->{$pkg};
1193 next if grep { $pkg eq $_ } @{$self->{excl
}};
1194 die "missing ubuntu-minimal package '$pkg'\n";
1197 if (!$opts->{minimal
}) {
1198 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1199 foreach my $d (split (/,/, $mdeps)) {
1200 if ($d =~ m/^\s*(\S+)$/) {
1202 next if $closure->{$pkg};
1203 next if grep { $pkg eq $_ } @{$self->{excl
}};
1204 die "missing ubuntu-standard package '$pkg'\n";
1210 # download/cache all files first
1211 $self->cache_packages ($required);
1212 $self->cache_packages ($important);
1213 $self->cache_packages ($standard);
1215 my $rootdir = $self->{rootfs
};
1217 # extract required packages first
1218 $self->logmsg ("create basic environment\n");
1219 foreach my $p (@$required) {
1220 my $filename = $self->getpkgfile ($p);
1221 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1222 if ($content =~ m/^data.tar.xz$/m) {
1223 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1225 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1230 my $data = "Package: dpkg\n" .
1231 "Version: $pkginfo->{dpkg}->{version}\n" .
1232 "Status: install ok installed\n";
1234 write_file
($data, "$rootdir/var/lib/dpkg/status");
1235 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1236 write_file
("", "$rootdir/var/lib/dpkg/available");
1239 foreach my $ss (@{$self->{sources
}}) {
1240 my $url = $ss->{source
};
1241 my $comp = join (' ', @{$ss->{comp
}});
1242 $data .= "deb $url $ss->{suite} $comp\n\n";
1245 write_file
($data, "$rootdir/etc/apt/sources.list");
1247 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1248 write_file
($data, "$rootdir/etc/fstab", 0644);
1250 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1252 # avoid warnings about non-existent resolv.conf
1253 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1255 if ($suite eq 'zesty' || $suite eq 'yakkety' ||
1256 $suite eq 'xenial' || $suite eq 'wily') {
1257 # no need to configure loopback device
1259 $data = "auto lo\niface lo inet loopback\n";
1260 mkdir "$rootdir/etc/network";
1261 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1265 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1267 # avoid warnings about missing default locale
1268 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1271 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1272 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1274 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1276 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1278 $self->logmsg ("initialize ld cache\n");
1279 $self->ve_command ("/sbin/ldconfig");
1280 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1282 $self->logmsg ("installing packages\n");
1284 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1286 $self->ve_dpkg ('install', 'dpkg');
1288 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1290 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1292 $self->ve_dpkg ('install', 'libc6');
1293 $self->ve_dpkg ('install', 'perl-base');
1295 unlink "$rootdir/usr/bin/awk";
1297 $self->ve_dpkg ('install', 'mawk');
1298 $self->ve_dpkg ('install', 'debconf');
1300 if ($suite eq 'trusty') {
1301 # hack: util-linux preinst calls update-rc.d, which calls /sbin/insserv
1302 $self->run_command ("ln -s /usr/lib/insserv/insserv '$rootdir/sbin/insserv'");
1305 # unpack required packages
1306 foreach my $p (@$required) {
1307 $self->ve_dpkg ('unpack', $p);
1310 if ($suite eq 'trusty') {
1311 $self->run_command ("rm '$rootdir/sbin/insserv'");
1314 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1315 $self->ve_divert_add ("/sbin/init");
1316 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1318 # disable service activation
1319 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1320 $data = "#!/bin/sh\nexit 101\n";
1321 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1323 # disable start-stop-daemon
1324 $self->ve_divert_add ("/sbin/start-stop-daemon");
1328 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1330 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1333 $self->ve_divert_add ("/sbin/udevd");
1335 if ($suite eq 'etch') {
1336 # disable apache2 startup
1337 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1340 $self->logmsg ("configure required packages\n");
1341 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1343 # set postfix defaults
1344 if ($mta eq 'postfix') {
1345 $data = "postfix postfix/main_mailer_type select Local only\n";
1346 $self->ve_debconfig_set ($data);
1348 $data = "postmaster: root\nwebmaster: root\n";
1349 write_file
($data, "$rootdir/etc/aliases");
1352 if ($suite eq 'jaunty') {
1353 # jaunty does not create /var/run/network, so network startup fails.
1354 # so we do not use tmpfs for /var/run and /var/lock
1355 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1356 # and create the directory here
1357 $self->run_command ("mkdir $rootdir/var/run/network");
1360 # unpack base packages
1361 foreach my $p (@$important) {
1362 $self->ve_dpkg ('unpack', $p);
1366 if (-x
"$rootdir/sbin/ifconfig") {
1367 $self->ve_command ("ifconfig lo up");
1369 $self->ve_command ("ip link set lo up");
1372 $self->logmsg ("configure important packages\n");
1373 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1375 if (-d
"$rootdir/etc/event.d") {
1376 unlink <$rootdir/etc/event.d
/tty
*>;
1379 if (-f
"$rootdir/etc/inittab") {
1380 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1383 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1384 unlink "$rootdir/etc/mtab";
1385 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1388 $self->ve_command ("usermod -L root");
1390 if ($mta eq 'postfix') {
1391 $data = "postfix postfix/main_mailer_type select No configuration\n";
1392 $self->ve_debconfig_set ($data);
1394 unlink "$rootdir/etc/mailname";
1395 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1398 if (!$opts->{minimal
}) {
1399 # unpack standard packages
1400 foreach my $p (@$standard) {
1401 $self->ve_dpkg ('unpack', $p);
1404 $self->logmsg ("configure standard packages\n");
1405 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1408 # disable HWCLOCK access
1409 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1412 $self->ve_divert_add ("/usr/sbin/hald");
1414 # disable /dev/urandom init
1415 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1417 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1419 $self->ve_divert_add ("/sbin/klogd");
1422 # remove unnecessays sysctl entries to avoid warnings
1424 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1425 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1426 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1427 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1428 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1429 $self->run_command ($cmd);
1431 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1432 if (-f
$bindv6only) {
1434 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1435 $cmd .= " -i '$bindv6only'";
1436 $self->run_command ($cmd);
1439 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1440 # disable tty init (console-setup)
1442 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1443 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1444 $self->run_command ($cmd);
1447 if ($suite eq 'intrepid') {
1448 # remove sysctl setup (avoid warnings at startup)
1449 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1450 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf";
1451 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1452 $self->run_command ("rm $filelist");
1454 if ($suite eq 'jaunty') {
1455 # remove sysctl setup (avoid warnings at startup)
1456 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1457 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1458 $self->run_command ("rm $filelist");
1465 my $veid = $self->{veid
};
1466 my $conffile = $self->{veconffile
};
1468 my $vestat = $self->ve_status();
1470 if (!$vestat->{exist
}) {
1471 $self->logmsg ("Please create the appliance first (bootstrap)");
1475 if (!$vestat->{running
}) {
1476 $self->run_command ("lxc-start -n $veid -f $conffile");
1479 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1482 sub ve_mysql_command
{
1483 my ($self, $sql, $password) = @_;
1485 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1486 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1488 $self->ve_command ("mysql", $sql);
1491 sub ve_mysql_bootstrap
{
1492 my ($self, $sql, $password) = @_;
1496 my $suite = $self->{config
}->{suite
};
1498 if ($suite eq 'jessie') {
1499 my $rootdir = $self->{rootfs
};
1500 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1503 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1504 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1507 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1508 "--skip-bdb --skip-innodb --skip-ndbcluster";
1511 $self->ve_command ($cmd, $sql);
1514 sub compute_required
{
1515 my ($self, $pkglist) = @_;
1517 my $pkginfo = $self->pkginfo();
1518 my $instpkgs = $self->read_installed ();
1521 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1523 return $self->closure ($closure, $pkglist);
1527 my ($self, $opts) = @_;
1529 my @supp = ('7.4', '8.1');
1530 my $pgversion = '8.1';
1532 my $suite = $self->{config
}->{suite
};
1534 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1537 } elsif ($suite eq 'squeeze') {
1540 } elsif ($suite eq 'wheezy') {
1543 } elsif ($suite eq 'jessie') {
1546 } elsif ($suite eq 'stretch') {
1551 $pgversion = $opts->{version
} if $opts->{version
};
1553 die "unsupported postgres version '$pgversion'\n"
1554 if !grep { $pgversion eq $_; } @supp;
1556 my $rootdir = $self->{rootfs
};
1558 my $required = $self->compute_required (["postgresql-$pgversion"]);
1560 $self->cache_packages ($required);
1562 $self->ve_dpkg ('install', @$required);
1564 my $iscript = "postgresql-$pgversion";
1565 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1566 $suite eq 'stretch') {
1567 $iscript = 'postgresql';
1570 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1574 my ($self, $opts) = @_;
1576 my $password = $opts->{password
};
1577 my $rootdir = $self->{rootfs
};
1579 my $suite = $self->{config
}->{suite
};
1582 if ($suite eq 'squeeze') {
1584 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1587 die "task_mysql: unsupported suite '$suite'";
1590 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1592 $self->cache_packages ($required);
1594 $self->ve_dpkg ('install', @$required);
1596 # fix security (see /usr/bin/mysql_secure_installation)
1597 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1598 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1599 "FLUSH PRIVILEGES;\n";
1600 $self->ve_mysql_bootstrap ($sql);
1604 my $rpw = $password eq 'random' ?
'admin' : $password;
1606 my $sql = "USE mysql;\n" .
1607 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1608 "FLUSH PRIVILEGES
;\n";
1609 $self->ve_mysql_bootstrap ($sql);
1611 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1612 if ($password eq 'random') {
1613 $self->install_init_script ($script_mysql_randompw, 2, 20);
1617 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1621 my ($self, $opts) = @_;
1623 my $memlimit = $opts->{memlimit
};
1624 my $rootdir = $self->{rootfs
};
1626 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1628 $self->cache_packages ($required);
1630 $self->ve_dpkg ('install', @$required);
1633 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1638 my ($self, $pkglist, $unpack) = @_;
1640 my $required = $self->compute_required ($pkglist);
1642 $self->cache_packages ($required);
1644 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1648 my ($self, $distclean) = @_;
1650 unlink $self->{logfile
};
1651 unlink "$self->{targetname}.tar";
1652 unlink "$self->{targetname}.tar.gz";
1654 $self->ve_destroy ();
1657 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1659 rmtree
$self->{infodir
};