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",
101 ostype
=> "devuan-3.0",
104 ostype
=> "devuan-4.0",
109 ostype
=> "ubuntu-8.04",
113 ostype
=> "ubuntu-8.10",
117 ostype
=> "ubuntu-9.04",
121 ostype
=> "ubuntu-12.04",
125 ostype
=> "ubuntu-14.04",
129 ostype
=> "ubuntu-15.04",
133 ostype
=> "ubuntu-15.10",
137 ostype
=> "ubuntu-16.04",
141 ostype
=> "ubuntu-16.10",
145 ostype
=> "ubuntu-17.04",
149 ostype
=> "ubuntu-17.10",
153 ostype
=> "ubuntu-18.04",
157 ostype
=> "ubuntu-18.10",
161 ostype
=> "ubuntu-19.04",
165 ostype
=> "ubuntu-19.10",
169 ostype
=> "ubuntu-20.04",
173 ostype
=> "ubuntu-20.10",
177 ostype
=> "ubuntu-21.04",
185 my $suiteinfo = $supported_suites->{$suite} || die "unsupported suite '$suite'!\n";
188 $suiteinfo->{origin
} //= 'debian';
189 $suiteinfo->{suite
} //= $suite;
195 my ($self, $url, $path) = @_;
197 $self->logmsg ("download: $url\n");
198 my $tmpfn = "$path.tmp$$";
200 $self->run_command ("wget -q '$url' -O '$tmpfn'");
209 rename ($tmpfn, $path);
213 my ($data, $file, $perm) = @_;
215 die "no filename" if !$file;
219 my $fh = IO
::File-
>new ($file, O_WRONLY
| O_CREAT
, $perm) ||
220 die "unable to open file '$file'";
230 die "no filename" if !$file;
232 my $fh = IO
::File-
>new ($file) ||
233 die "unable to open file '$file'";
235 local $/; # slurp mode
249 my $fh = IO
::File-
>new ("<$filename") || return $res;
252 while (defined (my $line = <$fh>)) {
253 next if $line =~ m/^\#/;
254 next if $line =~ m/^\s*$/;
264 if ($rec =~ s/^Description:\s*([^\n]*)(\n\s+.*)*$//si) {
265 $res->{headline
} = $1;
266 chomp $res->{headline
};
269 $res->{description
} = $long;
270 chomp $res->{description
};
271 } elsif ($rec =~ s/^([^:]+):\s*(.*\S)\s*\n//) {
272 my ($key, $value) = (lc ($1), $2);
273 if ($key eq 'source' || $key eq 'mirror') {
274 push @{$res->{$key}}, $value;
276 die "duplicate key '$key'\n" if defined ($res->{$key});
277 $res->{$key} = $value;
280 die "unable to parse config file: $rec";
284 die "unable to parse config file" if $rec;
290 my ($self, $cmd, $input, $getoutput) = @_;
292 my $reader = IO
::File-
>new();
293 my $writer = IO
::File-
>new();
294 my $error = IO
::File-
>new();
298 my $cmdstr = ref ($cmd) eq 'ARRAY' ?
join (' ', @$cmd) : $cmd;
302 if (ref ($cmd) eq 'ARRAY') {
303 $pid = open3
($writer, $reader, $error, @$cmd) || die $!;
305 $pid = open3
($writer, $reader, $error, $cmdstr) || die $!;
312 if ($orig_pid != $$) {
313 $self->logmsg ("ERROR: command '$cmdstr' failed - fork failed\n");
320 print $writer $input if defined $input;
323 my $select = new IO
::Select
;
324 $select->add ($reader);
325 $select->add ($error);
328 my $logfd = $self->{logfd
};
330 while ($select->count) {
331 my @handles = $select->can_read ();
333 foreach my $h (@handles) {
335 my $count = sysread ($h, $buf, 4096);
336 if (!defined ($count)) {
338 die "command '$cmdstr' failed: $!";
340 $select->remove ($h) if !$count;
344 $res .= $buf if $getoutput;
351 die "command '$cmdstr' failed with exit code $ec\n" if $ec;
359 $self->writelog (@_);
364 my $fd = $self->{logfd
};
368 sub __sample_config
{
372 my $arch = $self->{config
}->{architecture
};
374 my $ostype = $self->{config
}->{ostype
};
376 if ($ostype =~ m/^de(bi|vu)an-/) {
377 $data .= "lxc.include = /usr/share/lxc/config/debian.common.conf\n";
378 } elsif ($ostype =~ m/^ubuntu-/) {
379 $data .= "lxc.include = /usr/share/lxc/config/ubuntu.common.conf\n";
381 die "unknown os type '$ostype'\n";
383 $data .= "lxc.uts.name = localhost\n";
384 $data .= "lxc.rootfs.path = $self->{rootfs}\n";
393 if (my $fd = IO
::File-
>new (".veid")) {
400 $self->{working_dir
} = getcwd
;
401 $self->{veconffile
} = "$self->{working_dir}/config";
402 $self->{rootfs
} = "$self->{working_dir}/rootfs";
405 $self->{veid
} = $cid;
411 UUID
::generate
($uuid);
412 UUID
::unparse
($uuid, $uuid_str);
413 $self->{veid
} = $uuid_str;
415 my $fd = IO
::File-
>new (">.veid") ||
416 die "unable to write '.veid'\n";
417 print $fd "$self->{veid}\n";
420 my $cdata = $self->__sample_config();
422 my $fh = IO
::File-
>new ($self->{veconffile
}, O_WRONLY
|O_CREAT
|O_EXCL
) ||
423 die "unable to write lxc config file '$self->{veconffile}' - $!";
427 mkdir $self->{rootfs
} || die "unable to create rootfs - $!";
429 $self->logmsg ("allocated VE $self->{veid}\n");
431 return $self->{veid
};
435 my ($class, $config) = @_;
437 $class = ref ($class) || $class;
441 $config = read_config
('dab.conf') if !$config;
443 $self->{config
} = $config;
447 $self->{logfile
} = "logfile";
448 $self->{logfd
} = IO
::File-
>new (">>$self->{logfile}") ||
449 die "unable to open log file";
451 my $arch = $config->{architecture
};
452 die "no 'architecture' specified\n" if !$arch;
454 die "unsupported architecture '$arch'\n"
455 if $arch !~ m/^(i386|amd64)$/;
457 my $suite = $config->{suite
} || die "no 'suite' specified\n";
459 my $suiteinfo = get_suite_info
($suite);
460 $suite = $suiteinfo->{suite
};
461 $config->{ostype
} = $suiteinfo->{ostype
};
463 my $name = $config->{name
} || die "no 'name' specified\n";
465 $name =~ m/^[a-z][0-9a-z\-\*\.]+$/ ||
466 die "illegal characters in name '$name'\n";
468 my $version = $config->{version
};
469 die "no 'version' specified\n" if !$version;
470 die "no 'section' specified\n" if !$config->{section
};
471 die "no 'description' specified\n" if !$config->{headline
};
472 die "no 'maintainer' specified\n" if !$config->{maintainer
};
474 if ($name =~ m/^$config->{ostype}/) {
475 $self->{targetname
} = "${name}_${version}_$config->{architecture}";
477 $self->{targetname
} = "$config->{ostype}-${name}_" .
478 "${version}_$config->{architecture}";
481 if (!$config->{source
}) {
482 if (lc($suiteinfo->{origin
}) eq 'debian') {
483 if ($suite eq 'etch' || $suite eq 'lenny') {
484 push @{$config->{source
}}, (
485 'http://ftp.debian.org/debian SUITE main contrib',
486 'http://security.debian.org SUITE/updates main contrib',
488 } elsif ($suite eq 'bullseye') {
489 push @{$config->{source
}}, (
490 "http://ftp.debian.org/debian SUITE main contrib",
491 "http://ftp.debian.org/debian SUITE-updates main contrib",
492 "http://security.debian.org SUITE-security main contrib",
495 push @{$config->{source
}}, (
496 "http://ftp.debian.org/debian SUITE main contrib",
497 "http://ftp.debian.org/debian SUITE-updates main contrib",
498 "http://security.debian.org SUITE/updates main contrib",
501 } elsif (lc($suiteinfo->{origin
}) eq 'ubuntu') {
502 my $comp = "main restricted universe multiverse";
503 push @{$config->{source
}}, (
504 "http://archive.ubuntu.com/ubuntu SUITE $comp",
505 "http://archive.ubuntu.com/ubuntu SUITE-updates $comp",
506 "http://archive.ubuntu.com/ubuntu SUITE-security $comp",
515 foreach my $s (@{$config->{source
}}) {
516 if ($s =~ m
@^\s*((http
|ftp
)://\S
+)\s
+(\S
+)((\s
+(\S
+))+)$@) {
517 my ($url, $su, $components) = ($1, $3, $4);
518 $su =~ s/SUITE/$suite/;
519 $components =~ s/^\s+//;
520 $components =~ s/\s+$//;
522 foreach my $co (split (/\s+/, $components)) {
525 $ca = ['main'] if !$ca;
533 die "syntax error in source spezification '$s'\n";
537 foreach my $m (@{$config->{mirror
}}) {
538 if ($m =~ m
@^\s*((http
|ftp
)://\S
+)\s
*=>\s
*((http
|ftp
)://\S
+)\s
*$@) {
539 my ($ms, $md) = ($1, $3);
541 foreach my $ss (@$sources) {
542 if ($ss->{source
} eq $ms) {
548 die "unusable mirror $ms\n" if !$found;
550 die "syntax error in mirror spezification '$m'\n";
554 $self->{sources
} = $sources;
556 $self->{infodir
} = "info";
558 $self->__allocate_ve ();
560 $self->{cachedir
} = ($config->{cachedir
} || 'cache') . "/$suite";;
562 my $incl = [qw
(less ssh openssh-server logrotate
)];
564 my $excl = [qw
(modutils reiserfsprogs ppp pppconfig pppoe
565 pppoeconf nfs-common mtools ntp
)];
567 # ubuntu has too many dependencies on udev, so
568 # we cannot exclude it (instead we disable udevd)
570 if ($suite eq 'vivid' || $suite eq 'wily' || $suite eq 'xenial' ||
571 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
572 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
573 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
574 || $suite eq 'hirsute'
576 push @$incl, 'isc-dhcp-client';
577 push @$excl, qw(libmodule-build-perl);
578 } elsif ($suite eq 'trusty') {
579 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+);
580 } elsif ($suite eq 'precise') {
581 push @$excl, qw(systemd systemd-services libpam-systemd libsystemd-daemon0 memtest86+ ubuntu-standard);
582 } elsif ($suite eq 'hardy') {
583 push @$excl, qw(kbd);
584 push @$excl, qw(apparmor apparmor-utils ntfs-3g
586 } elsif ($suite eq 'intrepid' || $suite eq 'jaunty') {
587 push @$excl, qw(apparmor apparmor-utils libapparmor1 libapparmor-perl
588 libntfs-3g28 ntfs-3g friendly-recovery);
589 } elsif ($suite eq 'jessie') {
590 push @$incl, 'sysvinit-core'; # avoid systemd and udev
591 push @$incl, 'libperl4-corelibs-perl'; # to make lsof happy
592 push @$excl, qw(systemd systemd-sysv udev module-init-tools pciutils hdparm
594 } elsif ($suite eq 'stretch' || $suite eq 'buster' || $suite eq 'bullseye') {
595 push @$excl, qw(module-init-tools pciutils hdparm
598 push @$excl, qw(udev module-init-tools pciutils hdparm
602 $self->{incl
} = $incl;
603 $self->{excl
} = $excl;
611 my $infodir = $self->{infodir
};
612 my $arch = $self->{config
}->{architecture
};
618 my $logfd = $self->{logfd
} = IO
::File-
>new (">$self->{logfile}") ||
619 die "unable to open log file";
621 # FIXME: seems a bit like a hacky way??
626 if ($self->{config
}->{suite
} eq 'bullseye') {
633 foreach my $ss (@{$self->{sources
}}) {
634 my $src = $ss->{mirror
} || $ss->{source
};
635 my $path = "dists/$ss->{suite}/Release";
636 my $url = "$src/$path";
637 my $target = __url_to_filename
("$ss->{source}/$path");
639 $self->download ($url, "$infodir/$target");
640 $self->download ("$url.gpg", "$infodir/$target.gpg");
641 # fixme: impl. verify (needs --keyring option)
645 warn "Release info ignored\n";
648 foreach my $comp (@{$ss->{comp
}}) {
649 $path = "dists/$ss->{suite}/$comp/binary-$arch/Packages.$COMPRESSOR->{ext}";
650 $target = "$infodir/" . __url_to_filename
("$ss->{source}/$path");
651 my $pkgsrc = "$src/$path";
652 $self->download ($pkgsrc, $target);
653 $self->run_command ("$COMPRESSOR->{decomp} '$target'");
659 my ($self, $filename, $size) = @_;
661 my $config = $self->{config
};
665 $data .= "Name: $config->{name}\n";
666 $data .= "Version: $config->{version}\n";
667 $data .= "Type: lxc\n";
668 $data .= "OS: $config->{ostype}\n";
669 $data .= "Section: $config->{section}\n";
670 $data .= "Maintainer: $config->{maintainer}\n";
671 $data .= "Architecture: $config->{architecture}\n";
672 $data .= "Installed-Size: $size\n";
675 $data .= "Infopage: $config->{infopage}\n" if $config->{infopage
};
676 $data .= "ManageUrl: $config->{manageurl}\n" if $config->{manageurl
};
677 $data .= "Certified: $config->{certified}\n" if $config->{certified
};
680 $data .= "Description: $config->{headline}\n";
681 $data .= "$config->{description}\n" if $config->{description
};
683 write_file
($data, $filename, 0644);
687 my ($self, $opts) = @_;
689 my $suite = $self->{config
}->{suite
};
690 my $infodir = $self->{infodir
};
691 my $arch = $self->{config
}->{architecture
};
693 my $instpkgs = $self->read_installed ();
694 my $pkginfo = $self->pkginfo();
695 my $veid = $self->{veid
};
696 my $conffile = $self->{veconffile
};
697 my $rootdir = $self->{rootfs
};
699 my $vestat = $self->ve_status();
700 die "ve not running - unable to finalize\n" if !$vestat->{running
};
703 if (-f
"$rootdir/etc/init.d/mysql") {
704 $self->ve_command ("/etc/init.d/mysql stop");
707 if (!($opts->{keepmycnf
} || (-f
"$rootdir/etc/init.d/mysql_randompw"))) {
708 unlink "$rootdir/root/.my.cnf";
711 if ($suite eq 'etch') {
712 # enable apache2 startup
713 if ($instpkgs->{apache2
}) {
714 write_file
("NO_START=0\n", "$rootdir/etc/default/apache2");
716 unlink "$rootdir/etc/default/apache2";
719 $self->logmsg ("cleanup package status\n");
720 # prevent auto selection of all standard, required or important
721 # packages which are not installed
722 foreach my $pkg (keys %$pkginfo) {
723 my $pri = $pkginfo->{$pkg}->{priority
};
724 if ($pri && ($pri eq 'required' || $pri eq 'important'
725 || $pri eq 'standard')) {
726 if (!$instpkgs->{$pkg}) {
727 $self->ve_dpkg_set_selection ($pkg, 'purge');
732 $self->ve_command ("apt-get clean");
734 $self->logmsg ("update available package list\n");
736 $self->ve_command ("dpkg --clear-avail");
737 foreach my $ss (@{$self->{sources
}}) {
738 my $relsrc = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/Release");
739 if (-f
"$infodir/$relsrc" && -f
"$infodir/$relsrc.gpg") {
740 $self->run_command ("cp '$infodir/$relsrc' '$rootdir/var/lib/apt/lists/$relsrc'");
741 $self->run_command ("cp '$infodir/$relsrc.gpg' '$rootdir/var/lib/apt/lists/$relsrc.gpg'");
743 foreach my $comp (@{$ss->{comp
}}) {
744 my $src = __url_to_filename
("$ss->{source}/dists/$ss->{suite}/" .
745 "$comp/binary-$arch/Packages");
746 my $target = "/var/lib/apt/lists/$src";
747 $self->run_command ("cp '$infodir/$src' '$rootdir/$target'");
748 $self->ve_command ("dpkg --merge-avail '$target'");
752 # set dselect default method
753 write_file
("apt apt\n", "$rootdir/var/lib/dpkg/cmethopt");
755 $self->ve_divert_remove ("/usr/sbin/policy-rc.d");
757 $self->ve_divert_remove ("/sbin/start-stop-daemon");
759 $self->ve_divert_remove ("/sbin/init");
761 # finally stop the VE
762 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
764 unlink "$rootdir/sbin/defenv";
766 unlink <$rootdir/root/dead.letter
*>;
768 unlink "$rootdir/var/log/init.log";
770 unlink "$rootdir/aquota.group";
772 unlink "$rootdir/aquota.user";
774 write_file
("", "$rootdir/var/log/syslog");
776 my $get_path_size = sub {
778 my $sizestr = $self->run_command ("du -sm $path", undef, 1);
779 if ($sizestr =~ m/^(\d+)\s+\Q$path\E$/) {
782 die "unable to detect size for '$path'\n";
786 $self->logmsg ("detecting final appliance size: ");
787 my $size = $get_path_size->($rootdir);
788 $self->logmsg ("$size MB\n");
790 $self->write_config ("$rootdir/etc/appliance.info", $size);
792 $self->logmsg ("creating final appliance archive\n");
794 my $target = "$self->{targetname}.tar";
796 my $compressor = $opts->{compressor
} // 'gz';
797 my $compressor2cmd_map = {
802 'zstd-max' => 'zstd -19 -T0', # maximal level where the decompressor can still run efficiently
804 my $compressor2ending = {
809 my $compressor_cmd = $compressor2cmd_map->{$compressor};
810 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
811 if !defined($compressor_cmd);
813 my $ending = $compressor2ending->{$compressor} // $compressor;
814 my $final_archive = "${target}.${ending}";
816 unlink $final_archive;
818 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
819 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
820 $self->run_command ("$compressor_cmd $target");
822 $self->logmsg ("detecting final commpressed appliance size: ");
823 $size = $get_path_size->($final_archive);
824 $self->logmsg ("$size MB\n");
826 $self->logmsg ("appliance archive: $final_archive\n");
832 my $rootdir = $self->{rootfs
};
834 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
836 open (PKGLST
, "<$pkgfilelist") ||
837 die "unable to open '$pkgfilelist'";
841 while (my $rec = <PKGLST
>) {
847 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
851 my $pkg = $res->{'package'};
852 if (my $status = $res->{status
}) {
853 my @sa = split (/\s+/, $status);
855 if ($stat && ($stat ne 'purge')) {
856 $pkglist->{$pkg} = $res;
869 my $veid = $self->{veid
};
871 my $res = { running
=> 0 };
873 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
875 my $filename = "/proc/net/unix";
877 # similar test is used by lcxcontainers.c: list_active_containers
878 my $fh = IO
::File-
>new ($filename, "r");
881 while (defined(my $line = <$fh>)) {
882 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
884 if ($path =~ m!^@/\S+/$veid/command$!) {
895 my ($self, $cmd, $input) = @_;
897 my $veid = $self->{veid
};
898 my $conffile = $self->{veconffile
};
900 if (ref ($cmd) eq 'ARRAY') {
901 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
902 $self->run_command ($cmd, $input);
904 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
908 # like ve_command, but pipes stdin correctly
910 my ($self, @cmd) = @_;
912 my $veid = $self->{veid
};
913 my $conffile = $self->{veconffile
};
916 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
917 'defenv', @cmd) || die "unable to exec command";
919 while (defined (my $line = <$reader>)) {
920 $self->logmsg ($line);
926 die "ve_exec failed - status $rc\n" if $rc != 0;
930 my ($self, $filename) = @_;
932 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
933 "--rename '$filename'");
935 sub ve_divert_remove
{
936 my ($self, $filename) = @_;
938 my $rootdir = $self->{rootfs
};
940 unlink "$rootdir/$filename";
941 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
944 sub ve_debconfig_set
{
945 my ($self, $dcdata) = @_;
947 my $rootdir = $self->{rootfs
};
948 my $cfgfile = "/tmp/debconf.txt";
949 write_file
($dcdata, "$rootdir/$cfgfile");
950 $self->ve_command ("debconf-set-selections $cfgfile");
951 unlink "$rootdir/$cfgfile";
954 sub ve_dpkg_set_selection
{
955 my ($self, $pkg, $status) = @_;
957 $self->ve_command ("dpkg --set-selections", "$pkg $status");
961 my ($self, $cmd, @pkglist) = @_;
963 return if !scalar (@pkglist);
965 my $pkginfo = $self->pkginfo();
967 my $rootdir = $self->{rootfs
};
968 my $cachedir = $self->{cachedir
};
972 foreach my $pkg (@pkglist) {
973 my $filename = $self->getpkgfile ($pkg);
974 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
975 push @files, "/$filename";
976 $self->logmsg ("$cmd: $pkg\n");
979 my $fl = join (' ', @files);
981 if ($cmd eq 'install') {
982 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
983 } elsif ($cmd eq 'unpack') {
984 $self->ve_command ("dpkg --force-depends --unpack $fl");
986 die "internal error";
989 foreach my $fn (@files) { unlink "$rootdir$fn"; }
995 my $veid = $self->{veid
}; # fixme
996 my $conffile = $self->{veconffile
};
998 my $vestat = $self->ve_status();
999 if ($vestat->{running
}) {
1000 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1003 rmtree
$self->{rootfs
};
1004 unlink $self->{veconffile
};
1010 my $veid = $self->{veid
};
1011 my $conffile = $self->{veconffile
};
1013 $self->logmsg ("initialize VE $veid\n");
1015 my $vestat = $self->ve_status();
1016 if ($vestat->{running
}) {
1017 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1020 rmtree
$self->{rootfs
};
1021 mkpath
$self->{rootfs
};
1024 sub __deb_version_cmp
{
1025 my ($cur, $op, $new) = @_;
1027 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
1034 sub __parse_packages
{
1035 my ($pkginfo, $filename, $src) = @_;
1038 open (PKGLST
, "<$filename") ||
1039 die "unable to open '$filename'";
1041 while (my $rec = <PKGLST
>) {
1042 $rec =~ s/\n\s+/ /g;
1048 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
1052 my $pkg = $res->{'package'};
1053 if ($pkg && $res->{'filename'}) {
1055 if (my $info = $pkginfo->{$pkg}) {
1056 $cur = $info->{version
};
1058 my $new = $res->{version
};
1059 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1061 $res->{url
} = "$src/$res->{'filename'}";
1063 die "no url for package '$pkg'" if !$res->{url
};
1065 $pkginfo->{$pkg} = $res;
1076 return $self->{pkginfo
} if $self->{pkginfo
};
1078 my $infodir = $self->{infodir
};
1079 my $arch = $self->{config
}->{architecture
};
1081 my $availfn = "$infodir/available";
1086 # reading 'available' is faster, because it only contains latest version
1087 # (no need to do slow version compares)
1089 __parse_packages
($pkginfo, $availfn);
1090 $self->{pkginfo
} = $pkginfo;
1094 $self->logmsg ("generating available package list\n");
1096 foreach my $ss (@{$self->{sources
}}) {
1097 foreach my $comp (@{$ss->{comp
}}) {
1098 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1099 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1101 my $src = $ss->{mirror
} || $ss->{source
};
1103 __parse_packages
($pkginfo, $pkgfilelist, $src);
1107 if (my $dep = $self->{config
}->{depends
}) {
1108 foreach my $d (split (/,/, $dep)) {
1109 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1110 my ($pkg, $op, $rver) = ($1, $3, $4);
1111 $self->logmsg ("checking dependencies: $d\n");
1112 my $info = $pkginfo->{$pkg};
1113 die "package '$pkg' not available\n" if !$info;
1115 my $cver = $info->{version
};
1116 if (!__deb_version_cmp
($cver, $op, $rver)) {
1117 die "detected wrong version '$cver'\n";
1121 die "syntax error in depends field";
1126 $self->{pkginfo
} = $pkginfo;
1128 my $tmpfn = "$availfn.tmp$$";
1129 my $fd = IO
::File-
>new (">$tmpfn");
1130 foreach my $pkg (sort keys %$pkginfo) {
1131 my $info = $pkginfo->{$pkg};
1132 print $fd "package: $pkg\n";
1133 foreach my $k (sort keys %$info) {
1134 next if $k eq 'description';
1135 next if $k eq 'package';
1136 my $v = $info->{$k};
1137 print $fd "$k: $v\n" if $v;
1139 print $fd "description: $info->{description}\n" if $info->{description
};
1144 rename ($tmpfn, $availfn);
1149 sub __record_provides
{
1150 my ($pkginfo, $closure, $list, $skipself) = @_;
1152 foreach my $pname (@$list) {
1153 my $info = $pkginfo->{$pname};
1154 # fixme: if someone install packages directly using dpkg, there
1155 # is no entry in 'available', only in 'status'. In that case, we
1156 # should extract info from $instpkgs
1158 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1161 if (my $prov = $info->{provides
}) {
1162 my @pl = split (',', $prov);
1163 foreach my $p (@pl) {
1165 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1170 $closure->{$pname} = 1 if !$skipself;
1175 my ($self, $closure, $list) = @_;
1177 my $pkginfo = $self->pkginfo();
1179 # first, record provided packages
1180 __record_provides
($pkginfo, $closure, $list, 1);
1185 # then resolve dependencies
1186 foreach my $pname (@$list) {
1187 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1193 sub __closure_single
{
1194 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1198 $pname =~ s/:any$//;
1200 return if $closure->{$pname};
1202 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1204 my $dep = $info->{depends
};
1205 my $predep = $info->{'pre-depends'};
1207 my $size = $info->{size
};
1208 my $url = $info->{url
};
1210 $url || die "$pname: no url for package '$pname'";
1212 if (!$pkghash->{$pname}) {
1213 unshift @$pkglist, $pname;
1214 $pkghash->{$pname} = 1;
1217 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1219 $closure->{$pname} = 1;
1225 push @l, split (/,/, $predep) if $predep;
1226 push @l, split (/,/, $dep) if $dep;
1228 DEPEND
: foreach my $p (@l) {
1229 my @l1 = split (/\|/, $p);
1230 foreach my $p1 (@l1) {
1231 if ($p1 =~ m/^\s*(\S+).*/) {
1232 #printf (STDERR "$pname: $p --> $1\n");
1233 if ($closure->{$1}) {
1234 next DEPEND
; # dependency already met
1238 # search for non-excluded alternative
1240 foreach my $p1 (@l1) {
1241 if ($p1 =~ m/^\s*(\S+).*/) {
1242 next if grep { $1 eq $_ } @$excl;
1247 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1249 #printf (STDERR "$pname: $p --> $found\n");
1251 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1255 sub cache_packages
{
1256 my ($self, $pkglist) = @_;
1258 foreach my $pkg (@$pkglist) {
1259 $self->getpkgfile ($pkg);
1264 my ($self, $pkg) = @_;
1266 my $pkginfo = $self->pkginfo();
1267 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1268 my $cachedir = $self->{cachedir
};
1270 my $url = $info->{url
};
1273 if ($url =~ m
|/([^/]+.deb
)$|) {
1276 die "internal error";
1279 return $filename if -f
"$cachedir/$filename";
1283 $self->download ($url, "$cachedir/$filename");
1288 sub install_init_script
{
1289 my ($self, $script, $runlevel, $prio) = @_;
1291 my $suite = $self->{config
}->{suite
};
1292 my $rootdir = $self->{rootfs
};
1294 my $base = basename
($script);
1295 my $target = "$rootdir/etc/init.d/$base";
1297 $self->run_command ("install -m 0755 '$script' '$target'");
1298 if ($suite eq 'etch' || $suite eq 'lenny') {
1299 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1300 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1301 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1302 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1303 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
1304 || $suite eq 'hirsute'
1306 die "unable to install init script (system uses systemd)\n";
1307 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1308 die "unable to install init script (system uses upstart)\n";
1310 $self->ve_command ("insserv $base");
1317 my ($self, $opts) = @_;
1319 my $pkginfo = $self->pkginfo();
1320 my $veid = $self->{veid
};
1321 my $suite = $self->{config
}->{suite
};
1323 my $important = [ @{$self->{incl
}} ];
1327 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1329 if ($mta eq 'postfix') {
1330 push @$important, "postfix";
1333 foreach my $p (sort keys %$pkginfo) {
1334 next if grep { $p eq $_ } @{$self->{excl
}};
1335 my $pri = $pkginfo->{$p}->{priority
};
1337 next if $mta ne 'exim' && $p =~ m/exim/;
1338 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1340 push @$required, $p if $pri eq 'required';
1341 push @$important, $p if $pri eq 'important';
1342 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1346 $required = $self->closure ($closure, $required);
1347 $important = $self->closure ($closure, $important);
1349 if (!$opts->{minimal
}) {
1350 push @$standard, 'xbase-clients';
1351 $standard = $self->closure ($closure, $standard);
1354 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1355 # except those explicitly excluded
1356 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1357 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1358 foreach my $d (split (/,/, $mdeps)) {
1359 if ($d =~ m/^\s*(\S+)$/) {
1361 next if $closure->{$pkg};
1362 next if grep { $pkg eq $_ } @{$self->{excl
}};
1363 die "missing ubuntu-minimal package '$pkg'\n";
1366 if (!$opts->{minimal
}) {
1367 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1368 foreach my $d (split (/,/, $mdeps)) {
1369 if ($d =~ m/^\s*(\S+)$/) {
1371 next if $closure->{$pkg};
1372 next if grep { $pkg eq $_ } @{$self->{excl
}};
1373 die "missing ubuntu-standard package '$pkg'\n";
1379 # download/cache all files first
1380 $self->cache_packages ($required);
1381 $self->cache_packages ($important);
1382 $self->cache_packages ($standard);
1384 my $rootdir = $self->{rootfs
};
1386 # extract required packages first
1387 $self->logmsg ("create basic environment\n");
1388 foreach my $p (@$required) {
1389 my $filename = $self->getpkgfile ($p);
1390 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1391 if ($content =~ m/^data.tar.xz$/m) {
1392 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1394 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1399 my $data = "Package: dpkg\n" .
1400 "Version: $pkginfo->{dpkg}->{version}\n" .
1401 "Status: install ok installed\n";
1403 write_file
($data, "$rootdir/var/lib/dpkg/status");
1404 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1405 write_file
("", "$rootdir/var/lib/dpkg/available");
1408 foreach my $ss (@{$self->{sources
}}) {
1409 my $url = $ss->{source
};
1410 my $comp = join (' ', @{$ss->{comp
}});
1411 $data .= "deb $url $ss->{suite} $comp\n\n";
1414 write_file
($data, "$rootdir/etc/apt/sources.list");
1416 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1417 write_file
($data, "$rootdir/etc/fstab", 0644);
1419 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1421 # avoid warnings about non-existent resolv.conf
1422 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1425 $suite eq 'hirsute' || $suite eq 'groovy' || $suite eq 'focal' ||
1426 $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1427 $suite eq 'bionic' || $suite eq 'artful' ||
1428 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1430 # no need to configure loopback device
1432 $data = "auto lo\niface lo inet loopback\n";
1433 mkdir "$rootdir/etc/network";
1434 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1438 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1440 # avoid warnings about missing default locale
1441 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1444 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1445 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1447 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1449 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1451 $self->logmsg ("initialize ld cache\n");
1452 $self->ve_command ("/sbin/ldconfig");
1453 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1455 $self->logmsg ("installing packages\n");
1457 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1459 $self->ve_dpkg ('install', 'dpkg');
1461 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1463 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1465 $self->ve_dpkg ('install', 'libc6');
1466 $self->ve_dpkg ('install', 'perl-base');
1468 unlink "$rootdir/usr/bin/awk";
1470 $self->ve_dpkg ('install', 'mawk');
1471 $self->ve_dpkg ('install', 'debconf');
1473 # unpack required packages
1474 foreach my $p (@$required) {
1475 $self->ve_dpkg ('unpack', $p);
1478 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1479 $self->ve_divert_add ("/sbin/init");
1480 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1482 # disable service activation
1483 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1484 $data = "#!/bin/sh\nexit 101\n";
1485 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1487 # disable start-stop-daemon
1488 $self->ve_divert_add ("/sbin/start-stop-daemon");
1492 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1494 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1497 $self->ve_divert_add ("/sbin/udevd");
1499 if ($suite eq 'etch') {
1500 # disable apache2 startup
1501 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1504 $self->logmsg ("configure required packages\n");
1505 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1507 # set postfix defaults
1508 if ($mta eq 'postfix') {
1509 $data = "postfix postfix/main_mailer_type select Local only\n";
1510 $self->ve_debconfig_set ($data);
1512 $data = "postmaster: root\nwebmaster: root\n";
1513 write_file
($data, "$rootdir/etc/aliases");
1516 if ($suite eq 'jaunty') {
1517 # jaunty does not create /var/run/network, so network startup fails.
1518 # so we do not use tmpfs for /var/run and /var/lock
1519 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1520 # and create the directory here
1521 $self->run_command ("mkdir $rootdir/var/run/network");
1524 # unpack base packages
1525 foreach my $p (@$important) {
1526 $self->ve_dpkg ('unpack', $p);
1530 if (-x
"$rootdir/sbin/ifconfig") {
1531 $self->ve_command ("ifconfig lo up");
1533 $self->ve_command ("ip link set lo up");
1536 $self->logmsg ("configure important packages\n");
1537 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1539 if (-d
"$rootdir/etc/event.d") {
1540 unlink <$rootdir/etc/event.d
/tty
*>;
1543 if (-f
"$rootdir/etc/inittab") {
1544 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1547 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1548 unlink "$rootdir/etc/mtab";
1549 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1552 $self->ve_command ("usermod -L root");
1554 if ($mta eq 'postfix') {
1555 $data = "postfix postfix/main_mailer_type select No configuration\n";
1556 $self->ve_debconfig_set ($data);
1558 unlink "$rootdir/etc/mailname";
1559 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1562 if (!$opts->{minimal
}) {
1563 # unpack standard packages
1564 foreach my $p (@$standard) {
1565 $self->ve_dpkg ('unpack', $p);
1568 $self->logmsg ("configure standard packages\n");
1569 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1572 # disable HWCLOCK access
1573 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1576 $self->ve_divert_add ("/usr/sbin/hald");
1578 # disable /dev/urandom init
1579 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1581 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1583 $self->ve_divert_add ("/sbin/klogd");
1586 # remove unnecessays sysctl entries to avoid warnings
1588 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1589 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1590 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1591 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1592 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1593 $self->run_command ($cmd);
1595 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1596 if (-f
$bindv6only) {
1598 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1599 $cmd .= " -i '$bindv6only'";
1600 $self->run_command ($cmd);
1603 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1604 # disable tty init (console-setup)
1606 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1607 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1608 $self->run_command ($cmd);
1611 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1612 # remove sysctl setup (avoid warnings at startup)
1613 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1614 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1615 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1616 $self->run_command ("rm $filelist");
1619 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1620 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1627 my $veid = $self->{veid
};
1628 my $conffile = $self->{veconffile
};
1630 my $vestat = $self->ve_status();
1632 if (!$vestat->{exist
}) {
1633 $self->logmsg ("Please create the appliance first (bootstrap)");
1637 if (!$vestat->{running
}) {
1638 $self->run_command ("lxc-start -n $veid -f $conffile");
1641 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1644 sub ve_mysql_command
{
1645 my ($self, $sql, $password) = @_;
1647 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1648 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1650 $self->ve_command ("mysql", $sql);
1653 sub ve_mysql_bootstrap
{
1654 my ($self, $sql, $password) = @_;
1658 my $suite = $self->{config
}->{suite
};
1660 if ($suite eq 'jessie') {
1661 my $rootdir = $self->{rootfs
};
1662 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1665 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1666 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1669 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1670 "--skip-bdb --skip-innodb --skip-ndbcluster";
1673 $self->ve_command ($cmd, $sql);
1676 sub compute_required
{
1677 my ($self, $pkglist) = @_;
1679 my $pkginfo = $self->pkginfo();
1680 my $instpkgs = $self->read_installed ();
1683 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1685 return $self->closure ($closure, $pkglist);
1689 my ($self, $opts) = @_;
1691 my @supp = ('7.4', '8.1');
1692 my $pgversion = '8.1';
1694 my $suite = $self->{config
}->{suite
};
1696 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1699 } elsif ($suite eq 'squeeze') {
1702 } elsif ($suite eq 'wheezy') {
1705 } elsif ($suite eq 'jessie') {
1708 } elsif ($suite eq 'stretch') {
1711 } elsif ($suite eq 'buster') {
1714 } elsif ($suite eq 'bullseye') {
1715 # FIXME update on freeze!
1720 $pgversion = $opts->{version
} if $opts->{version
};
1722 die "unsupported postgres version '$pgversion'\n"
1723 if !grep { $pgversion eq $_; } @supp;
1725 my $rootdir = $self->{rootfs
};
1727 my $required = $self->compute_required (["postgresql-$pgversion"]);
1729 $self->cache_packages ($required);
1731 $self->ve_dpkg ('install', @$required);
1733 my $iscript = "postgresql-$pgversion";
1734 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1735 $suite eq 'stretch') {
1736 $iscript = 'postgresql';
1739 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1743 my ($self, $opts) = @_;
1745 my $password = $opts->{password
};
1746 my $rootdir = $self->{rootfs
};
1748 my $suite = $self->{config
}->{suite
};
1751 if ($suite eq 'squeeze') {
1753 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1756 die "task_mysql: unsupported suite '$suite'";
1759 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1761 $self->cache_packages ($required);
1763 $self->ve_dpkg ('install', @$required);
1765 # fix security (see /usr/bin/mysql_secure_installation)
1766 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1767 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1768 "FLUSH PRIVILEGES;\n";
1769 $self->ve_mysql_bootstrap ($sql);
1773 my $rpw = $password eq 'random' ?
'admin' : $password;
1775 my $sql = "USE mysql;\n" .
1776 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1777 "FLUSH PRIVILEGES
;\n";
1778 $self->ve_mysql_bootstrap ($sql);
1780 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1781 if ($password eq 'random') {
1782 $self->install_init_script ($script_mysql_randompw, 2, 20);
1786 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1790 my ($self, $opts) = @_;
1792 my $memlimit = $opts->{memlimit
};
1793 my $rootdir = $self->{rootfs
};
1795 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1797 $self->cache_packages ($required);
1799 $self->ve_dpkg ('install', @$required);
1802 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1807 my ($self, $pkglist, $unpack) = @_;
1809 my $required = $self->compute_required ($pkglist);
1811 $self->cache_packages ($required);
1813 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1817 my ($self, $distclean) = @_;
1819 unlink $self->{logfile
};
1820 unlink "$self->{targetname}.tar";
1821 unlink "$self->{targetname}.tar.gz";
1823 $self->ve_destroy ();
1826 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1828 rmtree
$self->{infodir
};