]> git.proxmox.com Git - pve-installer.git/blob - proxinstall
95683198f2ef31b17ce8d32bdd2c2842874aa83c
[pve-installer.git] / proxinstall
1 #!/usr/bin/perl -w
2
3 $ENV{DEBIAN_FRONTEND} = 'noninteractive';
4 $ENV{LC_ALL} = 'C';
5
6 use strict;
7 use Getopt::Long;
8 use IPC::Open2;
9 use IPC::Open3;
10 use IO::File;
11 use IO::Select;
12 use Cwd 'abs_path';
13 use Gtk3 '-init';
14 use Gtk3::WebKit;
15 use Encode;
16 use String::ShellQuote;
17 use Data::Dumper;
18 use File::Basename;
19 use Time::HiRes;
20
21 my $release = '4.2';
22
23 my $kapi = `uname -r`;
24 chomp $kapi;
25
26 my $opt_testmode;
27
28 if (!$ENV{G_SLICE} || $ENV{G_SLICE} ne "always-malloc") {
29 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
30 }
31
32 if (!GetOptions ('testmode=s' => \$opt_testmode)) {
33 die "usage error\n";
34 exit (-1);
35 }
36
37 my $zfstestpool = "test_rpool";
38 my $zfspoolname = $opt_testmode ? $zfstestpool : 'rpool';
39
40 my $storage_cfg_zfs = <<__EOD__;
41 dir: local
42 path /var/lib/vz
43 content iso,vztmpl,backup
44
45 zfspool: local-zfs
46 pool $zfspoolname/data
47 sparse
48 content images,rootdir
49 __EOD__
50
51 my $storage_cfg_btrfs = <<__EOD__;
52 dir: local
53 path /var/lib/vz
54 content iso,vztmpl,backup
55 disabled
56
57 btrfs: local-btrfs
58 path /var/lib/pve/local-btrfs
59 content iso,vztmpl,backup,images,rootdir
60 __EOD__
61
62 my $storage_cfg_lvmthin = <<__EOD__;
63 dir: local
64 path /var/lib/vz
65 content iso,vztmpl,backup
66
67 lvmthin: local-lvm
68 thinpool data
69 vgname pve
70 content rootdir,images
71 __EOD__
72
73
74 sub file_read_firstline {
75 my ($filename) = @_;
76
77 my $fh = IO::File->new ($filename, "r");
78 return undef if !$fh;
79 my $res = <$fh>;
80 chomp $res if $res;
81 $fh->close;
82 return $res;
83 }
84
85 my $logfd = IO::File->new (">/tmp/install.log");
86
87 my $proxmox_dir = $opt_testmode ? Cwd::cwd() : "/var/lib/pve-installer";
88
89 my $grub_plattform = "pc"; # pc, efi-amd64 or efi-ia32
90
91 $grub_plattform = "efi-amd64" if -d "/sys/firmware/efi";
92
93 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
94 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
95 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
96 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
97
98 my $IPV6RE = "(?:" .
99 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
100 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
101 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
102 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
103 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
104 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
105 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
106 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
107 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
108
109 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
110
111
112 my $ipv4_mask_hash = {
113 '128.0.0.0' => 1,
114 '192.0.0.0' => 2,
115 '224.0.0.0' => 3,
116 '240.0.0.0' => 4,
117 '248.0.0.0' => 5,
118 '252.0.0.0' => 6,
119 '254.0.0.0' => 7,
120 '255.0.0.0' => 8,
121 '255.128.0.0' => 9,
122 '255.192.0.0' => 10,
123 '255.224.0.0' => 11,
124 '255.240.0.0' => 12,
125 '255.248.0.0' => 13,
126 '255.252.0.0' => 14,
127 '255.254.0.0' => 15,
128 '255.255.0.0' => 16,
129 '255.255.128.0' => 17,
130 '255.255.192.0' => 18,
131 '255.255.224.0' => 19,
132 '255.255.240.0' => 20,
133 '255.255.248.0' => 21,
134 '255.255.252.0' => 22,
135 '255.255.254.0' => 23,
136 '255.255.255.0' => 24,
137 '255.255.255.128' => 25,
138 '255.255.255.192' => 26,
139 '255.255.255.224' => 27,
140 '255.255.255.240' => 28,
141 '255.255.255.248' => 29,
142 '255.255.255.252' => 30
143 };
144
145 my ($window, $cmdbox, $inbox, $htmlview);
146 my ($next, $next_fctn, $target_hd);
147 my ($progress, $progress_status);
148 my ($ipversion, $ipaddress, $ipconf_entry_addr);
149 my ($netmask, $ipconf_entry_mask);
150 my ($gateway, $ipconf_entry_gw);
151 my ($dnsserver, $ipconf_entry_dns);
152 my $hostname = 'proxmox';
153 my $domain = 'domain.tld';
154 my $cmdline = file_read_firstline("/proc/cmdline");
155 my $ipconf;
156 my $country;
157 my $timezone = 'Europe/Vienna';
158 my $password;
159 my $mailto;
160 my $keymap = 'en-us';
161 my $cmap;
162
163 # parse command line args
164
165 my $config_options = {};
166
167 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
168 $config_options->{filesys} = $1;
169 } else {
170 $config_options->{filesys} = 'ext4';
171 }
172
173 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
174 $config_options->{hdsize} = $1;
175 }
176
177 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
178 $config_options->{swapsize} = $1;
179 }
180
181 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
182 $config_options->{maxroot} = $1;
183 }
184
185 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
186 $config_options->{minfree} = $1;
187 }
188
189 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
190 $config_options->{maxvz} = $1;
191 }
192
193 my $postfix_main_cf = <<_EOD;
194 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
195
196 myhostname=__FQDN__
197
198 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
199 biff = no
200
201 # appending .domain is the MUA's job.
202 append_dot_mydomain = no
203
204 # Uncomment the next line to generate "delayed mail" warnings
205 #delay_warning_time = 4h
206
207 alias_maps = hash:/etc/aliases
208 alias_database = hash:/etc/aliases
209 mydestination = \$myhostname, localhost.\$mydomain, localhost
210 relayhost =
211 mynetworks = 127.0.0.0/8
212 inet_interfaces = loopback-only
213 recipient_delimiter = +
214
215 _EOD
216
217 sub shellquote {
218 my $str = shift;
219
220 return String::ShellQuote::shell_quote($str);
221 }
222
223 sub cmd2string {
224 my ($cmd) = @_;
225
226 die "no arguments" if !$cmd;
227
228 return $cmd if !ref($cmd);
229
230 my @qa = ();
231 foreach my $arg (@$cmd) { push @qa, shellquote($arg); }
232
233 return join (' ', @qa);
234 }
235
236 sub syscmd {
237 my ($cmd) = @_;
238
239 return run_command ($cmd, undef, undef, 1);
240 }
241
242 sub run_command {
243 my ($cmd, $func, $input, $noout) = @_;
244
245 my $cmdstr;
246 if (!ref($cmd)) {
247 $cmdstr = $cmd;
248 if ($cmd =~ m/|/) {
249 # see 'man bash' for option pipefail
250 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
251 } else {
252 $cmd = [ $cmd ];
253 }
254 } else {
255 $cmdstr = cmd2string($cmd);
256 }
257
258 my $cmdtxt;
259 if ($input && ($cmdstr !~ m/chpasswd/)) {
260 $cmdtxt = "# $cmdstr <<EOD\n$input";
261 chomp $cmdtxt;
262 $cmdtxt .= "\nEOD\n";
263 } else {
264 $cmdtxt = "# $cmdstr\n";
265 }
266
267 if ($opt_testmode) {
268 print $cmdtxt;
269 STDOUT->flush();
270 }
271
272 print $logfd $cmdtxt;
273
274 my $reader = IO::File->new();
275 my $writer = IO::File->new();
276 my $error = IO::File->new();
277
278 my $orig_pid = $$;
279
280 my $pid;
281 eval {
282 $pid = open3 ($writer, $reader, $error, @$cmd) || die $!;
283 };
284
285 my $err = $@;
286
287 # catch exec errors
288 if ($orig_pid != $$) {
289 POSIX::_exit (1);
290 kill ('KILL', $$);
291 }
292
293 die $err if $err;
294
295 print $writer $input if defined $input;
296 close $writer;
297
298 my $select = new IO::Select;
299 $select->add ($reader);
300 $select->add ($error);
301
302 my ($ostream, $logout) = ('', '', '');
303
304 while ($select->count) {
305 my @handles = $select->can_read (0.2);
306
307 Gtk3::main_iteration() while Gtk3::events_pending();
308
309 next if !scalar (@handles); # timeout
310
311 foreach my $h (@handles) {
312 my $buf = '';
313 my $count = sysread ($h, $buf, 4096);
314 if (!defined ($count)) {
315 my $err = $!;
316 kill (9, $pid);
317 waitpid ($pid, 0);
318 die "command '$cmd' failed: $err";
319 }
320 $select->remove ($h) if !$count;
321 if ($h eq $reader) {
322 $ostream .= $buf if !($noout || $func);
323 $logout .= $buf;
324 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
325 my $line = $1;
326 &$func($line) if $func;
327 }
328
329 } elsif ($h eq $error) {
330 $ostream .= $buf if !($noout || $func);
331 }
332 print $buf;
333 STDOUT->flush();
334 print $logfd $buf;
335 }
336 }
337
338 &$func($logout) if $func;
339
340 my $rv = waitpid ($pid, 0);
341
342 return $? if $noout; # behave like standard system();
343
344 my $ec = ($? >> 8);
345
346 if ($ec) {
347 die "command '$cmdstr' failed with exit code $ec";
348 }
349
350 return $ostream;
351 }
352
353 sub detect_country {
354
355 print "trying to detect country...\n";
356 my $cpid = open2(\*TMP, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
357 return undef if !$cpid;
358
359 my $country;
360
361 my $previous_alarm = alarm (10);
362 eval {
363 local $SIG{ALRM} = sub { die "timed out!\n" };
364 my $line;
365 while (defined ($line = <TMP>)) {
366 print $logfd "DC TRACEROUTE: $line";
367 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
368 my $geoip = `geoiplookup $1`;
369 print $logfd "DC GEOIP: $geoip";
370 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
371 $country = lc ($1);
372 print $logfd "DC FOUND: $country\n";
373 last;
374 }
375 }
376 }
377 };
378
379 my $err = $@;
380
381 alarm ($previous_alarm);
382
383 close (TMP);
384
385 if ($err) {
386 print "unable to detect country - $err\n";
387 } elsif ($country) {
388 print "detected country: " . uc($country) . "\n";
389 } else {
390 print "unable to detect country\n";
391 }
392
393 return $country;
394 }
395
396 sub get_memtotal {
397
398 open (MEMINFO, "/proc/meminfo");
399
400 my $res = 512; # default to 512 if something goes wrong
401 while (my $line = <MEMINFO>) {
402 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
403 $res = int ($1 / 1024);
404 }
405 }
406
407 close (MEMINFO);
408
409 return $res;
410 }
411
412 my $total_memory = get_memtotal();
413
414 sub link_points_to {
415 my ($src, $dest) = @_;
416
417 my ($dev1,$ino1) = stat ($src);
418 my ($dev2,$ino2) = stat ($dest);
419
420 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
421
422 return $ino1 == $ino2 && $dev1 == $dev2;
423 }
424
425 sub find_stable_path {
426 my ($stabledir, $bdev) = @_;
427
428 foreach my $path (<$stabledir/*>) {
429 if (link_points_to ($path, $bdev)) {
430 return wantarray ? ($path, basename($path)) : $path;
431 }
432 }
433 }
434
435 sub find_dev_by_uuid {
436 my $bdev = shift;
437
438 my ($full_path, $name) = find_stable_path ("/dev/disk/by-uuid", $bdev);
439
440 return $name;
441 }
442
443 sub hd_list {
444
445 my $res = ();
446
447 if ($opt_testmode) {
448 push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
449 return $res;
450 }
451
452 my $count = 0;
453
454 foreach my $bd (</sys/block/*>) {
455 next if $bd =~ m|^/sys/block/ram\d+$|;
456 next if $bd =~ m|^/sys/block/loop\d+$|;
457 next if $bd =~ m|^/sys/block/md\d+$|;
458 next if $bd =~ m|^/sys/block/dm-.*$|;
459 next if $bd =~ m|^/sys/block/fd\d+$|;
460 next if $bd =~ m|^/sys/block/sr\d+$|;
461
462 my $dev = file_read_firstline("$bd/dev");
463 chomp $dev;
464
465 next if !$dev;
466
467 my $info = `udevadm info --path $bd --query all`;
468 next if !$info;
469
470 next if $info !~ m/^E: DEVTYPE=disk$/m;
471
472 next if $info =~ m/^E: ID_CDROM/m;
473
474 my ($name) = $info =~ m/^N: (\S+)$/m;
475
476 if ($name) {
477 my $real_name = "/dev/$name";
478
479 my $size = file_read_firstline("$bd/size");
480 chomp $size;
481 $size = undef if !($size && $size =~ m/^\d+$/);
482
483 my $model = file_read_firstline("$bd/device/model") || '';
484 $model =~ s/^\s+//;
485 $model =~ s/\s+$//;
486 if (length ($model) > 30) {
487 $model = substr ($model, 0, 30);
488 }
489 push @$res, [$count++, $real_name, $size, $model] if $size;
490 } else {
491 print STDERR "ERROR: unable to map device $dev ($bd)\n";
492 }
493 }
494
495 return $res;
496 }
497
498 sub read_cmap {
499 my $countryfn = $opt_testmode ? "/usr/share/pve-manager/country.dat" :
500 "/proxmox/country.dat";
501 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
502 my $line;
503 my $country = {};
504 my $countryhash = {};
505 my $kmap = {};
506 my $kmaphash = {};
507 while (defined ($line = <TMP>)) {
508 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
509 $kmap->{$1} = {
510 name => $2,
511 kvm => $3,
512 console => $4,
513 x11 => $5,
514 x11var => $6,
515 };
516 $kmaphash->{$2} = $1;
517 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
518 $country->{$1} = {
519 name => $2,
520 kmap => $3,
521 mirror => $4,
522 };
523 $countryhash->{lc($2)} = $1;
524 } else {
525 warn "unable to parse 'country.dat' line: $line";
526 }
527 }
528 close (TMP);
529
530 my $zones = {};
531 my $cczones = {};
532 my $zonefn = "/usr/share/zoneinfo/zone.tab";
533 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
534 while (defined ($line = <TMP>)) {
535 next if $line =~ m/^\#/;
536 next if $line =~ m/^\s*$/;
537 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
538 my $cc = lc($1);
539 $cczones->{$cc}->{$2} = 1;
540 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
541 $zones->{$2} = 1;
542
543 }
544 }
545 close (TMP);
546
547 return {
548 zones => $zones,
549 cczones => $cczones,
550 country => $country,
551 countryhash => $countryhash,
552 kmap => $kmap,
553 kmaphash => $kmaphash,
554 }
555 }
556
557 # search for Harddisks
558 my $hds = hd_list ();
559
560 sub hd_size {
561 my ($dev) = @_;
562
563 foreach my $hd (@$hds) {
564 my ($disk, $devname, $size, $model) = @$hd;
565 return int($size/2) if $devname eq $dev;
566 }
567
568 die "no such device '$dev'\n";
569 }
570
571 sub get_partition_dev {
572 my ($dev, $partnum) = @_;
573
574 if ($dev =~ m|^/dev/[hxsev]d[a-z]$|) {
575 return "${dev}$partnum";
576 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
577 return "${dev}p$partnum";
578 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
579 return "${dev}p$partnum";
580 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
581 return "${dev}$partnum";
582 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
583 return "${dev}p$partnum";
584 } else {
585 die "unable to get device for partition $partnum on device $dev\n";
586 }
587
588 }
589
590 sub file_get_contents {
591 my ($filename, $max) = @_;
592
593 my $fh = IO::File->new($filename, "r") ||
594 die "can't open '$filename' - $!\n";
595
596 local $/; # slurp mode
597
598 my $content = <$fh>;
599
600 close $fh;
601
602 return $content;
603 }
604
605 sub write_config {
606 my ($text, $filename) = @_;
607
608 my $fd = IO::File->new (">$filename") ||
609 die "unable to open file '$filename' - $!\n";
610 print $fd $text;
611 $fd->close();
612 }
613
614 sub update_progress {
615 my ($frac, $start, $end, $text) = @_;
616
617 my $part = $end - $start;
618 my $res = $start + $frac*$part;
619
620 $progress->set_fraction ($res);
621 $progress->set_text (sprintf ("%d%%", int ($res*100)));
622 $progress_status->set_text ($text) if defined ($text);
623
624 Gtk3::main_iteration() while Gtk3::events_pending();
625 }
626
627 my $fssetup = {
628 ext3 => {
629 mkfs => 'mkfs.ext3 -F',
630 mkfs_root_opt => '',
631 mkfs_data_opt => '-m 0',
632 root_mountopt => 'errors=remount-ro',
633 },
634 ext4 => {
635 mkfs => 'mkfs.ext4 -F',
636 mkfs_root_opt => '',
637 mkfs_data_opt => '-m 0',
638 root_mountopt => 'errors=remount-ro',
639 },
640 xfs => {
641 mkfs => 'mkfs.xfs -f',
642 mkfs_root_opt => '',
643 mkfs_data_opt => '',
644 root_mountopt => '',
645 },
646 };
647
648 sub create_filesystem {
649 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
650
651 my $range = $end - $start;
652 my $rs = $start + $range*$fs;
653 my $re = $start + $range*$fe;
654 my $max = 0;
655
656 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
657 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
658
659 update_progress (0, $rs, $re, "creating $name filesystem");
660
661 run_command ("$fsdata->{mkfs} $opts $dev", sub {
662 my $line = shift;
663
664 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
665 $max = $2;
666 } elsif ($max && $line =~ m/(\d+)\/$max/) {
667 update_progress (($1/$max)*0.9, $rs, $re);
668 } elsif ($line =~ m/Creating journal.*done/) {
669 update_progress (0.95, $rs, $re);
670 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
671 update_progress (1, $rs, $re);
672 }
673 });
674 }
675
676 sub debconfig_set {
677 my ($targetdir, $dcdata) = @_;
678
679 my $cfgfile = "/tmp/debconf.txt";
680 write_config ($dcdata, "$targetdir/$cfgfile");
681 syscmd ("chroot $targetdir debconf-set-selections $cfgfile");
682 unlink "$targetdir/$cfgfile";
683 }
684
685 sub diversion_add {
686 my ($targetdir, $cmd, $new_cmd) = @_;
687
688 syscmd ("chroot $targetdir dpkg-divert --package proxmox " .
689 "--add --rename $cmd") == 0 ||
690 die "unable to exec dpkg-divert\n";
691
692 syscmd ("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
693 die "unable to link diversion to ${new_cmd}\n";
694 }
695
696 sub diversion_remove {
697 my ($targetdir, $cmd) = @_;
698
699 syscmd ("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
700 die "unable to remove $cmd diversion\n";
701
702 syscmd ("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
703 die "unable to remove $cmd diversion\n";
704 }
705
706 sub btrfs_create {
707 my ($partitions, $mode) = @_;
708
709 die "unknown btrfs mode '$mode'"
710 if !($mode eq 'single' || $mode eq 'raid0' ||
711 $mode eq 'raid1' || $mode eq 'raid10');
712
713 my $cmd = ['mkfs.btrfs', '-f'];
714
715 push @$cmd, '-d', $mode, '-m', $mode;
716
717 push @$cmd, @$partitions;
718
719 syscmd($cmd);
720 }
721
722 sub zfs_create_rpool {
723 my ($vdev) = @_;
724
725 syscmd ("zpool create -f -o ashift=12 -o cachefile=none $zfspoolname $vdev") == 0 ||
726 die "unable to create zfs root pool\n";
727
728 syscmd ("zfs create $zfspoolname/ROOT") == 0 ||
729 die "unable to create zfs $zfspoolname/ROOT volume\n";
730
731 syscmd ("zfs create $zfspoolname/data") == 0 ||
732 die "unable to create zfs $zfspoolname/data volume\n";
733
734 syscmd ("zfs create $zfspoolname/ROOT/pve-1") == 0 ||
735 die "unable to create zfs $zfspoolname/ROOT/pve-1 volume\n";
736
737 # disable atime during insatll
738 syscmd ("zfs set atime=off $zfspoolname") == 0 ||
739 die "unable to set zfs properties\n";
740 syscmd ("zfs set compression=lz4 $zfspoolname") == 0 ||
741 die "unable to set zfs properties\n";
742 }
743
744 sub zfs_create_swap {
745 my ($swapsize) = @_;
746
747 syscmd ("zfs create -V ${swapsize}K -b 4K $zfspoolname/swap") == 0 ||
748 die "unable to create zfs swap device\n";
749
750 syscmd ("zfs set com.sun:auto-snapshot=false $zfspoolname/swap") == 0 ||
751 die "unable to set zfs properties\n";
752
753 # reduces memory pressure
754 syscmd ("zfs set sync=always $zfspoolname/swap") == 0 ||
755 die "unable to set zfs properties\n";
756
757 return "/dev/zvol/$zfspoolname/swap";
758 }
759
760 sub partition_bootable_disk {
761 my ($target_dev, $maxhdsize, $ptype) = @_;
762
763 die "too dangerous" if $opt_testmode;
764
765 die "unknown partition type '$ptype'"
766 if !($ptype eq '8E00' || $ptype eq '8300');
767
768 syscmd("sgdisk -Z ${target_dev}");
769 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
770
771 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
772 if ($maxhdsize && ($maxhdsize < $hdsize)) {
773 $hdsize = $maxhdsize;
774 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
775 }
776
777 my $hdgb = int($hdsize/(1024*1024));
778 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
779
780 # 1 - GRUB boot partition: 1M
781 # 2 - EFI ESP: 128M
782 # 3 - OS/Data partition
783
784 my $grubbootdev = get_partition_dev($target_dev, 1);
785 my $efibootdev = get_partition_dev($target_dev, 2);
786 my $osdev = get_partition_dev ($target_dev, 3);
787
788 my $pcmd = ['sgdisk', '-a1'];
789
790 my $pnum = 1;
791 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
792
793 $pnum = 2;
794 # Note: from sector 2048 to 128M
795 my $endsec = 128*1024*2 - 1;
796 push @$pcmd, "-n$pnum:2048:$endsec", "-t$pnum:EF00";
797
798 $pnum = 3;
799 # Note: from 128M to end
800 push @$pcmd, "-n$pnum:128M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
801
802 push @$pcmd, $target_dev;
803
804 my $os_size = $hdsize - 128*1024;
805
806 syscmd($pcmd) == 0 ||
807 die "unable to partition harddisk '${target_dev}'\n";
808
809 return ($os_size, $osdev, $efibootdev);
810 }
811
812 # ZFS has this use_whole_disk concept, so we try to partition the same
813 # way as zfs does by default. There is room at start of disk to insert
814 # a grub boot partition. But adding a EFI ESP is not possible.
815 #
816 # Note: zfs people think this is just a waste of space an not
817 # required. Instead, you should put the ESP on another disk (log,
818 # ..).
819
820 sub partition_bootable_zfs_disk {
821 my ($target_dev) = @_;
822
823 die "too dangerous" if $opt_testmode;
824
825 syscmd("sgdisk -Z ${target_dev}");
826 my $hdsize = hd_size($target_dev); # size in blocks (1024 bytes)
827
828 my $hdgb = int($hdsize/(1024*1024));
829 die "hardisk '$target_dev' too small (${hdsize}GB)\n" if $hdgb < 8;
830
831 # 1 - GRUB boot partition: 1M
832 # 2 - OS/Data partition
833 # 9 - ZFS reserved partition
834
835 my $grubbootdev = get_partition_dev($target_dev, 1);
836 my $osdev = get_partition_dev ($target_dev, 2);
837
838 my $pcmd = ['sgdisk', '-a1'];
839
840 my $pnum = 1;
841 push @$pcmd, "-n$pnum:34:2047", "-t$pnum:EF02";
842
843 $pnum = 9;
844 push @$pcmd, "-n$pnum:-8M:0", "-t$pnum:BF07";
845
846 $pnum = 2;
847 push @$pcmd, "-n$pnum:2048:0", "-t$pnum:BF01", '-c', "$pnum:zfs";
848
849 push @$pcmd, $target_dev;
850
851 my $os_size = $hdsize - 1024 - 1024*8;
852
853 syscmd($pcmd) == 0 ||
854 die "unable to partition harddisk '${target_dev}'\n";
855
856 return ($os_size, $osdev);
857 }
858
859 sub create_lvm_volumes {
860 my ($lvmdev, $os_size, $swap_size) = @_;
861
862 my $rootdev = '/dev/pve/root';
863 my $datadev = '/dev/pve/data';
864 my $swapfile = '/dev/pve/swap';
865
866 # we use --metadatasize 250k, which reseults in "pe_start = 512"
867 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
868 syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
869 die "unable to initialize physical volume $lvmdev\n";
870 syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
871 die "unable to create volume group 'pve'\n";
872
873 my $hdgb = int($os_size/(1024*1024));
874 my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
875
876 my $maxroot;
877 if ($config_options->{maxroot}) {
878 $maxroot = $config_options->{maxroot};
879 } else {
880 $maxroot = 96;
881 }
882
883 my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
884
885 my $rest = $os_size - $swap_size - $rootsize; # in KB
886
887 my $minfree;
888 if ($config_options->{minfree}) {
889 $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
890 $config_options->{minfree}*1024*1024 ;
891 } else {
892 $minfree = $space;
893 }
894
895 $rest = $rest - $minfree;
896
897 if ($config_options->{maxvz}) {
898 $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
899 $config_options->{maxvz}*1024*1024 : $rest;
900 }
901
902 syscmd ("/sbin/lvcreate -L${swap_size}K -nswap pve") == 0 ||
903 die "unable to create swap volume\n";
904
905 syscmd ("/sbin/lvcreate -L${rootsize}K -nroot pve") == 0 ||
906 die "unable to create root volume\n";
907
908 syscmd ("/sbin/lvcreate -L${rest}K -ndata pve") == 0 ||
909 die "unable to create data volume\n";
910
911 syscmd ("/sbin/lvconvert --yes --type thin-pool pve/data") == 0 ||
912 die "unable to create data thin-pool\n";
913
914 syscmd ("/sbin/vgchange -a y pve") == 0 ||
915 die "unable to activate volume group\n";
916
917 return ($rootdev, $datadev, $swapfile);
918 }
919
920 sub compute_swapsize {
921 my ($hdsize) = @_;
922
923 my $hdgb = int($hdsize/(1024*1024));
924
925 my $swapsize;
926 if ($config_options->{swapsize}) {
927 $swapsize = $config_options->{swapsize}*1024*1024;
928 } else {
929 my $ss = int ($total_memory / 1024);
930 $ss = 4 if $ss < 4;
931 $ss = ($hdgb/8) if $ss > ($hdgb/8);
932 $ss = 8 if $ss > 8;
933 $swapsize = $ss*1024*1024;
934 }
935 }
936
937 my $udevadm_trigger_block = sub {
938 my ($nowait) = @_;
939
940 sleep(1) if !$nowait; # give kernel time to reread part table
941
942 # trigger udev to create /dev/disk/by-uuid
943 syscmd ("udevadm trigger --subsystem-match block");
944 syscmd ("udevadm settle --timeout 10");
945 };
946
947 sub extract_data {
948 my ($tgzfile, $targetdir) = @_;
949
950 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
951
952 my $starttime = [Time::HiRes::gettimeofday];
953
954 my $bootdevinfo = [];
955
956 my $datadev;
957 my $swapfile;
958 my $rootdev;
959
960 my $use_zfs = 0;
961 my $use_btrfs = 0;
962
963 my $filesys = $config_options->{filesys};
964
965 if ($filesys =~ m/zfs/) {
966 $target_hd = undef; # do not use this config
967 $use_zfs = 1;
968 $targetdir = "/$zfspoolname/ROOT/pve-1";
969 } elsif ($filesys =~ m/btrfs/) {
970 $target_hd = undef; # do not use this config
971 $use_btrfs = 1;
972 }
973
974 if ($use_zfs) {
975 my $i;
976 for ($i = 5; $i > 0; $i--) {
977 syscmd("modprobe zfs");
978 last if -c "/dev/zfs";
979 sleep(1);
980 }
981
982 die "unable to load zfs kernel module\n" if !$i;
983 }
984
985 eval {
986
987
988 my $maxper = 0.25;
989
990 update_progress (0, 0, $maxper, "create partitions");
991
992 if ($opt_testmode) {
993
994 $rootdev = abs_path($opt_testmode);
995 syscmd("umount $rootdev");
996
997 if ($use_btrfs) {
998
999 die "unsupported btrfs mode (for testing environment)\n"
1000 if $filesys ne 'btrfs (RAID0)';
1001
1002 btrfs_create([$rootdev], 'single');
1003
1004 } elsif ($use_zfs) {
1005
1006 die "unsupported zfs mode (for testing environment)\n"
1007 if $filesys ne 'zfs (RAID0)';
1008
1009 syscmd ("zpool destroy $zfstestpool");
1010
1011 zfs_create_rpool($rootdev);
1012
1013 } else {
1014
1015 # nothing to do
1016 }
1017
1018 } elsif ($use_btrfs) {
1019
1020 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
1021 my $btrfs_partitions = [];
1022 my $disksize;
1023 foreach my $hd (@$devlist) {
1024 my $devname = @$hd[1];
1025 my ($size, $osdev, $efidev) =
1026 partition_bootable_disk($devname, undef, '8300');
1027 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1028 my $by_id = find_stable_path("/dev/disk/by-id", $devname);
1029 push @$bootdevinfo, { esp => $efidev, devname => $devname,
1030 osdev => $osdev, by_id => $by_id };
1031 push @$btrfs_partitions, $osdev;
1032 $disksize = $size;
1033 }
1034
1035 &$udevadm_trigger_block();
1036
1037 btrfs_create($btrfs_partitions, $btrfs_mode);
1038
1039 } elsif ($use_zfs) {
1040
1041 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
1042
1043 my $disksize;
1044 foreach my $hd (@$bootdevlist) {
1045 my $devname = @$hd[1];
1046 my ($size, $osdev) =
1047 partition_bootable_zfs_disk($devname);
1048 die "unable to mirror disks with different sizes!\n"
1049 if $disksize && ($size != $disksize);
1050 push @$bootdevinfo, { devname => $devname, osdev => $osdev};
1051 $disksize = $size;
1052 }
1053
1054 &$udevadm_trigger_block();
1055
1056 foreach my $di (@$bootdevinfo) {
1057 my $devname = $di->{devname};
1058 $di->{by_id} = find_stable_path ("/dev/disk/by-id", $devname);
1059
1060 # Note: using /dev/disk/by-id/ does not work for unknown reason, we get
1061 # cannot create 'rpool': no such pool or dataset
1062 #my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1063
1064 my $osdev = $di->{osdev};
1065 $vdev =~ s/ $devname/ $osdev/;
1066 }
1067
1068 zfs_create_rpool($vdev);
1069
1070 my $swap_size = compute_swapsize($disksize);
1071 $swapfile = zfs_create_swap($swap_size);
1072
1073 } else {
1074
1075 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
1076
1077 my $maxhdsize;
1078 if ($config_options->{hdsize}) {
1079 # max hdsize passed on cmdline (GB)
1080 $maxhdsize = $config_options->{hdsize}*1024*1024;
1081 }
1082
1083 my ($os_size, $osdev, $efidev);
1084 ($os_size, $osdev, $efidev) =
1085 partition_bootable_disk($target_hd, $maxhdsize, '8E00');
1086
1087 &$udevadm_trigger_block();
1088
1089 my $by_id = find_stable_path ("/dev/disk/by-id", $target_hd);
1090 push @$bootdevinfo, { esp => $efidev, devname => $target_hd,
1091 osdev => $osdev, by_id => $by_id };
1092
1093 my $swap_size = compute_swapsize($os_size);
1094 ($rootdev, $datadev, $swapfile) =
1095 create_lvm_volumes($osdev, $os_size, $swap_size);
1096
1097 # trigger udev to create /dev/disk/by-uuid
1098 &$udevadm_trigger_block(1);
1099 }
1100
1101 if ($use_zfs) {
1102 # to be fast during installation
1103 syscmd ("zfs set sync=disabled $zfspoolname") == 0 ||
1104 die "unable to set zfs properties\n";
1105 }
1106
1107 update_progress (0.03, 0, $maxper, "create swap space");
1108 if ($swapfile) {
1109 syscmd ("mkswap -f $swapfile") == 0 ||
1110 die "unable to create swap space\n";
1111 }
1112
1113 update_progress (0.05, 0, $maxper, "creating filesystems");
1114
1115 foreach my $di (@$bootdevinfo) {
1116 next if !$di->{esp};
1117 syscmd ("mkfs.vfat -F32 $di->{esp}") == 0 ||
1118 die "unable to initialize EFI ESP on device $di->{esp}\n";
1119 }
1120
1121 if ($use_zfs) {
1122 # do nothing
1123 } elsif ($use_btrfs) {
1124 # do nothing
1125 } else {
1126 create_filesystem ($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1127 }
1128
1129 update_progress (1, 0.05, $maxper, "mounting target $rootdev");
1130
1131 if ($use_zfs) {
1132 # do nothing
1133 } elsif ($use_btrfs) {
1134 syscmd("mount -n $rootdev -o noatime,nobarrier $targetdir") == 0 ||
1135 die "unable to mount $rootdev\n";
1136 } else {
1137 syscmd ("mount -n $rootdev -o noatime,barrier=0 $targetdir") == 0 ||
1138 die "unable to mount $rootdev\n";
1139 }
1140
1141 mkdir "$targetdir/boot";
1142 mkdir "$targetdir/boot/efi";
1143
1144 mkdir "$targetdir/var";
1145 mkdir "$targetdir/var/lib";
1146 mkdir "$targetdir/var/lib/vz";
1147 mkdir "$targetdir/var/lib/pve";
1148
1149 if ($use_btrfs) {
1150 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1151 die "unable to create btrfs subvolume\n";
1152 }
1153
1154 display_html ("extract2-rulesystem.htm");
1155 update_progress (1, 0.05, $maxper, "extracting base system");
1156
1157 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($tgzfile);
1158 $ino || die "unable to open file '$tgzfile' - $!\n";
1159
1160 my $files;
1161 if ($opt_testmode) {
1162 $files = file_read_firstline("/pve/$release/install/pve-base.cnt");
1163 } else {
1164 $files = file_read_firstline("/proxmox/pve-base.cnt");
1165 }
1166
1167 my $per = 0;
1168 my $count = 0;
1169
1170 run_command ("tar xvf $tgzfile -C $targetdir", sub {
1171 my $line = shift;
1172 $count++;
1173 my $nper = int (($count *100)/$files);
1174 if ($nper != $per) {
1175 $per = $nper;
1176 my $frac = $per > 100 ? 100 : $per/100;
1177 update_progress ($frac, $maxper, 0.5);
1178 }
1179 });
1180
1181 syscmd ("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1182 die "unable to mount tmpfs on $targetdir/tmp\n";
1183 syscmd ("mount -n -t proc proc $targetdir/proc") == 0 ||
1184 die "unable to mount proc on $targetdir/proc\n";
1185 syscmd ("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1186 die "unable to mount sysfs on $targetdir/sys\n";
1187
1188 display_html ("extract3-spam.htm");
1189 update_progress (1, $maxper, 0.5, "configuring base system");
1190
1191 # configure hosts
1192
1193 my $hosts =
1194 "127.0.0.1 localhost.localdomain localhost\n" .
1195 "$ipaddress $hostname.$domain $hostname pvelocalhost\n\n" .
1196 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1197 "::1 ip6-localhost ip6-loopback\n" .
1198 "fe00::0 ip6-localnet\n" .
1199 "ff00::0 ip6-mcastprefix\n" .
1200 "ff02::1 ip6-allnodes\n" .
1201 "ff02::2 ip6-allrouters\n" .
1202 "ff02::3 ip6-allhosts\n";
1203
1204 write_config ($hosts, "$targetdir/etc/hosts");
1205
1206 write_config ("$hostname\n", "$targetdir/etc/hostname");
1207
1208 syscmd ("/bin/hostname $hostname") if !$opt_testmode;
1209
1210 # configure interfaces
1211
1212 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1213
1214 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1215
1216 $ifaces .=
1217 "auto vmbr0\niface vmbr0 $ntype static\n" .
1218 "\taddress $ipaddress\n" .
1219 "\tnetmask $netmask\n" .
1220 "\tgateway $gateway\n" .
1221 "\tbridge_ports eth0\n" .
1222 "\tbridge_stp off\n" .
1223 "\tbridge_fd 0\n";
1224
1225 write_config ($ifaces, "$targetdir/etc/network/interfaces");
1226
1227 # configure dns
1228
1229 my $resolfconf = "search $domain\nnameserver $dnsserver\n";
1230 write_config ($resolfconf, "$targetdir/etc/resolv.conf");
1231
1232 # configure fstab
1233
1234 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1235
1236 if ($use_zfs) {
1237 # do nothing
1238 } elsif ($use_btrfs) {
1239 my $fsuuid;
1240 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1241 run_command($cmd, sub {
1242 my $line = shift;
1243
1244 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1245 $fsuuid = $1;
1246 }
1247 });
1248
1249 die "unable to detect FS UUID" if !defined($fsuuid);
1250
1251 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1252 } else {
1253 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1254 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1255 }
1256
1257 # mount /boot/efi
1258 # Note: this is required by current grub, but really dangerous, because
1259 # vfat does not have journaling, so it triggers manual fsck after each crash
1260 # so we only mount /boot/efi if really required (efi systems).
1261 if ($grub_plattform =~ m/^efi-/) {
1262 if (scalar(@$bootdevinfo)) {
1263 my $di = @$bootdevinfo[0]; # simply use first disk
1264 if ($di->{esp}) {
1265 my $efi_boot_uuid = $di->{esp};
1266 if (my $uuid = find_dev_by_uuid ($di->{esp})) {
1267 $efi_boot_uuid = "UUID=$uuid";
1268 }
1269
1270 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1271 }
1272 }
1273 }
1274
1275
1276 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1277
1278 $fstab .= "proc /proc proc defaults 0 0\n";
1279
1280 write_config ($fstab, "$targetdir/etc/fstab");
1281 write_config ("", "$targetdir/etc/mtab");
1282
1283 syscmd ("cp ${proxmox_dir}/policy-disable-rc.d " .
1284 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1285 die "unable to copy policy-rc.d\n";
1286 syscmd ("cp ${proxmox_dir}/fake-start-stop-daemon " .
1287 "$targetdir/sbin/") == 0 ||
1288 die "unable to copy start-stop-daemon\n";
1289
1290 diversion_add ($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1291 diversion_add ($targetdir, "/usr/sbin/update-grub", "/bin/true");
1292 diversion_add ($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1293
1294 syscmd ("touch $targetdir/proxmox_install_mode");
1295
1296 my $grub_install_devices_txt = '';
1297 foreach my $di (@$bootdevinfo) {
1298 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1299 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1300 }
1301
1302 # Note: debian-installer/locale is used by console-setup
1303
1304 debconfig_set ($targetdir, <<_EOD);
1305 locales locales/default_environment_locale select en_US.UTF-8
1306 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1307 samba-common samba-common/dhcp boolean false
1308 samba-common samba-common/workgroup string WORKGROUP
1309 postfix postfix/main_mailer_type select Local only
1310 keyboard-configuration keyboard-configuration/xkb-keymap select $keymap
1311 d-i debian-installer/locale select en_US.UTF-8
1312 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1313 _EOD
1314
1315 my $pkgdir = $opt_testmode ? "packages" : "/proxmox/packages";
1316 my $pkg_count = 0;
1317 while (<$pkgdir/*.deb>) { $pkg_count++ };
1318
1319 # btrfs/dpkg is extremely slow without --force-unsafe-io
1320 my $dpkg_opts = $use_btrfs ? "--force-unsafe-io" : "";
1321
1322 $count = 0;
1323 while (<$pkgdir/*.deb>) {
1324 chomp;
1325 my $path = $_;
1326 my ($deb) = $path =~ m/$pkgdir\/(.*\.deb)/;
1327 # if ($deb =~ m/^grub-efi-/ && $deb !~ m/^grub-${grub_plattform}/) {
1328 # $count++;
1329 # next;
1330 # }
1331 update_progress ($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1332 print "extracting: $deb\n";
1333 syscmd ("cp $path $targetdir/tmp/$deb") == 0 ||
1334 die "installation of package $deb failed\n";
1335 syscmd ("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1336 die "installation of package $deb failed\n";
1337 update_progress ((++$count)/$pkg_count, 0.5, 0.75);
1338 }
1339
1340 display_html ("extract4-virus.htm");
1341
1342 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1343 $count = 0;
1344 run_command ($cmd, sub {
1345 my $line = shift;
1346 if ($line =~ m/Setting up\s+(\S+)/) {
1347 update_progress ((++$count)/$pkg_count, 0.75, 0.95,
1348 "configuring $1");
1349 }
1350 });
1351
1352 debconfig_set ($targetdir, <<_EOD);
1353 postfix postfix/main_mailer_type select No configuration
1354 _EOD
1355
1356 unlink "$targetdir/etc/mailname";
1357 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1358 write_config ($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1359
1360 # make sure we have all postfix directories
1361 syscmd ("chroot $targetdir /usr/sbin/postfix check");
1362 # cleanup mail queue
1363 syscmd ("chroot $targetdir /usr/sbin/postsuper -d ALL");
1364
1365 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1366 syscmd ("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1367
1368 unlink "$targetdir/proxmox_install_mode";
1369
1370 # set timezone
1371 unlink ("$targetdir/etc/localtime");
1372 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1373 write_config ("$timezone\n", "$targetdir/etc/timezone");
1374
1375 # set apt mirror
1376 if (my $mirror = $cmap->{country}->{$country}->{mirror}) {
1377 my $fn = "$targetdir/etc/apt/sources.list";
1378 syscmd ("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1379 }
1380
1381 # create extended_states for apt (avoid cron job warning if that
1382 # file does not exist)
1383 write_config ('', "$targetdir/var/lib/apt/extended_states");
1384
1385 # allow ssh root login
1386 syscmd ("sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' '$targetdir/etc/ssh/sshd_config'");
1387
1388 # save installer settings
1389 my $ucc = uc ($country);
1390 debconfig_set ($targetdir, <<_EOD);
1391 pve-manager pve-manager/country string $ucc
1392 _EOD
1393
1394 update_progress (0.8, 0.95, 1, "make system bootable");
1395
1396 if ($use_zfs) {
1397 syscmd ("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/pve-1 boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1398 die "unable to update /etc/default/grub\n";
1399
1400 }
1401
1402 diversion_remove ($targetdir, "/usr/sbin/update-grub");
1403 diversion_remove ($targetdir, "/usr/sbin/update-initramfs");
1404
1405 if (!$opt_testmode) {
1406
1407 unlink ("$targetdir/etc/mtab");
1408 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1409 syscmd ("mount -n --bind /dev $targetdir/dev");
1410
1411 syscmd ("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1412 die "unable to install initramfs\n";
1413
1414 foreach my $di (@$bootdevinfo) {
1415 my $dev = $di->{devname};
1416 syscmd ("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1417 die "unable to install the i386-pc boot loader on '$dev'\n";
1418
1419 if ($di->{esp}) {
1420 syscmd ("mount -n $di->{esp} $targetdir/boot/efi") == 0 ||
1421 die "unable to mount $di->{esp}\n";
1422 syscmd ("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1423 die "unable to install the EFI boot loader on '$dev'\n";
1424 # also install fallback boot file (OVMF does not boot without)
1425 mkdir("$targetdir/boot/efi/EFI/BOOT");
1426 syscmd("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1427 die "unable to copy efi boot loader\n";
1428
1429 syscmd ("umount $targetdir/boot/efi") == 0 ||
1430 die "unable to umount $targetdir/boot/efi\n";
1431 }
1432 }
1433
1434 syscmd ("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1435 die "unable to update boot loader config\n";
1436
1437 syscmd ("umount $targetdir/dev");
1438 }
1439
1440 # cleanup
1441
1442 # hack: remove dead.letter from sshd installation
1443 syscmd ("rm -rf $targetdir/dead.letter");
1444
1445 unlink "$targetdir/usr/sbin/policy-rc.d";
1446
1447 diversion_remove ($targetdir, "/sbin/start-stop-daemon");
1448
1449 # set root password
1450 my $octets = encode("utf-8", $password);
1451 run_command ("chroot $targetdir /usr/sbin/chpasswd", undef,
1452 "root:$octets\n");
1453
1454 # create pmxcfs DB
1455
1456 my $tmpdir = "$targetdir/tmp/pve";
1457 mkdir $tmpdir;
1458
1459 # write vnc keymap to datacenter.cfg
1460 my $vnckmap = $cmap->{kmap}->{$keymap}->{kvm} || 'en-us';
1461 write_config ("keyboard: $vnckmap\n",
1462 "$tmpdir/datacenter.cfg");
1463
1464 # save admin email
1465 write_config ("user:root\@pam:1:0:::${mailto}::\n",
1466 "$tmpdir/user.cfg");
1467
1468 # write storage.cfg
1469 my $strorage_cfg_fn = "$tmpdir/storage.cfg";
1470 if ($use_zfs) {
1471 write_config ($storage_cfg_zfs, $strorage_cfg_fn);
1472 } elsif ($use_btrfs) {
1473 write_config ($storage_cfg_btrfs, $strorage_cfg_fn);
1474 } else {
1475 write_config ($storage_cfg_lvmthin, $strorage_cfg_fn);
1476 }
1477
1478 run_command("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1479
1480 syscmd ("rm -rf $tmpdir");
1481 };
1482
1483 my $err = $@;
1484
1485 update_progress (1, 0, 1, "");
1486
1487 print $err if $err;
1488
1489 if ($opt_testmode) {
1490 my $elapsed = Time::HiRes::tv_interval($starttime);
1491 print "Elapsed extract time: $elapsed\n";
1492
1493 syscmd ("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> pve-final.pkglist");
1494 }
1495
1496 syscmd ("umount $targetdir/var/lib/vz");
1497 syscmd ("umount $targetdir/tmp");
1498 syscmd ("umount $targetdir/proc");
1499 syscmd ("umount $targetdir/sys");
1500
1501 if ($use_zfs) {
1502 syscmd ("zfs umount -a") == 0 ||
1503 die "unable to unmount zfs\n";
1504 } else {
1505 syscmd ("umount -d $targetdir");
1506 }
1507
1508 if (!$err && $use_zfs) {
1509 syscmd ("zfs set sync=standard $zfspoolname") == 0 ||
1510 die "unable to set zfs properties\n";
1511
1512 syscmd ("zfs set mountpoint=/ $zfspoolname/ROOT/pve-1") == 0 ||
1513 die "zfs set mountpoint failed\n";
1514
1515 syscmd ("zpool set bootfs=$zfspoolname/ROOT/pve-1 $zfspoolname") == 0 ||
1516 die "zfs set bootfs failed\n";
1517 }
1518
1519 die $err if $err;
1520 }
1521
1522 sub display_html {
1523 my ($filename) = @_;
1524
1525 my $path = "${proxmox_dir}/html/$filename";
1526 my $url = "file://$path";
1527
1528 my $data = file_get_contents($path);
1529
1530 if ($filename eq 'license.htm') {
1531 my $licensefn = -f "/EULA" ? "/EULA" :
1532 $opt_testmode ? "./copyright" :
1533 "/usr/share/doc/pve-installer/copyright";
1534 my $license = decode('utf8', file_get_contents($licensefn));
1535 $license =~ m/^\s+(.+\n)/;
1536 my $title = $licensefn eq '/EULA' ? "END USER LICENSE AGREEMENT (EULA)": $1;
1537 $data =~ s/__LICENSE__/$license/;
1538 $data =~ s/__LICENSE_TITLE__/$title/;
1539 }
1540
1541 $htmlview->load_html_string($data, $url);
1542 }
1543
1544 sub set_next {
1545 my ($text, $fctn) = @_;
1546
1547 $next_fctn = $fctn;
1548 $text = "_Next" if !$text;
1549 $next->set_label ($text);
1550
1551 $next->grab_focus ();
1552 }
1553
1554 sub url_requested {
1555 my ($doc, $url, $stream) = @_;
1556
1557 $stream->set_cancel_func (sub {}); # hack: avoid warning
1558
1559 my $path = "${proxmox_dir}/html/$url";
1560
1561 if (-f $path) {
1562 open (HTMLTMP, $path) ||
1563 die "unable to open file '$path' - $!\n";
1564 my $buf;
1565 while (my $i = read (HTMLTMP, $buf, 4096)) {
1566 $stream->write ($buf);
1567 Gtk3::main_iteration() while Gtk3::events_pending();
1568 }
1569 close (HTMLTMP);
1570 }
1571
1572 #$stream->close(); # hack: dont close - avoid crash
1573 }
1574
1575 sub create_main_window {
1576
1577 $window = Gtk3::Window->new ();
1578 $window->set_default_size (1024, 768);
1579 $window->set_has_resize_grip(0);
1580 $window->set_decorated (0) if !$opt_testmode;
1581
1582 my $vbox = Gtk3::VBox->new (0, 0);
1583
1584 my $image = Gtk3::Image->new_from_file ("${proxmox_dir}/proxlogo.png");
1585 $vbox->pack_start ($image, 0, 0, 0);
1586
1587 my $hbox = Gtk3::HBox->new (0, 0);
1588 $vbox->pack_start ($hbox, 1, 1, 0);
1589
1590 # my $f1 = Gtk3::Frame->new ('test');
1591 # $f1->set_shadow_type ('none');
1592 # $hbox->pack_start ($f1, 1, 1, 0);
1593
1594 my $sep1 = Gtk3::HSeparator->new;
1595 $vbox->pack_start ($sep1, 0, 0, 0);
1596
1597 $cmdbox = Gtk3::HBox->new ();
1598 $vbox->pack_start ($cmdbox, 0, 0, 10);
1599
1600 $next = Gtk3::Button->new ('_Next');
1601 $next->signal_connect (clicked => sub { &$next_fctn (); });
1602 $cmdbox->pack_end ($next, 0, 0, 10);
1603 my $abort = Gtk3::Button->new ('_Abort');
1604 $abort->set_can_focus (0);
1605 $cmdbox->pack_start ($abort, 0, 0, 10);
1606 $abort->signal_connect (clicked => sub { exit (-1); });
1607
1608 my $vbox2 = Gtk3::VBox->new (0, 0);
1609 $hbox->add ($vbox2);
1610
1611 $htmlview = Gtk3::WebKit::WebView->new();
1612 my $scrolls = Gtk3::ScrolledWindow->new();
1613 $scrolls->add($htmlview);
1614
1615 my $hbox2 = Gtk3::HBox->new (0, 0);
1616 $hbox2->pack_start ($scrolls, 1, 1, 0);
1617
1618 $vbox2->pack_start ($hbox2, 1, 1, 0);
1619
1620 my $vbox3 = Gtk3::VBox->new (0, 0);
1621 $vbox2->pack_start ($vbox3, 0, 0, 0);
1622
1623 my $sep2 = Gtk3::HSeparator->new;
1624 $vbox3->pack_start ($sep2, 0, 0, 0);
1625
1626 $inbox = Gtk3::HBox->new (0, 0);
1627 $vbox3->pack_start ($inbox, 0, 0, 0);
1628
1629 $window->add ($vbox);
1630
1631 $window->show_all;
1632 $window->realize ();
1633 }
1634
1635 sub cleanup_view {
1636 $inbox->foreach(sub {
1637 my $child = shift;
1638 $inbox->remove ($child);
1639 });
1640 }
1641
1642 # fixme: newer GTK3 has special properties to handle numbers with Entry
1643 # only allow floating point numbers with Gtk3::Entry
1644 sub check_float {
1645 my ($entry, $event) = @_;
1646
1647
1648 my $val = $event->get_keyval;
1649
1650 if ($val == ord '.' ||
1651 $val == Gtk3::Gdk::KEY_ISO_Left_Tab ||
1652 $val == Gtk3::Gdk::KEY_Shift_L ||
1653 $val == Gtk3::Gdk::KEY_Tab ||
1654 $val == Gtk3::Gdk::KEY_Left ||
1655 $val == Gtk3::Gdk::KEY_Right ||
1656 $val == Gtk3::Gdk::KEY_BackSpace ||
1657 $val == Gtk3::Gdk::KEY_Delete ||
1658 ($val >= ord '0' && $val <= ord '9') ||
1659 ($val >= Gtk3::Gdk::KEY_KP_0 &&
1660 $val <= Gtk3::Gdk::KEY_KP_9)) {
1661 return undef;
1662 }
1663
1664 return 1;
1665 }
1666
1667 sub create_text_input {
1668 my ($default, $text) = @_;
1669
1670 my $hbox = Gtk3::HBox->new (0, 0);
1671
1672 my $label = Gtk3::Label->new ($text);
1673 $label->set_size_request (150, -1);
1674 $label->set_alignment (1, 0.5);
1675 $hbox->pack_start ($label, 0, 0, 10);
1676 my $e1 = Gtk3::Entry->new ();
1677 $e1->set_width_chars (30);
1678 $hbox->pack_start ($e1, 0, 0, 0);
1679 $e1->set_text ($default);
1680
1681 return ($hbox, $e1);
1682 }
1683
1684 sub get_ip_config {
1685
1686 my $ifconfig = `ifconfig eth0`;
1687
1688 my ($addr) = $ifconfig =~ m/inet addr:(\S*)/m;
1689 my ($mask) = $ifconfig =~ m/Mask:(\S*)/m;
1690
1691 my $route = `route -n`;
1692 my ($gateway) = $route =~ m/^0\.0\.0\.0\s+(\d+\.\d+\.\d+\.\d+)\s+/m;
1693
1694 my $resolvconf = `cat /etc/resolv.conf`;
1695 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
1696 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
1697
1698 return {
1699 addr => $addr,
1700 mask => $mask,
1701 gateway => $gateway,
1702 dnsserver => $dnsserver,
1703 domain => $domain,
1704 }
1705 }
1706
1707 sub display_message {
1708 my ($msg) = @_;
1709
1710 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1711 'info', 'ok', $msg);
1712 $dialog->run();
1713 $dialog->destroy();
1714 }
1715
1716 sub display_error {
1717 my ($msg) = @_;
1718
1719 my $dialog = Gtk3::MessageDialog->new ($window, 'modal',
1720 'error', 'ok', $msg);
1721 $dialog->run();
1722 $dialog->destroy();
1723 }
1724
1725 sub create_ipconf_view {
1726
1727 cleanup_view ();
1728 display_html ("ipconf.htm");
1729
1730 my $vbox = Gtk3::VBox->new (0, 0);
1731 $inbox->pack_start ($vbox, 1, 0, 0);
1732 my $hbox = Gtk3::HBox->new (0, 0);
1733 $vbox->pack_start ($hbox, 0, 0, 10);
1734 my $vbox2 = Gtk3::VBox->new (0, 0);
1735 $hbox->add ($vbox2);
1736
1737 my $addr = $ipconf->{addr} || '192.168.100.2';
1738 my $mask = $ipconf->{mask} || '255.255.255.0';
1739
1740 my $hn = $ipconf->{domain} ? "pve.$ipconf->{domain}" : 'pve.domain.tld';
1741
1742 my ($hostbox, $hostentry) =
1743 create_text_input ($hn, 'Hostname (FQDN):');
1744 $vbox2->pack_start ($hostbox, 0, 0, 2);
1745
1746 my $ipbox;
1747 ($ipbox, $ipconf_entry_addr) =
1748 create_text_input ($addr, 'IP Address:');
1749 $vbox2->pack_start ($ipbox, 0, 0, 2);
1750
1751 my $maskbox;
1752 ($maskbox, $ipconf_entry_mask) =
1753 create_text_input ($mask, 'Netmask:');
1754 $vbox2->pack_start ($maskbox, 0, 0, 2);
1755
1756 $gateway = $ipconf->{gateway} || '192.168.100.1';
1757
1758 my $gwbox;
1759 ($gwbox, $ipconf_entry_gw) =
1760 create_text_input ($gateway, 'Gateway:');
1761
1762 $vbox2->pack_start ($gwbox, 0, 0, 2);
1763
1764 $dnsserver = $ipconf->{dnsserver} || $gateway;
1765
1766 my $dnsbox;
1767 ($dnsbox, $ipconf_entry_dns) =
1768 create_text_input ($dnsserver, 'DNS Server:');
1769
1770 $vbox2->pack_start ($dnsbox, 0, 0, 0);
1771
1772 $inbox->show_all;
1773 set_next (undef, sub {
1774
1775 # verify hostname
1776
1777 my $text = $hostentry->get_text();
1778
1779 $text =~ s/^\s+//;
1780 $text =~ s/\s+$//;
1781
1782 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
1783
1784 # Debian does not support purely numeric hostnames
1785 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
1786 display_message("Purely numeric hostnames are not allowed.");
1787 $hostentry->grab_focus();
1788 return;
1789 }
1790
1791 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.domain.tld$/ &&
1792 $text =~ m/^([^\.]+)\.(\S+)$/) {
1793 $hostname = $1;
1794 $domain = $2;
1795 } else {
1796 display_message ("Hostname does not look like a fully qualified domain name.");
1797 $hostentry->grab_focus();
1798 return;
1799 }
1800
1801 # verify ip address
1802
1803 $text = $ipconf_entry_addr->get_text();
1804 $text =~ s/^\s+//;
1805 $text =~ s/\s+$//;
1806 if ($text =~ m!^($IPV4RE)$!) {
1807 $ipaddress = $text;
1808 $ipversion = 4;
1809 } elsif ($text =~ m!^($IPV6RE)$!) {
1810 $ipaddress = $text;
1811 $ipversion = 6;
1812 } else {
1813 display_message ("IP address is not valid.");
1814 $ipconf_entry_addr->grab_focus();
1815 return;
1816 }
1817
1818 $text = $ipconf_entry_mask->get_text();
1819 $text =~ s/^\s+//;
1820 $text =~ s/\s+$//;
1821 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
1822 $netmask = $text;
1823 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
1824 $netmask = $text;
1825 } else {
1826 display_message ("Netmask is not valid.");
1827 $ipconf_entry_mask->grab_focus();
1828 return;
1829 }
1830
1831 $text = $ipconf_entry_gw->get_text();
1832 $text =~ s/^\s+//;
1833 $text =~ s/\s+$//;
1834 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1835 $gateway = $text;
1836 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1837 $gateway = $text;
1838 } else {
1839 display_message ("Gateway is not valid.");
1840 $ipconf_entry_gw->grab_focus();
1841 return;
1842 }
1843
1844 $text = $ipconf_entry_dns->get_text();
1845 $text =~ s/^\s+//;
1846 $text =~ s/\s+$//;
1847 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
1848 $dnsserver = $text;
1849 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
1850 $dnsserver = $text;
1851 } else {
1852 display_message ("DNS server is not valid.");
1853 $ipconf_entry_dns->grab_focus();
1854 return;
1855 }
1856
1857 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
1858
1859 create_extract_view ();
1860 });
1861
1862 $hostentry->grab_focus();
1863 }
1864
1865 sub get_device_desc {
1866 my ($devname, $size, $model) = @_;
1867
1868 if ($size && ($size > 0)) {
1869 $size = int($size/2048); # size in MB
1870
1871 my $text = "$devname (";
1872 if ($size >= 1024) {
1873 $size = int($size/1024); # size in GB
1874 $text .= "${size}GB";
1875 } else {
1876 $text .= "${size}MB";
1877 }
1878
1879 $text .= ", $model" if $model;
1880 $text .= ")";
1881
1882 } else {
1883 return $devname;
1884 }
1885 }
1886
1887 sub update_layout {
1888 my ($cb, $kmap) = @_;
1889
1890 my $ind;
1891 my $def;
1892 my $i = 0;
1893 my $kmaphash = $cmap->{kmaphash};
1894 foreach my $layout (sort keys %$kmaphash) {
1895 $def = $i if $kmaphash->{$layout} eq 'en-us';
1896 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
1897 $i++;
1898 }
1899
1900 $cb->set_active ($ind || $def || 0);
1901 }
1902
1903 my $lastzonecb;
1904 sub update_zonelist {
1905 my ($box, $cc) = @_;
1906
1907 my $cczones = $cmap->{cczones};
1908 my $zones = $cmap->{zones};
1909
1910 my $sel;
1911 if ($lastzonecb) {
1912 $sel = $lastzonecb->get_active_text();
1913 $box->remove ($lastzonecb);
1914 } else {
1915 $sel = $timezone; # used once to select default
1916 }
1917
1918 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
1919 $cb->set_size_request (200, -1);
1920
1921 $cb->signal_connect ('changed' => sub {
1922 $timezone = $cb->get_active_text();
1923 });
1924
1925 my @za;
1926 if ($cc && defined ($cczones->{$cc})) {
1927 @za = keys %{$cczones->{$cc}};
1928 } else {
1929 @za = keys %$zones;
1930 }
1931 my $ind;
1932 my $i = 0;
1933 foreach my $zone (sort @za) {
1934 $ind = $i if $sel && $zone eq $sel;
1935 $cb->append_text ($zone);
1936 $i++;
1937 }
1938
1939 $cb->set_active ($ind || 0);
1940
1941 $cb->show;
1942 $box->pack_start ($cb, 0, 0, 0);
1943 }
1944
1945 sub create_password_view {
1946
1947 cleanup_view ();
1948
1949 my $vbox2 = Gtk3::VBox->new (0, 0);
1950 $inbox->pack_start ($vbox2, 1, 0, 0);
1951 my $vbox = Gtk3::VBox->new (0, 0);
1952 $vbox2->pack_start ($vbox, 0, 0, 10);
1953
1954 my $hbox1 = Gtk3::HBox->new (0, 0);
1955 my $label = Gtk3::Label->new ("Password");
1956 $label->set_size_request (150, -1);
1957 $label->set_alignment (1, 0.5);
1958 $hbox1->pack_start ($label, 0, 0, 10);
1959 my $pwe1 = Gtk3::Entry->new ();
1960 $pwe1->set_visibility (0);
1961 $pwe1->set_size_request (200, -1);
1962 $hbox1->pack_start ($pwe1, 0, 0, 0);
1963
1964 my $hbox2 = Gtk3::HBox->new (0, 0);
1965 $label = Gtk3::Label->new ("Confirm");
1966 $label->set_size_request (150, -1);
1967 $label->set_alignment (1, 0.5);
1968 $hbox2->pack_start ($label, 0, 0, 10);
1969 my $pwe2 = Gtk3::Entry->new ();
1970 $pwe2->set_visibility (0);
1971 $pwe2->set_size_request (200, -1);
1972 $hbox2->pack_start ($pwe2, 0, 0, 0);
1973
1974 my $hbox3 = Gtk3::HBox->new (0, 0);
1975 $label = Gtk3::Label->new ("E-Mail");
1976 $label->set_size_request (150, -1);
1977 $label->set_alignment (1, 0.5);
1978 $hbox3->pack_start ($label, 0, 0, 10);
1979 my $eme = Gtk3::Entry->new ();
1980 $eme->set_size_request (200, -1);
1981 $hbox3->pack_start ($eme, 0, 0, 0);
1982
1983
1984 $vbox->pack_start ($hbox1, 0, 0, 5);
1985 $vbox->pack_start ($hbox2, 0, 0, 5);
1986 $vbox->pack_start ($hbox3, 0, 0, 15);
1987
1988 $inbox->show_all;
1989
1990 display_html ("passwd.htm");
1991
1992 set_next (undef, sub {
1993
1994 my $t1 = $pwe1->get_text;
1995 my $t2 = $pwe2->get_text;
1996
1997 if (length ($t1) < 5) {
1998 display_message ("Password is too short.");
1999 $pwe1->grab_focus();
2000 return;
2001 }
2002
2003 if ($t1 ne $t2) {
2004 display_message ("Password does not match.");
2005 $pwe1->grab_focus();
2006 return;
2007 }
2008
2009 my $t3 = $eme->get_text;
2010 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2011 display_message ("E-Mail does not look like a vaild address" .
2012 " (user\@domain.tld)");
2013 $eme->grab_focus();
2014 return;
2015
2016 }
2017
2018 $password = $t1;
2019 $mailto = $t3;
2020
2021 create_ipconf_view();
2022 });
2023
2024 $pwe1->grab_focus();
2025
2026 }
2027
2028 sub create_country_view {
2029
2030 cleanup_view ();
2031
2032 my $countryhash = $cmap->{countryhash};
2033 my $ctr = $cmap->{country};
2034
2035 my $vbox2 = Gtk3::VBox->new (0, 0);
2036 $inbox->pack_start ($vbox2, 1, 0, 0);
2037 my $vbox = Gtk3::VBox->new (0, 0);
2038 $vbox2->pack_start ($vbox, 0, 0, 10);
2039
2040 my $w = Gtk3::Entry->new ();
2041 $w->set_size_request (200, -1);
2042
2043 my $c = Gtk3::EntryCompletion->new ();
2044 $c->set_text_column (0);
2045 $c->set_minimum_key_length(0);
2046 $c->set_popup_set_width (1);
2047 $c->set_inline_completion (1);
2048
2049 my $hbox2 = Gtk3::HBox->new (0, 0);
2050 my $label = Gtk3::Label->new ("Time zone");
2051 $label->set_size_request (150, -1);
2052 $label->set_alignment (1, 0.5);
2053 $hbox2->pack_start ($label, 0, 0, 10);
2054 update_zonelist ($hbox2);
2055
2056 my $hbox3 = Gtk3::HBox->new (0, 0);
2057 $label = Gtk3::Label->new ("Keyboard Layout");
2058 $label->set_size_request (150, -1);
2059 $label->set_alignment (1, 0.5);
2060 $hbox3->pack_start ($label, 0, 0, 10);
2061
2062 my $kmapcb = Gtk3::ComboBoxText->new();
2063 $kmapcb->set_size_request (200, -1);
2064 foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
2065 $kmapcb->append_text ($layout);
2066 }
2067
2068 update_layout ($kmapcb);
2069 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2070
2071 $kmapcb->signal_connect ('changed' => sub {
2072 my $sel = $kmapcb->get_active_text();
2073 if (my $kmap = $cmap->{kmaphash}->{$sel}) {
2074 my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
2075 my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
2076 syscmd ("setxkbmap $xkmap $xvar") if !$opt_testmode;
2077 $keymap = $kmap;
2078 }
2079 });
2080
2081 $w->signal_connect ('changed' => sub {
2082 my ($entry, $event) = @_;
2083 my $text = $entry->get_text;
2084
2085 if (my $cc = $countryhash->{lc($text)}) {
2086 update_zonelist ($hbox2, $cc);
2087 my $kmap = $ctr->{$cc}->{kmap} || 'en-us';
2088 update_layout ($kmapcb, $kmap);
2089 }
2090 });
2091
2092 $w->signal_connect (key_press_event => sub {
2093 my ($entry, $event) = @_;
2094 my $text = $entry->get_text;
2095
2096 my $val = $event->get_keyval;
2097
2098 if ($val == Gtk3::Gdk::KEY_Tab) {
2099 my $cc = $countryhash->{lc($text)};
2100
2101 my $found = 0;
2102 my $compl;
2103
2104 if ($cc) {
2105 $found = 1;
2106 $compl = $ctr->{$cc}->{name};
2107 } else {
2108 foreach my $cc (keys %$ctr) {
2109 my $ct = $ctr->{$cc}->{name};
2110 if ($ct =~ m/^\Q$text\E.*$/i) {
2111 $found++;
2112 $compl = $ct;
2113 }
2114 last if $found > 1;
2115 }
2116 }
2117
2118 if ($found == 1) {
2119 $entry->set_text($compl);
2120 $c->complete();
2121 return undef;
2122 } else {
2123 #Gtk3::Gdk::beep();
2124 print chr(7); # beep ?
2125 }
2126
2127 $c->complete();
2128
2129 my $buf = $w->get_buffer();
2130 $buf->insert_text(-1, '', -1); # popup selection
2131
2132 return 1;
2133 }
2134
2135 return undef;
2136 });
2137
2138 my $ls = Gtk3::ListStore->new('Glib::String');
2139 foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) {
2140 my $iter = $ls->append();
2141 $ls->set ($iter, 0, $ctr->{$cc}->{name});
2142 }
2143 $c->set_model ($ls);
2144
2145 $w->set_completion ($c);
2146
2147 my $hbox = Gtk3::HBox->new (0, 0);
2148
2149 $label = Gtk3::Label->new ("Country");
2150 $label->set_alignment (1, 0.5);
2151 $label->set_size_request (150, -1);
2152 $hbox->pack_start ($label, 0, 0, 10);
2153 $hbox->pack_start ($w, 0, 0, 0);
2154
2155 $vbox->pack_start ($hbox, 0, 0, 5);
2156 $vbox->pack_start ($hbox2, 0, 0, 5);
2157 $vbox->pack_start ($hbox3, 0, 0, 5);
2158
2159 if ($country) {
2160 $w->set_text ($ctr->{$country}->{name});
2161 }
2162
2163 $inbox->show_all;
2164
2165 display_html ("country.htm");
2166 set_next (undef, sub {
2167
2168 my $text = $w->get_text;
2169
2170 if (my $cc = $countryhash->{lc($text)}) {
2171 $country = $cc;
2172 create_password_view();
2173 return;
2174 } else {
2175 display_message ("Please select a country first.");
2176 $w->grab_focus();
2177 }
2178 });
2179
2180 $w->grab_focus();
2181 }
2182
2183 my $target_hd_combo;
2184 my $target_hd_label;
2185
2186 my $hdopion_first_setup = 1;
2187
2188 sub create_hdoption_view {
2189
2190 my $dialog = Gtk3::Dialog->new();
2191
2192 $dialog->set_title("Harddisk options");
2193
2194 $dialog->add_button("_OK", 1);
2195
2196 my $contarea = $dialog->get_content_area();
2197
2198 my $hbox2 = Gtk3::Box->new('horizontal', 0);
2199 $contarea->pack_start($hbox2, 1, 1, 10);
2200
2201 my $grid = Gtk3::Grid->new();
2202 $grid->set_column_spacing(10);
2203 $grid->set_row_spacing(10);
2204
2205 $hbox2->pack_start($grid, 1, 0, 10);
2206
2207 my $row = 0;
2208
2209 # Filesystem type
2210
2211 my $label0 = Gtk3::Label->new ("Filesystem");
2212 $label0->set_alignment (1, 0.5);
2213 $grid->attach($label0, 0, $row, 1, 1);
2214
2215 my $fstypecb = Gtk3::ComboBoxText->new();
2216
2217 my $fstype = ['ext3', 'ext4', 'xfs',
2218 'zfs (RAID0)', 'zfs (RAID1)',
2219 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2220 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)',
2221 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'];
2222
2223 my $tcount = 0;
2224 foreach my $tmp (@$fstype) {
2225 $fstypecb->append_text($tmp);
2226 $fstypecb->set_active ($tcount)
2227 if $config_options->{filesys} eq $tmp;
2228 $tcount++;
2229 }
2230
2231 $grid->attach($fstypecb, 1, $row, 1, 1);
2232
2233 $hbox2->show_all();
2234
2235 $row++;
2236
2237 my @disk_label;
2238 my @disk_selector;
2239 for (my $i = 0; $i < 8; $i++) {
2240 $disk_label[$i] = Gtk3::Label->new ("Hardisk $i");
2241 $disk_label[$i]->set_alignment (1, 0.5);
2242 $grid->attach($disk_label[$i], 0, $row, 1, 1);
2243 $disk_selector[$i] = Gtk3::ComboBoxText->new();
2244 $disk_selector[$i]->append_text("-- do not use --");
2245 $disk_selector[$i]->set_active(0);
2246 foreach my $hd (@$hds) {
2247 my ($disk, $devname, $size, $model) = @$hd;
2248 $disk_selector[$i]->append_text(get_device_desc ($devname, $size, $model));
2249 $disk_selector[$i]->{pve_disk_id} = $i;
2250 $disk_selector[$i]->signal_connect (changed => sub {
2251 my $w = shift;
2252 my $diskid = $w->{pve_disk_id};
2253 my $a = $w->get_active - 1;
2254 $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef;
2255 });
2256 }
2257
2258 if ($hdopion_first_setup) {
2259 $disk_selector[$i]->set_active ($i+1) if $hds->[$i];
2260 } else {
2261 my $hdind = 0;
2262 if (my $cur_hd = $config_options->{"disksel$i"}) {
2263 foreach my $hd (@$hds) {
2264 if (@$hd[1] eq @$cur_hd[1]) {
2265 $disk_selector[$i]->set_active($hdind+1);
2266 last;
2267 }
2268 $hdind++;
2269 }
2270
2271 }
2272 }
2273
2274 $grid->attach($disk_selector[$i], 1, $row, 1, 1);
2275
2276 $row++;
2277 }
2278
2279 $hdopion_first_setup = 0;
2280
2281 my $label_hdsize = Gtk3::Label->new ("hdsize");
2282 $label_hdsize->set_alignment (1, 0.5);
2283 $grid->attach($label_hdsize, 0, $row, 1, 1);
2284
2285 # size compute
2286 my $hdsize = 0;
2287 if ( -b $target_hd) {
2288 $hdsize = int(hd_size ($target_hd) / (1024*1024.0)); # size in GB
2289 } elsif ($target_hd) {
2290 $hdsize = int((-s $target_hd) / (1024*1024*1024.0));
2291 }
2292
2293 my $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2294 my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
2295 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2296 $grid->attach($spinbutton_hdsize, 1, $row, 1, 1);
2297 $row++;
2298
2299 my $label_swapsize = Gtk3::Label->new ("swapsize");
2300 $label_swapsize->set_alignment (1, 0.5);
2301 $grid->attach($label_swapsize, 0, $row, 1, 1);
2302
2303 my $entry_swapsize = Gtk3::Entry->new();
2304 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2305 $entry_swapsize->signal_connect (key_press_event => \&check_float);
2306 $entry_swapsize->set_text($config_options->{swapsize}) if $config_options->{swapsize};
2307 $grid->attach($entry_swapsize, 1, $row, 1, 1);
2308 $row++;
2309
2310 my $label_maxroot = Gtk3::Label->new ("maxroot");
2311 $label_maxroot->set_alignment (1, 0.5);
2312 $grid->attach($label_maxroot, 0, $row, 1, 1);
2313
2314 my $entry_maxroot = Gtk3::Entry->new();
2315 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2316 $entry_maxroot->signal_connect (key_press_event => \&check_float);
2317 $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot};
2318 $grid->attach($entry_maxroot, 1, $row, 1, 1);
2319 $row++;
2320
2321 my $label_minfree = Gtk3::Label->new ("minfree");
2322 $label_minfree->set_alignment (1, 0.5);
2323 $grid->attach($label_minfree, 0, $row, 1, 1);
2324
2325 my $entry_minfree = Gtk3::Entry->new();
2326 $entry_minfree->set_tooltip_text("minumum free LVM space (GB, required for LVM snapshots)");
2327 $entry_minfree->signal_connect (key_press_event => \&check_float);
2328 $entry_minfree->set_text($config_options->{minfree}) if $config_options->{minfree};
2329 $grid->attach($entry_minfree, 1, $row, 1, 1);
2330 $row++;
2331
2332 my $label_maxvz = Gtk3::Label->new ("maxvz");
2333 $label_maxvz->set_alignment (1, 0.5);
2334 $grid->attach($label_maxvz, 0, $row, 1, 1);
2335
2336 my $entry_maxvz = Gtk3::Entry->new();
2337 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2338 $entry_maxvz->signal_connect (key_press_event => \&check_float);
2339 $entry_maxvz->set_text($config_options->{maxvz}) if $config_options->{maxvz};
2340 $grid->attach($entry_maxvz, 1, $row, 1, 1);
2341 $row++;
2342
2343 my $set_sensitive_flag = sub {
2344 my $enable_size_hints = $config_options->{filesys} !~ m/zfs|btrfs/;
2345
2346 if ($config_options->{filesys} =~ m/zfs|btrfs/) {
2347 $target_hd_combo->set_visible(0);
2348 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2349 foreach my $w (@disk_selector) { $w->set_visible(1); }
2350 foreach my $w (@disk_label) { $w->set_visible(1); }
2351 } else {
2352 $target_hd_combo->set_visible(1);
2353 foreach my $w (@disk_selector) { $w->set_visible(0); }
2354 foreach my $w (@disk_label) { $w->set_visible(0); }
2355 $target_hd_label->set_text("Target Harddisk: ");
2356 }
2357
2358 $spinbutton_hdsize->set_visible($enable_size_hints);
2359 $label_hdsize->set_visible($enable_size_hints);
2360 $entry_swapsize->set_visible($enable_size_hints);
2361 $label_swapsize->set_visible($enable_size_hints);
2362 $entry_maxroot->set_visible($enable_size_hints);
2363 $label_maxroot->set_visible($enable_size_hints);
2364 $entry_minfree->set_visible($enable_size_hints);
2365 $label_minfree->set_visible($enable_size_hints);
2366 $entry_maxvz->set_visible($enable_size_hints);
2367 $label_maxvz->set_visible($enable_size_hints);
2368 };
2369
2370 &$set_sensitive_flag();
2371
2372 $fstypecb->signal_connect (changed => sub {
2373 $config_options->{filesys} = $fstypecb->get_active_text();
2374 &$set_sensitive_flag();
2375 });
2376
2377 $dialog->show();
2378
2379 $dialog->run();
2380
2381 my $get_float = sub {
2382 my ($entry) = @_;
2383
2384 my $text = $entry->get_text();
2385 return undef if !defined($text);
2386
2387 $text =~ s/^\s+//;
2388 $text =~ s/\s+$//;
2389
2390 return undef if $text !~ m/^\d+(\.\d+)?$/;
2391
2392 return $text;
2393 };
2394
2395 my $tmp;
2396
2397 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2398 $config_options->{hdsize} = $tmp;
2399 } else {
2400 delete $config_options->{hdsize};
2401 }
2402
2403 if (defined($tmp = &$get_float($entry_swapsize))) {
2404 $config_options->{swapsize} = $tmp;
2405 } else {
2406 delete $config_options->{swapsize};
2407 }
2408
2409 if (defined($tmp = &$get_float($entry_maxroot))) {
2410 $config_options->{maxroot} = $tmp;
2411 } else {
2412 delete $config_options->{maxroot};
2413 }
2414
2415 if (defined($tmp = &$get_float($entry_minfree))) {
2416 $config_options->{minfree} = $tmp;
2417 } else {
2418 delete $config_options->{minfree};
2419 }
2420
2421 if (defined($tmp = &$get_float($entry_maxvz))) {
2422 $config_options->{maxvz} = $tmp;
2423 } else {
2424 delete $config_options->{maxvz};
2425 }
2426
2427 $dialog->destroy();
2428 }
2429
2430 my $get_raid_devlist = sub {
2431
2432 my $dev_name_hash = {};
2433
2434 my $devlist = [];
2435 for (my $i = 0; $i < 8; $i++) {
2436 if (my $hd = $config_options->{"disksel$i"}) {
2437 my ($disk, $devname, $size, $model) = @$hd;
2438 die "device '$devname' is used more than once\n"
2439 if $dev_name_hash->{$devname};
2440 $dev_name_hash->{$devname} = $hd;
2441 push @$devlist, $hd;
2442 }
2443 }
2444
2445 return $devlist;
2446 };
2447
2448 sub get_zfs_raid_setup {
2449
2450 my $filesys = $config_options->{filesys};
2451
2452 my $devlist = &$get_raid_devlist();
2453
2454 my $diskcount = scalar(@$devlist);
2455 die "$filesys need at least one device\n" if $diskcount < 1;
2456
2457 my $bootdevlist = [];
2458
2459 my $cmd= '';
2460 if ($filesys eq 'zfs (RAID0)') {
2461 push @$bootdevlist, @$devlist[0];
2462 foreach my $hd (@$devlist) {
2463 $cmd .= " @$hd[1]";
2464 }
2465 } elsif ($filesys eq 'zfs (RAID1)') {
2466 die "zfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2467 $cmd .= ' mirror ';
2468 my $hd = @$devlist[0];
2469 my $expected_size = @$hd[2]; # all disks needs same size
2470 foreach $hd (@$devlist) {
2471 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2472 $cmd .= " @$hd[1]";
2473 push @$bootdevlist, $hd;
2474 }
2475 } elsif ($filesys eq 'zfs (RAID10)') {
2476 my $half = int($diskcount/2);
2477 die "zfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2478 die "zfs (RAID10) need at an even numver of devices\n" if $half*2 != $diskcount;
2479
2480 push @$bootdevlist, @$devlist[0], @$devlist[1];
2481
2482 for (my $i = 0; $i < $diskcount; $i+=2) {
2483 my $hd1 = @$devlist[$i];
2484 my $hd2 = @$devlist[$i+1];
2485 die "mirrored disks must have same size\n" if @$hd1[2] != @$hd2[2];
2486 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
2487 }
2488
2489 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
2490 my $level = $1;
2491 my $mindisks = 2 + $level;
2492 die "zfs (RAIDZ-$level) need at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
2493 my $hd = @$devlist[0];
2494 my $expected_size = @$hd[2]; # all disks needs same size
2495 $cmd .= " raidz$level";
2496 foreach $hd (@$devlist) {
2497 die "mirrored disks must have same size\n" if @$hd[2] != $expected_size;
2498 $cmd .= " @$hd[1]";
2499 push @$bootdevlist, $hd;
2500 }
2501 } else {
2502 die "unknown zfs mode '$filesys'\n";
2503 }
2504
2505 return ($devlist, $bootdevlist, $cmd);
2506 }
2507
2508 sub get_btrfs_raid_setup {
2509
2510 my $filesys = $config_options->{filesys};
2511
2512 my $devlist = &$get_raid_devlist();
2513
2514 my $diskcount = scalar(@$devlist);
2515 die "$filesys need at least one device\n" if $diskcount < 1;
2516
2517 my $mode;
2518
2519 if ($diskcount == 1) {
2520 $mode = 'single';
2521 } else {
2522 if ($filesys eq 'btrfs (RAID0)') {
2523 $mode = 'raid0';
2524 } elsif ($filesys eq 'btrfs (RAID1)') {
2525 die "btrfs (RAID1) need at least 2 device\n" if $diskcount < 2;
2526 $mode = 'raid1';
2527 } elsif ($filesys eq 'btrfs (RAID10)') {
2528 die "btrfs (RAID10) need at least 4 device\n" if $diskcount < 4;
2529 $mode = 'raid10';
2530 } else {
2531 die "unknown zfs mode '$filesys'\n";
2532 }
2533 }
2534
2535 return ($devlist, $mode);
2536 }
2537
2538 sub create_hdsel_view {
2539
2540 cleanup_view ();
2541
2542 my $vbox = Gtk3::VBox->new (0, 0);
2543 $inbox->pack_start ($vbox, 1, 0, 0);
2544 my $hbox = Gtk3::HBox->new (0, 0);
2545 $vbox->pack_start ($hbox, 0, 0, 10);
2546
2547 my ($disk, $devname, $size, $model) = @{@$hds[0]};
2548 $target_hd = $devname;
2549
2550 $target_hd_label = Gtk3::Label->new ("Target Harddisk: ");
2551 $hbox->pack_start ($target_hd_label, 0, 0, 0);
2552
2553 $target_hd_combo = Gtk3::ComboBoxText->new();
2554
2555 foreach my $hd (@$hds) {
2556 ($disk, $devname, $size, $model) = @$hd;
2557 $target_hd_combo->append_text (get_device_desc ($devname, $size, $model));
2558 }
2559
2560 $target_hd_combo->set_active (0);
2561 $target_hd_combo->signal_connect (changed => sub {
2562 $a = shift->get_active;
2563 my ($disk, $devname) = @{@$hds[$a]};
2564 $target_hd = $devname;
2565 });
2566
2567 $hbox->pack_start ($target_hd_combo, 0, 0, 10);
2568
2569 my $options = Gtk3::Button->new ('_Options');
2570 $options->signal_connect (clicked => \&create_hdoption_view);
2571 $hbox->pack_start ($options, 0, 0, 0);
2572
2573
2574 $inbox->show_all;
2575
2576 display_html ("page1.htm");
2577
2578 set_next (undef, sub {
2579
2580 if ($config_options->{filesys} =~ m/zfs/) {
2581 eval { get_zfs_raid_setup(); };
2582 if (my $err = $@) {
2583 display_message ("Warning: $err\n" .
2584 "Please fix ZFS setup first.");
2585 } else {
2586 create_country_view();
2587 }
2588 } elsif ($config_options->{filesys} =~ m/btrfs/) {
2589 eval { get_btrfs_raid_setup(); };
2590 if (my $err = $@) {
2591 display_message ("Warning: $err\n" .
2592 "Please fix BTRFS setup first.");
2593 } else {
2594 create_country_view();
2595 }
2596 } else {
2597 create_country_view();
2598 }
2599 });
2600 }
2601
2602 sub create_extract_view {
2603
2604 cleanup_view ();
2605
2606 display_html ("extract1-license.htm");
2607 $next->set_sensitive (0);
2608
2609 my $vbox = Gtk3::VBox->new (0, 0);
2610 $inbox->pack_start ($vbox, 1, 0, 0);
2611 my $hbox = Gtk3::HBox->new (0, 0);
2612 $vbox->pack_start ($hbox, 0, 0, 10);
2613
2614 my $vbox2 = Gtk3::VBox->new (0, 0);
2615 $hbox->pack_start ($vbox2, 0, 0, 0);
2616
2617 $progress_status = Gtk3::Label->new ('');
2618 $vbox2->pack_start ($progress_status, 1, 1, 0);
2619
2620 $progress = Gtk3::ProgressBar->new;
2621 $progress->set_show_text(1);
2622 $progress->set_size_request (600, -1);
2623
2624 $vbox2->pack_start ($progress, 0, 0, 0);
2625
2626 $inbox->show_all;
2627
2628 my $tdir = $opt_testmode ? "target" : "/target";
2629 mkdir $tdir;
2630 my $base = $opt_testmode ? "/pve/$release/install/pve-base.tar" : "/proxmox/pve-base.tar";
2631
2632 eval { extract_data ($base, $tdir); };
2633 my $err = $@;
2634
2635 $next->set_sensitive (1);
2636
2637 set_next ("_Reboot", sub { exit (0); } );
2638
2639 if ($err) {
2640 display_html ("fail.htm");
2641 display_error ($err);
2642 } else {
2643 cleanup_view ();
2644 display_html ("success.htm");
2645 }
2646 }
2647
2648 sub create_intro_view {
2649
2650 cleanup_view ();
2651
2652 display_html ("license.htm");
2653
2654 set_next ("I a_gree", \&create_hdsel_view);
2655 }
2656
2657 $ipconf = get_ip_config ();
2658
2659 $country = detect_country() if $ipconf->{addr} || $opt_testmode;;
2660
2661 # read country, kmap and timezone infos
2662 $cmap = read_cmap ();
2663
2664 create_main_window ();
2665
2666 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
2667 print "no hardisks found\n";
2668 display_html ("nohds.htm");
2669 set_next ("Reboot", sub { exit (0); } );
2670 } else {
2671
2672 foreach my $hd (@$hds) {
2673 my ($disk, $devname) = @$hd;
2674 next if $devname =~ m|^/dev/md\d+$|;
2675 print "found Disk$disk N:$devname\n";
2676 }
2677
2678 create_intro_view ();
2679 }
2680
2681 Gtk3->main;
2682
2683 exit 0;