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 = {
801 my $compressor_cmd = $compressor2cmd_map->{$compressor};
802 die "unkown compressor '$compressor', use one of: ". join(', ', sort keys %$compressor2cmd_map)
803 if !defined($compressor_cmd);
805 my $final_archive = "${target}.${compressor}";
807 unlink $final_archive;
809 $self->run_command ("tar cpf $target --numeric-owner -C '$rootdir' ./etc/appliance.info");
810 $self->run_command ("tar rpf $target --numeric-owner -C '$rootdir' --exclude ./etc/appliance.info .");
811 $self->run_command ("$compressor_cmd $target");
813 $self->logmsg ("detecting final commpressed appliance size: ");
814 $size = $get_path_size->($final_archive);
815 $self->logmsg ("$size MB\n");
817 $self->logmsg ("appliance archive: $final_archive\n");
823 my $rootdir = $self->{rootfs
};
825 my $pkgfilelist = "$rootdir/var/lib/dpkg/status";
827 open (PKGLST
, "<$pkgfilelist") ||
828 die "unable to open '$pkgfilelist'";
832 while (my $rec = <PKGLST
>) {
838 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
842 my $pkg = $res->{'package'};
843 if (my $status = $res->{status
}) {
844 my @sa = split (/\s+/, $status);
846 if ($stat && ($stat ne 'purge')) {
847 $pkglist->{$pkg} = $res;
860 my $veid = $self->{veid
};
862 my $res = { running
=> 0 };
864 $res->{exist
} = 1 if -d
"$self->{rootfs}/usr";
866 my $filename = "/proc/net/unix";
868 # similar test is used by lcxcontainers.c: list_active_containers
869 my $fh = IO
::File-
>new ($filename, "r");
872 while (defined(my $line = <$fh>)) {
873 if ($line =~ m/^[a-f0-9]+:\s\S+\s\S+\s\S+\s\S+\s\S+\s\d+\s(\S+)$/) {
875 if ($path =~ m!^@/\S+/$veid/command$!) {
886 my ($self, $cmd, $input) = @_;
888 my $veid = $self->{veid
};
889 my $conffile = $self->{veconffile
};
891 if (ref ($cmd) eq 'ARRAY') {
892 unshift @$cmd, 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--clear-env', '--', 'defenv';
893 $self->run_command ($cmd, $input);
895 $self->run_command ("lxc-attach -n $veid --rcfile $conffile --clear-env -- defenv $cmd", $input);
899 # like ve_command, but pipes stdin correctly
901 my ($self, @cmd) = @_;
903 my $veid = $self->{veid
};
904 my $conffile = $self->{veconffile
};
907 my $pid = open2
($reader, "<&STDIN", 'lxc-attach', '-n', $veid, '--rcfile', $conffile, '--',
908 'defenv', @cmd) || die "unable to exec command";
910 while (defined (my $line = <$reader>)) {
911 $self->logmsg ($line);
917 die "ve_exec failed - status $rc\n" if $rc != 0;
921 my ($self, $filename) = @_;
923 $self->ve_command ("dpkg-divert --add --divert '$filename.distrib' " .
924 "--rename '$filename'");
926 sub ve_divert_remove
{
927 my ($self, $filename) = @_;
929 my $rootdir = $self->{rootfs
};
931 unlink "$rootdir/$filename";
932 $self->ve_command ("dpkg-divert --remove --rename '$filename'");
935 sub ve_debconfig_set
{
936 my ($self, $dcdata) = @_;
938 my $rootdir = $self->{rootfs
};
939 my $cfgfile = "/tmp/debconf.txt";
940 write_file
($dcdata, "$rootdir/$cfgfile");
941 $self->ve_command ("debconf-set-selections $cfgfile");
942 unlink "$rootdir/$cfgfile";
945 sub ve_dpkg_set_selection
{
946 my ($self, $pkg, $status) = @_;
948 $self->ve_command ("dpkg --set-selections", "$pkg $status");
952 my ($self, $cmd, @pkglist) = @_;
954 return if !scalar (@pkglist);
956 my $pkginfo = $self->pkginfo();
958 my $rootdir = $self->{rootfs
};
959 my $cachedir = $self->{cachedir
};
963 foreach my $pkg (@pkglist) {
964 my $filename = $self->getpkgfile ($pkg);
965 $self->run_command ("cp '$cachedir/$filename' '$rootdir/$filename'");
966 push @files, "/$filename";
967 $self->logmsg ("$cmd: $pkg\n");
970 my $fl = join (' ', @files);
972 if ($cmd eq 'install') {
973 $self->ve_command ("dpkg --force-depends --force-confold --install $fl");
974 } elsif ($cmd eq 'unpack') {
975 $self->ve_command ("dpkg --force-depends --unpack $fl");
977 die "internal error";
980 foreach my $fn (@files) { unlink "$rootdir$fn"; }
986 my $veid = $self->{veid
}; # fixme
987 my $conffile = $self->{veconffile
};
989 my $vestat = $self->ve_status();
990 if ($vestat->{running
}) {
991 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
994 rmtree
$self->{rootfs
};
995 unlink $self->{veconffile
};
1001 my $veid = $self->{veid
};
1002 my $conffile = $self->{veconffile
};
1004 $self->logmsg ("initialize VE $veid\n");
1006 my $vestat = $self->ve_status();
1007 if ($vestat->{running
}) {
1008 $self->run_command ("lxc-stop -n $veid --rcfile $conffile --kill");
1011 rmtree
$self->{rootfs
};
1012 mkpath
$self->{rootfs
};
1015 sub __deb_version_cmp
{
1016 my ($cur, $op, $new) = @_;
1018 if (system("dpkg", "--compare-versions", $cur, $op, $new) == 0) {
1025 sub __parse_packages
{
1026 my ($pkginfo, $filename, $src) = @_;
1029 open (PKGLST
, "<$filename") ||
1030 die "unable to open '$filename'";
1032 while (my $rec = <PKGLST
>) {
1033 $rec =~ s/\n\s+/ /g;
1039 while ($rec =~ s/^([^:]+):\s+(.*)\s*\n//) {
1043 my $pkg = $res->{'package'};
1044 if ($pkg && $res->{'filename'}) {
1046 if (my $info = $pkginfo->{$pkg}) {
1047 $cur = $info->{version
};
1049 my $new = $res->{version
};
1050 if (!$cur || __deb_version_cmp
($cur, 'lt', $new)) {
1052 $res->{url
} = "$src/$res->{'filename'}";
1054 die "no url for package '$pkg'" if !$res->{url
};
1056 $pkginfo->{$pkg} = $res;
1067 return $self->{pkginfo
} if $self->{pkginfo
};
1069 my $infodir = $self->{infodir
};
1070 my $arch = $self->{config
}->{architecture
};
1072 my $availfn = "$infodir/available";
1077 # reading 'available' is faster, because it only contains latest version
1078 # (no need to do slow version compares)
1080 __parse_packages
($pkginfo, $availfn);
1081 $self->{pkginfo
} = $pkginfo;
1085 $self->logmsg ("generating available package list\n");
1087 foreach my $ss (@{$self->{sources
}}) {
1088 foreach my $comp (@{$ss->{comp
}}) {
1089 my $url = "$ss->{source}/dists/$ss->{suite}/$comp/binary-$arch/Packages";
1090 my $pkgfilelist = "$infodir/" . __url_to_filename
($url);
1092 my $src = $ss->{mirror
} || $ss->{source
};
1094 __parse_packages
($pkginfo, $pkgfilelist, $src);
1098 if (my $dep = $self->{config
}->{depends
}) {
1099 foreach my $d (split (/,/, $dep)) {
1100 if ($d =~ m/^\s*(\S+)\s*(\((\S+)\s+(\S+)\)\s*)?$/) {
1101 my ($pkg, $op, $rver) = ($1, $3, $4);
1102 $self->logmsg ("checking dependencies: $d\n");
1103 my $info = $pkginfo->{$pkg};
1104 die "package '$pkg' not available\n" if !$info;
1106 my $cver = $info->{version
};
1107 if (!__deb_version_cmp
($cver, $op, $rver)) {
1108 die "detected wrong version '$cver'\n";
1112 die "syntax error in depends field";
1117 $self->{pkginfo
} = $pkginfo;
1119 my $tmpfn = "$availfn.tmp$$";
1120 my $fd = IO
::File-
>new (">$tmpfn");
1121 foreach my $pkg (sort keys %$pkginfo) {
1122 my $info = $pkginfo->{$pkg};
1123 print $fd "package: $pkg\n";
1124 foreach my $k (sort keys %$info) {
1125 next if $k eq 'description';
1126 next if $k eq 'package';
1127 my $v = $info->{$k};
1128 print $fd "$k: $v\n" if $v;
1130 print $fd "description: $info->{description}\n" if $info->{description
};
1135 rename ($tmpfn, $availfn);
1140 sub __record_provides
{
1141 my ($pkginfo, $closure, $list, $skipself) = @_;
1143 foreach my $pname (@$list) {
1144 my $info = $pkginfo->{$pname};
1145 # fixme: if someone install packages directly using dpkg, there
1146 # is no entry in 'available', only in 'status'. In that case, we
1147 # should extract info from $instpkgs
1149 warn "hint: ignoring provides for '$pname' - package not in 'available' list.\n";
1152 if (my $prov = $info->{provides
}) {
1153 my @pl = split (',', $prov);
1154 foreach my $p (@pl) {
1156 if (!($skipself && (grep { $1 eq $_ } @$list))) {
1161 $closure->{$pname} = 1 if !$skipself;
1166 my ($self, $closure, $list) = @_;
1168 my $pkginfo = $self->pkginfo();
1170 # first, record provided packages
1171 __record_provides
($pkginfo, $closure, $list, 1);
1176 # then resolve dependencies
1177 foreach my $pname (@$list) {
1178 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $pname, $self->{excl
});
1184 sub __closure_single
{
1185 my ($pkginfo, $closure, $pkghash, $pkglist, $pname, $excl) = @_;
1189 $pname =~ s/:any$//;
1191 return if $closure->{$pname};
1193 my $info = $pkginfo->{$pname} || die "no such package '$pname'";
1195 my $dep = $info->{depends
};
1196 my $predep = $info->{'pre-depends'};
1198 my $size = $info->{size
};
1199 my $url = $info->{url
};
1201 $url || die "$pname: no url for package '$pname'";
1203 if (!$pkghash->{$pname}) {
1204 unshift @$pkglist, $pname;
1205 $pkghash->{$pname} = 1;
1208 __record_provides
($pkginfo, $closure, [$pname]) if $info->{provides
};
1210 $closure->{$pname} = 1;
1216 push @l, split (/,/, $predep) if $predep;
1217 push @l, split (/,/, $dep) if $dep;
1219 DEPEND
: foreach my $p (@l) {
1220 my @l1 = split (/\|/, $p);
1221 foreach my $p1 (@l1) {
1222 if ($p1 =~ m/^\s*(\S+).*/) {
1223 #printf (STDERR "$pname: $p --> $1\n");
1224 if ($closure->{$1}) {
1225 next DEPEND
; # dependency already met
1229 # search for non-excluded alternative
1231 foreach my $p1 (@l1) {
1232 if ($p1 =~ m/^\s*(\S+).*/) {
1233 next if grep { $1 eq $_ } @$excl;
1238 die "package '$pname' depends on exclusion '$p'\n" if !$found;
1240 #printf (STDERR "$pname: $p --> $found\n");
1242 __closure_single
($pkginfo, $closure, $pkghash, $pkglist, $found, $excl);
1246 sub cache_packages
{
1247 my ($self, $pkglist) = @_;
1249 foreach my $pkg (@$pkglist) {
1250 $self->getpkgfile ($pkg);
1255 my ($self, $pkg) = @_;
1257 my $pkginfo = $self->pkginfo();
1258 my $info = $pkginfo->{$pkg} || die "no such package '$pkg'";
1259 my $cachedir = $self->{cachedir
};
1261 my $url = $info->{url
};
1264 if ($url =~ m
|/([^/]+.deb
)$|) {
1267 die "internal error";
1270 return $filename if -f
"$cachedir/$filename";
1274 $self->download ($url, "$cachedir/$filename");
1279 sub install_init_script
{
1280 my ($self, $script, $runlevel, $prio) = @_;
1282 my $suite = $self->{config
}->{suite
};
1283 my $rootdir = $self->{rootfs
};
1285 my $base = basename
($script);
1286 my $target = "$rootdir/etc/init.d/$base";
1288 $self->run_command ("install -m 0755 '$script' '$target'");
1289 if ($suite eq 'etch' || $suite eq 'lenny') {
1290 $self->ve_command ("update-rc.d $base start $prio $runlevel .");
1291 } elsif ($suite eq 'xenial' || $suite eq 'wily' || $suite eq 'vivid' ||
1292 $suite eq 'yakkety' || $suite eq 'zesty' || $suite eq 'artful' ||
1293 $suite eq 'bionic' || $suite eq 'cosmic' || $suite eq 'disco' ||
1294 $suite eq 'eoan' || $suite eq 'focal' || $suite eq 'groovy'
1295 || $suite eq 'hirsute'
1297 die "unable to install init script (system uses systemd)\n";
1298 } elsif ($suite eq 'trusty' || $suite eq 'precise') {
1299 die "unable to install init script (system uses upstart)\n";
1301 $self->ve_command ("insserv $base");
1308 my ($self, $opts) = @_;
1310 my $pkginfo = $self->pkginfo();
1311 my $veid = $self->{veid
};
1312 my $suite = $self->{config
}->{suite
};
1314 my $important = [ @{$self->{incl
}} ];
1318 my $mta = $opts->{exim
} ?
'exim' : 'postfix';
1320 if ($mta eq 'postfix') {
1321 push @$important, "postfix";
1324 foreach my $p (sort keys %$pkginfo) {
1325 next if grep { $p eq $_ } @{$self->{excl
}};
1326 my $pri = $pkginfo->{$p}->{priority
};
1328 next if $mta ne 'exim' && $p =~ m/exim/;
1329 next if $p =~ m/(selinux|semanage|policycoreutils)/;
1331 push @$required, $p if $pri eq 'required';
1332 push @$important, $p if $pri eq 'important';
1333 push @$standard, $p if $pri eq 'standard' && !$opts->{minimal
};
1337 $required = $self->closure ($closure, $required);
1338 $important = $self->closure ($closure, $important);
1340 if (!$opts->{minimal
}) {
1341 push @$standard, 'xbase-clients';
1342 $standard = $self->closure ($closure, $standard);
1345 # test if we have all 'ubuntu-minimal' and 'ubuntu-standard' packages
1346 # except those explicitly excluded
1347 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1348 my $mdeps = $pkginfo->{'ubuntu-minimal'}->{depends
};
1349 foreach my $d (split (/,/, $mdeps)) {
1350 if ($d =~ m/^\s*(\S+)$/) {
1352 next if $closure->{$pkg};
1353 next if grep { $pkg eq $_ } @{$self->{excl
}};
1354 die "missing ubuntu-minimal package '$pkg'\n";
1357 if (!$opts->{minimal
}) {
1358 $mdeps = $pkginfo->{'ubuntu-standard'}->{depends
};
1359 foreach my $d (split (/,/, $mdeps)) {
1360 if ($d =~ m/^\s*(\S+)$/) {
1362 next if $closure->{$pkg};
1363 next if grep { $pkg eq $_ } @{$self->{excl
}};
1364 die "missing ubuntu-standard package '$pkg'\n";
1370 # download/cache all files first
1371 $self->cache_packages ($required);
1372 $self->cache_packages ($important);
1373 $self->cache_packages ($standard);
1375 my $rootdir = $self->{rootfs
};
1377 # extract required packages first
1378 $self->logmsg ("create basic environment\n");
1379 foreach my $p (@$required) {
1380 my $filename = $self->getpkgfile ($p);
1381 my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);
1382 if ($content =~ m/^data.tar.xz$/m) {
1383 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.xz | tar -C '$rootdir' -xJf -");
1385 $self->run_command ("ar -p '$self->{cachedir}/$filename' data.tar.gz | tar -C '$rootdir' -xzf -");
1390 my $data = "Package: dpkg\n" .
1391 "Version: $pkginfo->{dpkg}->{version}\n" .
1392 "Status: install ok installed\n";
1394 write_file
($data, "$rootdir/var/lib/dpkg/status");
1395 write_file
("", "$rootdir/var/lib/dpkg/info/dpkg.list");
1396 write_file
("", "$rootdir/var/lib/dpkg/available");
1399 foreach my $ss (@{$self->{sources
}}) {
1400 my $url = $ss->{source
};
1401 my $comp = join (' ', @{$ss->{comp
}});
1402 $data .= "deb $url $ss->{suite} $comp\n\n";
1405 write_file
($data, "$rootdir/etc/apt/sources.list");
1407 $data = "# UNCONFIGURED FSTAB FOR BASE SYSTEM\n";
1408 write_file
($data, "$rootdir/etc/fstab", 0644);
1410 write_file
("localhost\n", "$rootdir/etc/hostname", 0644);
1412 # avoid warnings about non-existent resolv.conf
1413 write_file
("", "$rootdir/etc/resolv.conf", 0644);
1416 $suite eq 'hirsute' || $suite eq 'groovy' || $suite eq 'focal' ||
1417 $suite eq 'eoan' || $suite eq 'disco' || $suite eq 'cosmic' ||
1418 $suite eq 'bionic' || $suite eq 'artful' ||
1419 $suite eq 'zesty' || $suite eq 'yakkety' || $suite eq 'xenial' ||
1421 # no need to configure loopback device
1423 $data = "auto lo\niface lo inet loopback\n";
1424 mkdir "$rootdir/etc/network";
1425 write_file
($data, "$rootdir/etc/network/interfaces", 0644);
1429 $self->run_command ("tar xzf '$devicetar' -C '$rootdir'");
1431 # avoid warnings about missing default locale
1432 write_file
("LANG=\"C\"\n", "$rootdir/etc/default/locale", 0644);
1435 rename ("$rootdir/sbin/init", "$rootdir/sbin/init.org");
1436 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1438 $self->run_command ("cp '$default_env' '$rootdir/sbin/defenv'");
1440 $self->run_command ("lxc-start -n $veid -f $self->{veconffile}");
1442 $self->logmsg ("initialize ld cache\n");
1443 $self->ve_command ("/sbin/ldconfig");
1444 $self->run_command ("ln -sf mawk '$rootdir/usr/bin/awk'");
1446 $self->logmsg ("installing packages\n");
1448 $self->ve_dpkg ('install', 'base-files', 'base-passwd');
1450 $self->ve_dpkg ('install', 'dpkg');
1452 $self->run_command ("ln -sf /usr/share/zoneinfo/UTC '$rootdir/etc/localtime'");
1454 $self->run_command ("ln -sf bash '$rootdir/bin/sh'");
1456 $self->ve_dpkg ('install', 'libc6');
1457 $self->ve_dpkg ('install', 'perl-base');
1459 unlink "$rootdir/usr/bin/awk";
1461 $self->ve_dpkg ('install', 'mawk');
1462 $self->ve_dpkg ('install', 'debconf');
1464 # unpack required packages
1465 foreach my $p (@$required) {
1466 $self->ve_dpkg ('unpack', $p);
1469 rename ("$rootdir/sbin/init.org", "$rootdir/sbin/init");
1470 $self->ve_divert_add ("/sbin/init");
1471 $self->run_command ("cp '$fake_init' '$rootdir/sbin/init'");
1473 # disable service activation
1474 $self->ve_divert_add ("/usr/sbin/policy-rc.d");
1475 $data = "#!/bin/sh\nexit 101\n";
1476 write_file
($data, "$rootdir/usr/sbin/policy-rc.d", 755);
1478 # disable start-stop-daemon
1479 $self->ve_divert_add ("/sbin/start-stop-daemon");
1483 echo \"Warning: Fake start-stop-daemon called, doing nothing\"
1485 write_file
($data, "$rootdir/sbin/start-stop-daemon", 0755);
1488 $self->ve_divert_add ("/sbin/udevd");
1490 if ($suite eq 'etch') {
1491 # disable apache2 startup
1492 write_file
("NO_START=1\n", "$rootdir/etc/default/apache2");
1495 $self->logmsg ("configure required packages\n");
1496 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1498 # set postfix defaults
1499 if ($mta eq 'postfix') {
1500 $data = "postfix postfix/main_mailer_type select Local only\n";
1501 $self->ve_debconfig_set ($data);
1503 $data = "postmaster: root\nwebmaster: root\n";
1504 write_file
($data, "$rootdir/etc/aliases");
1507 if ($suite eq 'jaunty') {
1508 # jaunty does not create /var/run/network, so network startup fails.
1509 # so we do not use tmpfs for /var/run and /var/lock
1510 $self->run_command ("sed -e 's/RAMRUN=yes/RAMRUN=no/' -e 's/RAMLOCK=yes/RAMLOCK=no/' -i $rootdir/etc/default/rcS");
1511 # and create the directory here
1512 $self->run_command ("mkdir $rootdir/var/run/network");
1515 # unpack base packages
1516 foreach my $p (@$important) {
1517 $self->ve_dpkg ('unpack', $p);
1521 if (-x
"$rootdir/sbin/ifconfig") {
1522 $self->ve_command ("ifconfig lo up");
1524 $self->ve_command ("ip link set lo up");
1527 $self->logmsg ("configure important packages\n");
1528 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1530 if (-d
"$rootdir/etc/event.d") {
1531 unlink <$rootdir/etc/event.d
/tty
*>;
1534 if (-f
"$rootdir/etc/inittab") {
1535 $self->run_command ("sed -i -e '/getty\\s38400\\stty[23456]/d' '$rootdir/etc/inittab'");
1538 # Link /etc/mtab to /proc/mounts, so df and friends will work:
1539 unlink "$rootdir/etc/mtab";
1540 $self->ve_command ("ln -s /proc/mounts /etc/mtab");
1543 $self->ve_command ("usermod -L root");
1545 if ($mta eq 'postfix') {
1546 $data = "postfix postfix/main_mailer_type select No configuration\n";
1547 $self->ve_debconfig_set ($data);
1549 unlink "$rootdir/etc/mailname";
1550 write_file
($postfix_main_cf, "$rootdir/etc/postfix/main.cf");
1553 if (!$opts->{minimal
}) {
1554 # unpack standard packages
1555 foreach my $p (@$standard) {
1556 $self->ve_dpkg ('unpack', $p);
1559 $self->logmsg ("configure standard packages\n");
1560 $self->ve_command ("dpkg --force-confold --skip-same-version --configure -a");
1563 # disable HWCLOCK access
1564 $self->run_command ("echo 'HWCLOCKACCESS=no' >> '$rootdir/etc/default/rcS'");
1567 $self->ve_divert_add ("/usr/sbin/hald");
1569 # disable /dev/urandom init
1570 $self->run_command ("install -m 0755 '$script_init_urandom' '$rootdir/etc/init.d/urandom'");
1572 if ($suite eq 'etch' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1574 $self->ve_divert_add ("/sbin/klogd");
1577 # remove unnecessays sysctl entries to avoid warnings
1579 $cmd .= ' -e \'s/^\(kernel\.printk.*\)/#\1/\'';
1580 $cmd .= ' -e \'s/^\(kernel\.maps_protect.*\)/#\1/\'';
1581 $cmd .= ' -e \'s/^\(fs\.inotify\.max_user_watches.*\)/#\1/\'';
1582 $cmd .= ' -e \'s/^\(vm\.mmap_min_addr.*\)/#\1/\'';
1583 $cmd .= " -i '$rootdir/etc/sysctl.conf'";
1584 $self->run_command ($cmd);
1586 my $bindv6only = "$rootdir/etc/sysctl.d/bindv6only.conf";
1587 if (-f
$bindv6only) {
1589 $cmd .= ' -e \'s/^\(net\.ipv6\.bindv6only.*\)/#\1/\'';
1590 $cmd .= " -i '$bindv6only'";
1591 $self->run_command ($cmd);
1594 if ($suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1595 # disable tty init (console-setup)
1597 $cmd .= ' -e \'s/^\(ACTIVE_CONSOLES=.*\)/ACTIVE_CONSOLES=/\'';
1598 $cmd .= " -i '$rootdir/etc/default/console-setup'";
1599 $self->run_command ($cmd);
1602 if ($suite eq 'intrepid' || $suite eq 'jaunty') {
1603 # remove sysctl setup (avoid warnings at startup)
1604 my $filelist = "$rootdir/etc/sysctl.d/10-console-messages.conf";
1605 $filelist .= " $rootdir/etc/sysctl.d/10-process-security.conf" if $suite eq 'intrepid';
1606 $filelist .= " $rootdir/etc/sysctl.d/10-network-security.conf";
1607 $self->run_command ("rm $filelist");
1610 if (-e
"$rootdir/lib/systemd/system/sys-kernel-config.mount") {
1611 $self->ve_command ("ln -s /dev/null /etc/systemd/system/sys-kernel-debug.mount");
1618 my $veid = $self->{veid
};
1619 my $conffile = $self->{veconffile
};
1621 my $vestat = $self->ve_status();
1623 if (!$vestat->{exist
}) {
1624 $self->logmsg ("Please create the appliance first (bootstrap)");
1628 if (!$vestat->{running
}) {
1629 $self->run_command ("lxc-start -n $veid -f $conffile");
1632 system ("lxc-attach -n $veid --rcfile $conffile --clear-env");
1635 sub ve_mysql_command
{
1636 my ($self, $sql, $password) = @_;
1638 #my $bootstrap = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1639 #"--skip-bdb --skip-innodb --skip-ndbcluster";
1641 $self->ve_command ("mysql", $sql);
1644 sub ve_mysql_bootstrap
{
1645 my ($self, $sql, $password) = @_;
1649 my $suite = $self->{config
}->{suite
};
1651 if ($suite eq 'jessie') {
1652 my $rootdir = $self->{rootfs
};
1653 $self->run_command ("sed -e 's/^key_buffer\\s*=/key_buffer_size =/' -i $rootdir/etc/mysql/my.cnf");
1656 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie') {
1657 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables";
1660 $cmd = "/usr/sbin/mysqld --bootstrap --user=mysql --skip-grant-tables " .
1661 "--skip-bdb --skip-innodb --skip-ndbcluster";
1664 $self->ve_command ($cmd, $sql);
1667 sub compute_required
{
1668 my ($self, $pkglist) = @_;
1670 my $pkginfo = $self->pkginfo();
1671 my $instpkgs = $self->read_installed ();
1674 __record_provides
($pkginfo, $closure, [keys %$instpkgs]);
1676 return $self->closure ($closure, $pkglist);
1680 my ($self, $opts) = @_;
1682 my @supp = ('7.4', '8.1');
1683 my $pgversion = '8.1';
1685 my $suite = $self->{config
}->{suite
};
1687 if ($suite eq 'lenny' || $suite eq 'hardy' || $suite eq 'intrepid' || $suite eq 'jaunty') {
1690 } elsif ($suite eq 'squeeze') {
1693 } elsif ($suite eq 'wheezy') {
1696 } elsif ($suite eq 'jessie') {
1699 } elsif ($suite eq 'stretch') {
1702 } elsif ($suite eq 'buster') {
1705 } elsif ($suite eq 'bullseye') {
1706 # FIXME update on freeze!
1711 $pgversion = $opts->{version
} if $opts->{version
};
1713 die "unsupported postgres version '$pgversion'\n"
1714 if !grep { $pgversion eq $_; } @supp;
1716 my $rootdir = $self->{rootfs
};
1718 my $required = $self->compute_required (["postgresql-$pgversion"]);
1720 $self->cache_packages ($required);
1722 $self->ve_dpkg ('install', @$required);
1724 my $iscript = "postgresql-$pgversion";
1725 if ($suite eq 'squeeze' || $suite eq 'wheezy' || $suite eq 'jessie' ||
1726 $suite eq 'stretch') {
1727 $iscript = 'postgresql';
1730 $self->ve_command ("/etc/init.d/$iscript start") if $opts->{start
};
1734 my ($self, $opts) = @_;
1736 my $password = $opts->{password
};
1737 my $rootdir = $self->{rootfs
};
1739 my $suite = $self->{config
}->{suite
};
1742 if ($suite eq 'squeeze') {
1744 } elsif ($suite eq 'wheezy' || $suite eq 'jessie') {
1747 die "task_mysql: unsupported suite '$suite'";
1750 my $required = $self->compute_required (['mysql-common', "mysql-server-$ver"]);
1752 $self->cache_packages ($required);
1754 $self->ve_dpkg ('install', @$required);
1756 # fix security (see /usr/bin/mysql_secure_installation)
1757 my $sql = "DELETE FROM mysql.user WHERE User='';\n" .
1758 "DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';\n" .
1759 "FLUSH PRIVILEGES;\n";
1760 $self->ve_mysql_bootstrap ($sql);
1764 my $rpw = $password eq 'random' ?
'admin' : $password;
1766 my $sql = "USE mysql;\n" .
1767 "UPDATE user SET password=PASSWORD(\"$rpw\") WHERE user
='root';\n" .
1768 "FLUSH PRIVILEGES
;\n";
1769 $self->ve_mysql_bootstrap ($sql);
1771 write_file ("[client
]\nuser
=root
\npassword
=\"$rpw\"\n", "$rootdir/root/.my.cnf", 0600);
1772 if ($password eq 'random') {
1773 $self->install_init_script ($script_mysql_randompw, 2, 20);
1777 $self->ve_command ("/etc/init.d/mysql start") if $opts->{start
};
1781 my ($self, $opts) = @_;
1783 my $memlimit = $opts->{memlimit
};
1784 my $rootdir = $self->{rootfs
};
1786 my $required = $self->compute_required ([qw
(php5 php5-cli libapache2-mod-php5 php5-gd
)]);
1788 $self->cache_packages ($required);
1790 $self->ve_dpkg ('install', @$required);
1793 $self->run_command ("sed -e 's/^\\s*memory_limit\\s*=.*;/memory_limit = ${memlimit}M;/' -i $rootdir/etc/php5/apache2/php.ini");
1798 my ($self, $pkglist, $unpack) = @_;
1800 my $required = $self->compute_required ($pkglist);
1802 $self->cache_packages ($required);
1804 $self->ve_dpkg ($unpack ?
'unpack' : 'install', @$required);
1808 my ($self, $distclean) = @_;
1810 unlink $self->{logfile
};
1811 unlink "$self->{targetname}.tar";
1812 unlink "$self->{targetname}.tar.gz";
1814 $self->ve_destroy ();
1817 rmtree
$self->{cachedir
} if $distclean && !$self->{config
}->{cachedir
};
1819 rmtree
$self->{infodir
};