]> git.proxmox.com Git - pve-installer.git/blob - proxinstall
also umount efivars and minor improvements
[pve-installer.git] / proxinstall
1 #!/usr/bin/perl
2
3 $ENV{DEBIAN_FRONTEND} = 'noninteractive';
4 $ENV{LC_ALL} = 'C';
5
6 use strict;
7 use warnings;
8
9 use Getopt::Long;
10 use IPC::Open2;
11 use IPC::Open3;
12 use IO::File;
13 use IO::Select;
14 use Cwd 'abs_path';
15 use Gtk3 '-init';
16 use Gtk3::WebKit2;
17 use Encode;
18 use String::ShellQuote;
19 use Data::Dumper;
20 use File::Basename;
21 use File::Path;
22 use Time::HiRes;
23
24 use ProxmoxInstallerSetup;
25
26 my $setup = ProxmoxInstallerSetup::setup();
27
28 my $opt_testmode;
29
30 if (!$ENV{G_SLICE} || $ENV{G_SLICE} ne "always-malloc") {
31 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
32 }
33
34 if (!GetOptions('testmode=s' => \$opt_testmode)) {
35 die "usage error\n";
36 exit (-1);
37 }
38
39 my $zfstestpool = "test_rpool";
40 my $zfspoolname = $opt_testmode ? $zfstestpool : 'rpool';
41 my $zfsrootvolname = "$setup->{product}-1";
42
43 my $product_fullname = {
44 pve => 'Proxmox VE',
45 pmg => 'Proxmox MailGateway',
46 };
47
48 my $storage_cfg_zfs = <<__EOD__;
49 dir: local
50 path /var/lib/vz
51 content iso,vztmpl,backup
52
53 zfspool: local-zfs
54 pool $zfspoolname/data
55 sparse
56 content images,rootdir
57 __EOD__
58
59 my $storage_cfg_btrfs = <<__EOD__;
60 dir: local
61 path /var/lib/vz
62 content iso,vztmpl,backup
63 disabled
64
65 btrfs: local-btrfs
66 path /var/lib/pve/local-btrfs
67 content iso,vztmpl,backup,images,rootdir
68 __EOD__
69
70 my $storage_cfg_lvmthin = <<__EOD__;
71 dir: local
72 path /var/lib/vz
73 content iso,vztmpl,backup
74
75 lvmthin: local-lvm
76 thinpool data
77 vgname pve
78 content rootdir,images
79 __EOD__
80
81 my $storage_cfg_local = <<__EOD__;
82 dir: local
83 path /var/lib/vz
84 content iso,vztmpl,backup,rootdir,images
85 __EOD__
86
87 sub file_read_firstline {
88 my ($filename) = @_;
89
90 my $fh = IO::File->new ($filename, "r");
91 return undef if !$fh;
92 my $res = <$fh>;
93 chomp $res if $res;
94 $fh->close;
95 return $res;
96 }
97
98 my $logfd = IO::File->new(">/tmp/install.log");
99
100 my $proxmox_libdir = $opt_testmode ?
101 Cwd::cwd() . "/testdir/var/lib/pve-installer" : "/var/lib/pve-installer";
102 my $proxmox_cddir = $opt_testmode ? "../pve-cd-builder/tmp/data-gz/" : "/cdrom";
103 my $proxmox_pkgdir = "${proxmox_cddir}/proxmox/packages/";
104
105 my $boot_type = -d '/sys/firmware/efi' ? 'efi' : 'bios';
106
107 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
108 my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
109 my $IPV6H16 = "(?:[0-9a-fA-F]{1,4})";
110 my $IPV6LS32 = "(?:(?:$IPV4RE|$IPV6H16:$IPV6H16))";
111
112 my $IPV6RE = "(?:" .
113 "(?:(?:" . "(?:$IPV6H16:){6})$IPV6LS32)|" .
114 "(?:(?:" . "::(?:$IPV6H16:){5})$IPV6LS32)|" .
115 "(?:(?:(?:" . "$IPV6H16)?::(?:$IPV6H16:){4})$IPV6LS32)|" .
116 "(?:(?:(?:(?:$IPV6H16:){0,1}$IPV6H16)?::(?:$IPV6H16:){3})$IPV6LS32)|" .
117 "(?:(?:(?:(?:$IPV6H16:){0,2}$IPV6H16)?::(?:$IPV6H16:){2})$IPV6LS32)|" .
118 "(?:(?:(?:(?:$IPV6H16:){0,3}$IPV6H16)?::(?:$IPV6H16:){1})$IPV6LS32)|" .
119 "(?:(?:(?:(?:$IPV6H16:){0,4}$IPV6H16)?::" . ")$IPV6LS32)|" .
120 "(?:(?:(?:(?:$IPV6H16:){0,5}$IPV6H16)?::" . ")$IPV6H16)|" .
121 "(?:(?:(?:(?:$IPV6H16:){0,6}$IPV6H16)?::" . ")))";
122
123 my $IPRE = "(?:$IPV4RE|$IPV6RE)";
124
125
126 my $ipv4_mask_hash = {
127 '128.0.0.0' => 1,
128 '192.0.0.0' => 2,
129 '224.0.0.0' => 3,
130 '240.0.0.0' => 4,
131 '248.0.0.0' => 5,
132 '252.0.0.0' => 6,
133 '254.0.0.0' => 7,
134 '255.0.0.0' => 8,
135 '255.128.0.0' => 9,
136 '255.192.0.0' => 10,
137 '255.224.0.0' => 11,
138 '255.240.0.0' => 12,
139 '255.248.0.0' => 13,
140 '255.252.0.0' => 14,
141 '255.254.0.0' => 15,
142 '255.255.0.0' => 16,
143 '255.255.128.0' => 17,
144 '255.255.192.0' => 18,
145 '255.255.224.0' => 19,
146 '255.255.240.0' => 20,
147 '255.255.248.0' => 21,
148 '255.255.252.0' => 22,
149 '255.255.254.0' => 23,
150 '255.255.255.0' => 24,
151 '255.255.255.128' => 25,
152 '255.255.255.192' => 26,
153 '255.255.255.224' => 27,
154 '255.255.255.240' => 28,
155 '255.255.255.248' => 29,
156 '255.255.255.252' => 30,
157 '255.255.255.254' => 31,
158 '255.255.255.255' => 32
159 };
160
161 my $ipv4_reverse_mask = [
162 '0.0.0.0',
163 '128.0.0.0',
164 '192.0.0.0',
165 '224.0.0.0',
166 '240.0.0.0',
167 '248.0.0.0',
168 '252.0.0.0',
169 '254.0.0.0',
170 '255.0.0.0',
171 '255.128.0.0',
172 '255.192.0.0',
173 '255.224.0.0',
174 '255.240.0.0',
175 '255.248.0.0',
176 '255.252.0.0',
177 '255.254.0.0',
178 '255.255.0.0',
179 '255.255.128.0',
180 '255.255.192.0',
181 '255.255.224.0',
182 '255.255.240.0',
183 '255.255.248.0',
184 '255.255.252.0',
185 '255.255.254.0',
186 '255.255.255.0',
187 '255.255.255.128',
188 '255.255.255.192',
189 '255.255.255.224',
190 '255.255.255.240',
191 '255.255.255.248',
192 '255.255.255.252',
193 '255.255.255.254',
194 '255.255.255.255',
195 ];
196
197 my $step_number = 0; # Init number for global function list
198
199 my @steps = (
200 {
201 step => 'intro',
202 html => 'license.htm',
203 next_button => 'I a_gree',
204 function => \&create_intro_view,
205 },
206 {
207 step => 'intro',
208 html => 'page1.htm',
209 function => \&create_hdsel_view,
210 },
211 {
212 step => 'country',
213 html => 'country.htm',
214 function => \&create_country_view,
215 },
216 {
217 step => 'password',
218 html => 'passwd.htm',
219 function => \&create_password_view,
220 },
221 {
222 step => 'ipconf',
223 html => 'ipconf.htm',
224 function => \&create_ipconf_view,
225 },
226 {
227 step => 'ack',
228 html => 'ack.htm',
229 next_button => '_Install',
230 function => \&create_ack_view,
231 },
232 {
233 step => 'extract',
234 next_button => '_Reboot',
235 function => \&create_extract_view,
236 },
237 );
238
239 # GUI global variables
240 my ($window, $cmdbox, $inbox, $htmlview);
241 my $prev_btn;
242 my ($next, $next_fctn, $target_hd);
243 my ($progress, $progress_status);
244
245 my ($ipversion, $ipaddress, $ipconf_entry_addr);
246 my ($netmask, $ipconf_entry_mask);
247 my ($gateway, $ipconf_entry_gw);
248 my ($dnsserver, $ipconf_entry_dns);
249 my $hostname = 'proxmox';
250 my $domain = 'domain.tld';
251 my $cmdline = file_read_firstline("/proc/cmdline");
252 my $ipconf;
253 my $country;
254 my $timezone = 'Europe/Vienna';
255 my $keymap = 'en-us';
256 my $password;
257 my $mailto = 'mail@example.invalid';
258 my $cmap;
259
260 my $config = {
261 # TODO: add all the user-provided options for previous button
262 country => $country,
263 timezone => $timezone,
264 keymap => $keymap,
265
266 password => $password,
267 mailto => $mailto,
268
269 mngmt_nic => undef,
270 hostname => $hostname,
271 fqdn => undef,
272 ipaddress => undef,
273 netmask => undef,
274 gateway => undef,
275 };
276
277 # parse command line args
278
279 my $config_options = {};
280
281 if ($cmdline =~ m/\s(ext3|ext4|xfs)(\s.*)?$/) {
282 $config_options->{filesys} = $1;
283 } else {
284 $config_options->{filesys} = 'ext4';
285 }
286
287 if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) {
288 $config_options->{hdsize} = $1;
289 }
290
291 if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) {
292 $config_options->{swapsize} = $1;
293 }
294
295 if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) {
296 $config_options->{maxroot} = $1;
297 }
298
299 if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) {
300 $config_options->{minfree} = $1;
301 }
302
303 if ($setup->{product} eq 'pve') {
304 if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) {
305 $config_options->{maxvz} = $1;
306 }
307 }
308
309 my $postfix_main_cf = <<_EOD;
310 # See /usr/share/postfix/main.cf.dist for a commented, more complete version
311
312 myhostname=__FQDN__
313
314 smtpd_banner = \$myhostname ESMTP \$mail_name (Debian/GNU)
315 biff = no
316
317 # appending .domain is the MUA's job.
318 append_dot_mydomain = no
319
320 # Uncomment the next line to generate "delayed mail" warnings
321 #delay_warning_time = 4h
322
323 alias_maps = hash:/etc/aliases
324 alias_database = hash:/etc/aliases
325 mydestination = \$myhostname, localhost.\$mydomain, localhost
326 relayhost =
327 mynetworks = 127.0.0.0/8
328 inet_interfaces = loopback-only
329 recipient_delimiter = +
330
331 _EOD
332
333 sub shellquote {
334 my $str = shift;
335
336 return String::ShellQuote::shell_quote($str);
337 }
338
339 sub cmd2string {
340 my ($cmd) = @_;
341
342 die "no arguments" if !$cmd;
343
344 return $cmd if !ref($cmd);
345
346 my @qa = ();
347 foreach my $arg (@$cmd) { push @qa, shellquote($arg); }
348
349 return join (' ', @qa);
350 }
351
352 sub syscmd {
353 my ($cmd) = @_;
354
355 return run_command($cmd, undef, undef, 1);
356 }
357
358 sub run_command {
359 my ($cmd, $func, $input, $noout) = @_;
360
361 my $cmdstr;
362 if (!ref($cmd)) {
363 $cmdstr = $cmd;
364 if ($cmd =~ m/|/) {
365 # see 'man bash' for option pipefail
366 $cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
367 } else {
368 $cmd = [ $cmd ];
369 }
370 } else {
371 $cmdstr = cmd2string($cmd);
372 }
373
374 my $cmdtxt;
375 if ($input && ($cmdstr !~ m/chpasswd/)) {
376 $cmdtxt = "# $cmdstr <<EOD\n$input";
377 chomp $cmdtxt;
378 $cmdtxt .= "\nEOD\n";
379 } else {
380 $cmdtxt = "# $cmdstr\n";
381 }
382
383 if ($opt_testmode) {
384 print $cmdtxt;
385 STDOUT->flush();
386 }
387
388 print $logfd $cmdtxt;
389
390 my $reader = IO::File->new();
391 my $writer = IO::File->new();
392 my $error = IO::File->new();
393
394 my $orig_pid = $$;
395
396 my $pid;
397 eval {
398 $pid = open3($writer, $reader, $error, @$cmd) || die $!;
399 };
400
401 my $err = $@;
402
403 # catch exec errors
404 if ($orig_pid != $$) {
405 POSIX::_exit (1);
406 kill ('KILL', $$);
407 }
408
409 die $err if $err;
410
411 print $writer $input if defined $input;
412 close $writer;
413
414 my $select = new IO::Select;
415 $select->add($reader);
416 $select->add($error);
417
418 my ($ostream, $logout) = ('', '', '');
419
420 while ($select->count) {
421 my @handles = $select->can_read (0.2);
422
423 Gtk3::main_iteration() while Gtk3::events_pending();
424
425 next if !scalar (@handles); # timeout
426
427 foreach my $h (@handles) {
428 my $buf = '';
429 my $count = sysread ($h, $buf, 4096);
430 if (!defined ($count)) {
431 my $err = $!;
432 kill (9, $pid);
433 waitpid ($pid, 0);
434 die "command '$cmd' failed: $err";
435 }
436 $select->remove($h) if !$count;
437 if ($h eq $reader) {
438 $ostream .= $buf if !($noout || $func);
439 $logout .= $buf;
440 while ($logout =~ s/^([^\010\r\n]*)(\r|\n|(\010)+|\r\n)//s) {
441 my $line = $1;
442 &$func($line) if $func;
443 }
444
445 } elsif ($h eq $error) {
446 $ostream .= $buf if !($noout || $func);
447 }
448 print $buf;
449 STDOUT->flush();
450 print $logfd $buf;
451 }
452 }
453
454 &$func($logout) if $func;
455
456 my $rv = waitpid ($pid, 0);
457
458 return $? if $noout; # behave like standard system();
459
460 if ($? == -1) {
461 die "command '$cmdstr' failed to execute\n";
462 } elsif (my $sig = ($? & 127)) {
463 die "command '$cmdstr' failed - got signal $sig\n";
464 } elsif (my $exitcode = ($? >> 8)) {
465 die "command '$cmdstr' failed with exit code $exitcode";
466 }
467
468 return $ostream;
469 }
470
471 sub detect_country {
472
473 print "trying to detect country...\n";
474 my $cpid = open2(\*TMP, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
475 return undef if !$cpid;
476
477 my $country;
478
479 my $previous_alarm = alarm (10);
480 eval {
481 local $SIG{ALRM} = sub { die "timed out!\n" };
482 my $line;
483 while (defined ($line = <TMP>)) {
484 print $logfd "DC TRACEROUTE: $line";
485 if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
486 my $geoip = `geoiplookup $1`;
487 print $logfd "DC GEOIP: $geoip";
488 if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
489 $country = lc ($1);
490 print $logfd "DC FOUND: $country\n";
491 last;
492 }
493 }
494 }
495 };
496
497 my $err = $@;
498
499 alarm ($previous_alarm);
500
501 close (TMP);
502
503 if ($err) {
504 print "unable to detect country - $err\n";
505 } elsif ($country) {
506 print "detected country: " . uc($country) . "\n";
507 } else {
508 print "unable to detect country\n";
509 }
510
511 return $country;
512 }
513
514 sub get_memtotal {
515
516 open (MEMINFO, "/proc/meminfo");
517
518 my $res = 512; # default to 512 if something goes wrong
519 while (my $line = <MEMINFO>) {
520 if ($line =~ m/^MemTotal:\s+(\d+)\s*kB/i) {
521 $res = int ($1 / 1024);
522 }
523 }
524
525 close (MEMINFO);
526
527 return $res;
528 }
529
530 my $total_memory = get_memtotal();
531
532 sub link_points_to {
533 my ($src, $dest) = @_;
534
535 my ($dev1,$ino1) = stat ($src);
536 my ($dev2,$ino2) = stat ($dest);
537
538 return 0 if !($dev1 && $dev2 && $ino1 && $ino2);
539
540 return $ino1 == $ino2 && $dev1 == $dev2;
541 }
542
543 sub find_stable_path {
544 my ($stabledir, $bdev) = @_;
545
546 foreach my $path (<$stabledir/*>) {
547 if (link_points_to($path, $bdev)) {
548 return wantarray ? ($path, basename($path)) : $path;
549 }
550 }
551 }
552
553 sub find_dev_by_uuid {
554 my $bdev = shift;
555
556 my ($full_path, $name) = find_stable_path("/dev/disk/by-uuid", $bdev);
557
558 return $name;
559 }
560
561 sub hd_list {
562
563 my $res = ();
564
565 if ($opt_testmode) {
566 my @disks = split /,/, $opt_testmode;
567
568 for my $disk (@disks) {
569 push @$res, [-1, $disk, int((-s $disk)/512), "TESTDISK"];
570 }
571 return $res;
572 }
573
574 my $count = 0;
575
576 foreach my $bd (</sys/block/*>) {
577 next if $bd =~ m|^/sys/block/ram\d+$|;
578 next if $bd =~ m|^/sys/block/loop\d+$|;
579 next if $bd =~ m|^/sys/block/md\d+$|;
580 next if $bd =~ m|^/sys/block/dm-.*$|;
581 next if $bd =~ m|^/sys/block/fd\d+$|;
582 next if $bd =~ m|^/sys/block/sr\d+$|;
583
584 my $dev = file_read_firstline("$bd/dev");
585 chomp $dev;
586
587 next if !$dev;
588
589 my $info = `udevadm info --path $bd --query all`;
590 next if !$info;
591
592 next if $info !~ m/^E: DEVTYPE=disk$/m;
593
594 next if $info =~ m/^E: ID_CDROM/m;
595 next if $info =~ m/^E: ID_FS_TYPE=iso9660/m;
596
597 my ($name) = $info =~ m/^N: (\S+)$/m;
598
599 if ($name) {
600 my $real_name = "/dev/$name";
601
602 my $size = file_read_firstline("$bd/size");
603 chomp $size;
604 $size = undef if !($size && $size =~ m/^\d+$/);
605
606 my $model = file_read_firstline("$bd/device/model") || '';
607 $model =~ s/^\s+//;
608 $model =~ s/\s+$//;
609 if (length ($model) > 30) {
610 $model = substr ($model, 0, 30);
611 }
612 push @$res, [$count++, $real_name, $size, $model] if $size;
613 } else {
614 print STDERR "ERROR: unable to map device $dev ($bd)\n";
615 }
616 }
617
618 return $res;
619 }
620
621 sub read_cmap {
622 my $countryfn = "${proxmox_libdir}/country.dat";
623 open (TMP, "<$countryfn") || die "unable to open '$countryfn' - $!\n";
624 my $line;
625 my $country = {};
626 my $countryhash = {};
627 my $kmap = {};
628 my $kmaphash = {};
629 while (defined ($line = <TMP>)) {
630 if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) {
631 $kmap->{$1} = {
632 name => $2,
633 kvm => $3,
634 console => $4,
635 x11 => $5,
636 x11var => $6,
637 };
638 $kmaphash->{$2} = $1;
639 } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) {
640 $country->{$1} = {
641 name => $2,
642 kmap => $3,
643 mirror => $4,
644 };
645 $countryhash->{lc($2)} = $1;
646 } else {
647 warn "unable to parse 'country.dat' line: $line";
648 }
649 }
650 close (TMP);
651
652 my $zones = {};
653 my $cczones = {};
654 my $zonefn = "/usr/share/zoneinfo/zone.tab";
655 open (TMP, "<$zonefn") || die "unable to open '$zonefn' - $!\n";
656 while (defined ($line = <TMP>)) {
657 next if $line =~ m/^\#/;
658 next if $line =~ m/^\s*$/;
659 if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) {
660 my $cc = lc($1);
661 $cczones->{$cc}->{$2} = 1;
662 $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone});
663 $zones->{$2} = 1;
664
665 }
666 }
667 close (TMP);
668
669 return {
670 zones => $zones,
671 cczones => $cczones,
672 country => $country,
673 countryhash => $countryhash,
674 kmap => $kmap,
675 kmaphash => $kmaphash,
676 }
677 }
678
679 # search for Harddisks
680 my $hds = hd_list();
681
682 sub hd_size {
683 my ($dev) = @_;
684
685 foreach my $hd (@$hds) {
686 my ($disk, $devname, $size, $model) = @$hd;
687 # size is always in 512B "sectors"! convert to KB
688 return int($size/2) if $devname eq $dev;
689 }
690
691 die "no such device '$dev'\n";
692 }
693
694 sub get_partition_dev {
695 my ($dev, $partnum) = @_;
696
697 if ($dev =~ m|^/dev/sd([a-h]?[a-z]\|i[a-v])$|) {
698 return "${dev}$partnum";
699 } elsif ($dev =~ m|^/dev/xvd[a-z]$|) {
700 # Citrix Hypervisor blockdev
701 return "${dev}$partnum";
702 } elsif ($dev =~ m|^/dev/[hxev]d[a-z]$|) {
703 return "${dev}$partnum";
704 } elsif ($dev =~ m|^/dev/[^/]+/c\d+d\d+$|) {
705 return "${dev}p$partnum";
706 } elsif ($dev =~ m|^/dev/[^/]+/d\d+$|) {
707 return "${dev}p$partnum";
708 } elsif ($dev =~ m|^/dev/[^/]+/hd[a-z]$|) {
709 return "${dev}$partnum";
710 } elsif ($dev =~ m|^/dev/nvme\d+n\d+$|) {
711 return "${dev}p$partnum";
712 } else {
713 die "unable to get device for partition $partnum on device $dev\n";
714 }
715
716 }
717
718 sub file_get_contents {
719 my ($filename, $max) = @_;
720
721 my $fh = IO::File->new($filename, "r") ||
722 die "can't open '$filename' - $!\n";
723
724 local $/; # slurp mode
725
726 my $content = <$fh>;
727
728 close $fh;
729
730 return $content;
731 }
732
733 sub write_config {
734 my ($text, $filename) = @_;
735
736 my $fd = IO::File->new(">$filename") ||
737 die "unable to open file '$filename' - $!\n";
738 print $fd $text;
739 $fd->close();
740 }
741
742 sub update_progress {
743 my ($frac, $start, $end, $text) = @_;
744
745 my $part = $end - $start;
746 my $res = $start + $frac*$part;
747
748 $progress->set_fraction ($res);
749 $progress->set_text (sprintf ("%d%%", int ($res*100)));
750 $progress_status->set_text ($text) if defined ($text);
751
752 display_info() if $res < 0.9;
753
754 Gtk3::main_iteration() while Gtk3::events_pending();
755 }
756
757 my $fssetup = {
758 ext3 => {
759 mkfs => 'mkfs.ext3 -F',
760 mkfs_root_opt => '',
761 mkfs_data_opt => '-m 0',
762 root_mountopt => 'errors=remount-ro',
763 },
764 ext4 => {
765 mkfs => 'mkfs.ext4 -F',
766 mkfs_root_opt => '',
767 mkfs_data_opt => '-m 0',
768 root_mountopt => 'errors=remount-ro',
769 },
770 xfs => {
771 mkfs => 'mkfs.xfs -f',
772 mkfs_root_opt => '',
773 mkfs_data_opt => '',
774 root_mountopt => '',
775 },
776 };
777
778 sub create_filesystem {
779 my ($dev, $name, $type, $start, $end, $fs, $fe) = @_;
780
781 my $range = $end - $start;
782 my $rs = $start + $range*$fs;
783 my $re = $start + $range*$fe;
784 my $max = 0;
785
786 my $fsdata = $fssetup->{$type} || die "internal error - unknown file system '$type'";
787 my $opts = $name eq 'root' ? $fsdata->{mkfs_root_opt} : $fsdata->{mkfs_data_opt};
788
789 update_progress(0, $rs, $re, "creating $name filesystem");
790
791 run_command("$fsdata->{mkfs} $opts $dev", sub {
792 my $line = shift;
793
794 if ($line =~ m/Writing inode tables:\s+(\d+)\/(\d+)/) {
795 $max = $2;
796 } elsif ($max && $line =~ m/(\d+)\/$max/) {
797 update_progress(($1/$max)*0.9, $rs, $re);
798 } elsif ($line =~ m/Creating journal.*done/) {
799 update_progress(0.95, $rs, $re);
800 } elsif ($line =~ m/Writing superblocks and filesystem.*done/) {
801 update_progress(1, $rs, $re);
802 }
803 });
804 }
805
806 sub debconfig_set {
807 my ($targetdir, $dcdata) = @_;
808
809 my $cfgfile = "/tmp/debconf.txt";
810 write_config($dcdata, "$targetdir/$cfgfile");
811 syscmd("chroot $targetdir debconf-set-selections $cfgfile");
812 unlink "$targetdir/$cfgfile";
813 }
814
815 sub diversion_add {
816 my ($targetdir, $cmd, $new_cmd) = @_;
817
818 syscmd("chroot $targetdir dpkg-divert --package proxmox " .
819 "--add --rename $cmd") == 0 ||
820 die "unable to exec dpkg-divert\n";
821
822 syscmd("ln -sf ${new_cmd} $targetdir/$cmd") == 0 ||
823 die "unable to link diversion to ${new_cmd}\n";
824 }
825
826 sub diversion_remove {
827 my ($targetdir, $cmd) = @_;
828
829 syscmd("mv $targetdir/${cmd}.distrib $targetdir/${cmd};") == 0 ||
830 die "unable to remove $cmd diversion\n";
831
832 syscmd("chroot $targetdir dpkg-divert --remove $cmd") == 0 ||
833 die "unable to remove $cmd diversion\n";
834 }
835
836 sub btrfs_create {
837 my ($partitions, $mode) = @_;
838
839 die "unknown btrfs mode '$mode'"
840 if !($mode eq 'single' || $mode eq 'raid0' ||
841 $mode eq 'raid1' || $mode eq 'raid10');
842
843 my $cmd = ['mkfs.btrfs', '-f'];
844
845 push @$cmd, '-d', $mode, '-m', $mode;
846
847 push @$cmd, @$partitions;
848
849 syscmd($cmd);
850 }
851
852 sub zfs_create_rpool {
853 my ($vdev) = @_;
854
855 my $cmd = "zpool create -f -o cachefile=none";
856
857 $cmd .= " -o ashift=$config_options->{ashift}"
858 if defined($config_options->{ashift});
859
860 syscmd("$cmd $zfspoolname $vdev") == 0 ||
861 die "unable to create zfs root pool\n";
862
863 syscmd("zfs create $zfspoolname/ROOT") == 0 ||
864 die "unable to create zfs $zfspoolname/ROOT volume\n";
865
866 if ($setup->{product} eq 'pve') {
867 syscmd("zfs create $zfspoolname/data") == 0 ||
868 die "unable to create zfs $zfspoolname/data volume\n";
869 }
870
871 syscmd("zfs create $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
872 die "unable to create zfs $zfspoolname/ROOT/$zfsrootvolname volume\n";
873
874 # disable atime during install
875 syscmd("zfs set atime=off $zfspoolname") == 0 ||
876 die "unable to set zfs properties\n";
877
878 my $value = $config_options->{compress};
879 syscmd("zfs set compression=$value $zfspoolname")
880 if defined($value) && $value ne 'off';
881
882 $value = $config_options->{checksum};
883 syscmd("zfs set checksum=$value $zfspoolname")
884 if defined($value) && $value ne 'on';
885
886 $value = $config_options->{copies};
887 syscmd("zfs set copies=$value $zfspoolname")
888 if defined($value) && $value != 1;
889 }
890
891 my $udevadm_trigger_block = sub {
892 my ($nowait) = @_;
893
894 sleep(1) if !$nowait; # give kernel time to reread part table
895
896 # trigger udev to create /dev/disk/by-uuid
897 syscmd("udevadm trigger --subsystem-match block");
898 syscmd("udevadm settle --timeout 10");
899 };
900
901 my $clean_disk = sub {
902 my ($disk) = @_;
903
904 my $partitions = `lsblk --output kname --noheadings --path --list $disk`;
905 foreach my $part (split "\n", $partitions) {
906 next if $part eq $disk;
907 next if $part !~ /^\Q$disk\E/;
908 eval { syscmd("pvremove -ff -y $part"); };
909 eval { syscmd("zpool labelclear -f $part"); };
910 eval { syscmd("dd if=/dev/zero of=$part bs=1M count=16"); };
911 }
912 };
913
914 sub partition_bootable_disk {
915 my ($target_dev, $maxhdsizegb, $ptype) = @_;
916
917 die "too dangerous" if $opt_testmode;
918
919 die "unknown partition type '$ptype'"
920 if !($ptype eq '8E00' || $ptype eq '8300' || $ptype eq 'BF01');
921
922 syscmd("sgdisk -Z ${target_dev}");
923 my $hdsize = hd_size($target_dev); # size in KB (1024 bytes)
924
925 my $restricted_hdsize_mb = 0; # 0 ==> end of partition
926 if ($maxhdsizegb) {
927 my $maxhdsize = $maxhdsizegb * 1024 * 1024;
928 if ($maxhdsize < $hdsize) {
929 $hdsize = $maxhdsize;
930 $restricted_hdsize_mb = int($hdsize/1024) . 'M';
931 }
932 }
933
934 my $hdgb = int($hdsize/(1024*1024));
935 die "hardisk '$target_dev' too small (${hdgb}GB)\n" if $hdgb < 8;
936
937 # 1 - BIOS boot partition (Grub Stage2): first free 1M
938 # 2 - EFI ESP: next free 512M
939 # 3 - OS/Data partition: rest, up to $maxhdsize in MB
940
941 my $grubbootdev = get_partition_dev($target_dev, 1);
942 my $efibootdev = get_partition_dev($target_dev, 2);
943 my $osdev = get_partition_dev ($target_dev, 3);
944
945 my $pcmd = ['sgdisk'];
946
947 my $pnum = 2;
948 push @$pcmd, "-n${pnum}:1M:+512M", "-t$pnum:EF00";
949
950 $pnum = 3;
951 push @$pcmd, "-n${pnum}:513M:${restricted_hdsize_mb}", "-t$pnum:$ptype";
952
953 push @$pcmd, $target_dev;
954
955 my $os_size = $hdsize - 513*1024; # 512M efi + 1M bios_boot + 1M alignment
956
957 syscmd($pcmd) == 0 ||
958 die "unable to partition harddisk '${target_dev}'\n";
959
960 $pnum = 1;
961 $pcmd = ['sgdisk', '-a1', "-n$pnum:34:2047", "-t$pnum:EF02" , $target_dev];
962
963 syscmd($pcmd) == 0 ||
964 die "unable to create bios_boot partition '${target_dev}'\n";
965
966 &$udevadm_trigger_block();
967
968 foreach my $part ($efibootdev, $osdev) {
969 syscmd("dd if=/dev/zero of=$part bs=1M count=256") if -b $part;
970 }
971
972 return ($os_size, $osdev, $efibootdev);
973 }
974
975 sub create_lvm_volumes {
976 my ($lvmdev, $os_size, $swap_size) = @_;
977
978 my $vgname = $setup->{product};
979
980 my $rootdev = "/dev/$vgname/root";
981 my $datadev = "/dev/$vgname/data";
982 my $swapfile;
983
984 # we use --metadatasize 250k, which results in "pe_start = 512"
985 # so pe_start is aligned on a 128k boundary (advantage for SSDs)
986 syscmd("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
987 die "unable to initialize physical volume $lvmdev\n";
988 syscmd("/sbin/vgcreate $vgname $lvmdev") == 0 ||
989 die "unable to create volume group '$vgname'\n";
990
991 my $hdgb = int($os_size/(1024*1024));
992 my $space = (($hdgb > 128) ? 16 : ($hdgb/8))*1024*1024;
993
994 my $rootsize;
995 my $datasize;
996
997 if ($setup->{product} eq 'pve') {
998
999 my $maxroot;
1000 if ($config_options->{maxroot}) {
1001 $maxroot = $config_options->{maxroot};
1002 } else {
1003 $maxroot = 96;
1004 }
1005
1006 $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
1007
1008 my $rest = $os_size - $swap_size - $rootsize; # in KB
1009
1010 my $minfree;
1011 if (defined($config_options->{minfree})) {
1012 $minfree = (($config_options->{minfree}*1024*1024) >= $rest ) ? $space :
1013 $config_options->{minfree}*1024*1024 ;
1014 } else {
1015 $minfree = $space;
1016 }
1017
1018 $rest = $rest - $minfree;
1019
1020 if (defined($config_options->{maxvz})) {
1021 $rest = (($config_options->{maxvz}*1024*1024) <= $rest) ?
1022 $config_options->{maxvz}*1024*1024 : $rest;
1023 }
1024
1025 $datasize = $rest;
1026
1027 } else {
1028 my $minfree = defined($config_options->{minfree}) ? $config_options->{minfree}*1024*1024 : $space;
1029 $rootsize = $os_size - $minfree - $swap_size; # in KB
1030 }
1031
1032 if ($swap_size) {
1033 syscmd("/sbin/lvcreate -L${swap_size}K -nswap $vgname") == 0 ||
1034 die "unable to create swap volume\n";
1035
1036 $swapfile = "/dev/$vgname/swap";
1037 }
1038
1039 syscmd("/sbin/lvcreate -L${rootsize}K -nroot $vgname") == 0 ||
1040 die "unable to create root volume\n";
1041
1042 if ($datasize > 4*1024*1024) {
1043 my $metadatasize = $datasize/100; # default 1% of data
1044 $metadatasize = 1024*1024 if $metadatasize < 1024*1024; # but at least 1G
1045 $metadatasize = 16*1024*1024 if $metadatasize > 16*1024*1024; # but at most 16G
1046
1047 # otherwise the metadata is taken out of $minfree
1048 $datasize -= 2*$metadatasize;
1049
1050 # 1 4MB PE to allow for rounding
1051 $datasize -= 4*1024;
1052
1053 syscmd("/sbin/lvcreate -L${datasize}K -ndata $vgname") == 0 ||
1054 die "unable to create data volume\n";
1055
1056 syscmd("/sbin/lvconvert --yes --type thin-pool --poolmetadatasize ${metadatasize}K $vgname/data") == 0 ||
1057 die "unable to create data thin-pool\n";
1058 } else {
1059 $datadev = undef;
1060 }
1061
1062 syscmd("/sbin/vgchange -a y $vgname") == 0 ||
1063 die "unable to activate volume group\n";
1064
1065 return ($rootdev, $swapfile, $datadev);
1066 }
1067
1068 sub compute_swapsize {
1069 my ($hdsize) = @_;
1070
1071 my $hdgb = int($hdsize/(1024*1024));
1072
1073 my $swapsize;
1074 if (defined($config_options->{swapsize})) {
1075 $swapsize = $config_options->{swapsize}*1024*1024;
1076 } else {
1077 my $ss = int ($total_memory / 1024);
1078 $ss = 4 if $ss < 4;
1079 $ss = ($hdgb/8) if $ss > ($hdgb/8);
1080 $ss = 8 if $ss > 8;
1081 $swapsize = $ss*1024*1024;
1082 }
1083
1084 return $swapsize;
1085 }
1086
1087 sub prepare_systemd_boot_esp {
1088 my ($espdev, $targetdir) = @_;
1089
1090 my $espuuid = find_dev_by_uuid($espdev);
1091 my $espmp = "var/tmp/$espuuid";
1092 mkdir "$targetdir/$espmp";
1093
1094 syscmd("mount -n $espdev -t vfat $targetdir/$espmp") == 0 ||
1095 die "unable to mount ESP $espdev\n";
1096
1097 File::Path::make_path("$targetdir/$espmp/EFI/proxmox") ||
1098 die "unable to create directory $targetdir/$espmp/EFI/proxmox\n";
1099
1100 syscmd("chroot $targetdir bootctl --path /$espmp install") == 0 ||
1101 die "unable to install systemd-boot loader\n";
1102 write_config("timeout 3\ndefault proxmox-*\n",
1103 "$targetdir/$espmp/loader/loader.conf");
1104
1105 syscmd("umount $targetdir/$espmp") == 0 ||
1106 die "unable to umount ESP $targetdir/$espmp\n";
1107
1108 }
1109
1110 sub prepare_grub_efi_boot_esp {
1111 my ($dev, $espdev, $targetdir) = @_;
1112
1113 syscmd("mount -n $espdev -t vfat $targetdir/boot/efi") == 0 ||
1114 die "unable to mount $espdev\n";
1115
1116 my $rc = syscmd("chroot $targetdir /usr/sbin/grub-install --target x86_64-efi --no-floppy --bootloader-id='proxmox' $dev");
1117 if ($rc != 0) {
1118 if ($boot_type eq 'efi') {
1119 die "unable to install the EFI boot loader on '$dev'\n";
1120 } else {
1121 warn "unable to install the EFI boot loader on '$dev', ignoring (not booted using UEFI)\n";
1122 }
1123 }
1124 # also install fallback boot file (OVMF does not boot without)
1125 mkdir("$targetdir/boot/efi/EFI/BOOT");
1126 syscmd("cp $targetdir/boot/efi/EFI/proxmox/grubx64.efi $targetdir/boot/efi/EFI/BOOT/BOOTx64.EFI") == 0 ||
1127 die "unable to copy efi boot loader\n";
1128
1129 syscmd("umount $targetdir/boot/efi") == 0 ||
1130 die "unable to umount $targetdir/boot/efi\n";
1131 }
1132
1133 sub extract_data {
1134 my ($basefile, $targetdir) = @_;
1135
1136 die "target '$targetdir' does not exist\n" if ! -d $targetdir;
1137
1138 my $starttime = [Time::HiRes::gettimeofday];
1139
1140 my $bootdevinfo = [];
1141
1142 my $swapfile;
1143 my $rootdev;
1144 my $datadev;
1145
1146 my $use_zfs = 0;
1147 my $use_btrfs = 0;
1148
1149 my $filesys = $config_options->{filesys};
1150
1151 if ($filesys =~ m/zfs/) {
1152 $target_hd = undef; # do not use this config
1153 $use_zfs = 1;
1154 $targetdir = "/$zfspoolname/ROOT/$zfsrootvolname";
1155 } elsif ($filesys =~ m/btrfs/) {
1156 $target_hd = undef; # do not use this config
1157 $use_btrfs = 1;
1158 }
1159
1160 if ($use_zfs) {
1161 my $i;
1162 for ($i = 5; $i > 0; $i--) {
1163 syscmd("modprobe zfs");
1164 last if -c "/dev/zfs";
1165 sleep(1);
1166 }
1167
1168 die "unable to load zfs kernel module\n" if !$i;
1169 }
1170
1171 eval {
1172
1173
1174 my $maxper = 0.25;
1175
1176 update_progress(0, 0, $maxper, "create partitions");
1177
1178 syscmd("vgchange -an") if !$opt_testmode; # deactivate all detected VGs
1179
1180 if ($opt_testmode) {
1181
1182 $rootdev = abs_path($opt_testmode);
1183 syscmd("umount $rootdev");
1184
1185 if ($use_btrfs) {
1186
1187 die "unsupported btrfs mode (for testing environment)\n"
1188 if $filesys ne 'btrfs (RAID0)';
1189
1190 btrfs_create([$rootdev], 'single');
1191
1192 } elsif ($use_zfs) {
1193
1194 die "unsupported zfs mode (for testing environment)\n"
1195 if $filesys ne 'zfs (RAID0)';
1196
1197 syscmd("zpool destroy $zfstestpool");
1198
1199 zfs_create_rpool($rootdev);
1200
1201 } else {
1202
1203 # nothing to do
1204 }
1205
1206 } elsif ($use_btrfs) {
1207
1208 my ($devlist, $btrfs_mode) = get_btrfs_raid_setup();
1209 my $btrfs_partitions = [];
1210 my $disksize;
1211 foreach my $hd (@$devlist) {
1212 my $devname = @$hd[1];
1213 &$clean_disk($devname);
1214 my ($size, $osdev, $efidev) =
1215 partition_bootable_disk($devname, undef, '8300');
1216 $rootdev = $osdev if !defined($rootdev); # simply point to first disk
1217 my $by_id = find_stable_path("/dev/disk/by-id", $devname);
1218 push @$bootdevinfo, { esp => $efidev, devname => $devname,
1219 osdev => $osdev, by_id => $by_id };
1220 push @$btrfs_partitions, $osdev;
1221 $disksize = $size;
1222 }
1223
1224 &$udevadm_trigger_block();
1225
1226 btrfs_create($btrfs_partitions, $btrfs_mode);
1227
1228 } elsif ($use_zfs) {
1229
1230 my ($devlist, $bootdevlist, $vdev) = get_zfs_raid_setup();
1231
1232 foreach my $hd (@$devlist) {
1233 &$clean_disk(@$hd[1]);
1234 }
1235
1236 my $disksize;
1237 foreach my $hd (@$bootdevlist) {
1238 my $devname = @$hd[1];
1239
1240 my ($size, $osdev, $efidev) =
1241 partition_bootable_disk($devname, $config_options->{hdsize}, 'BF01');
1242
1243 zfs_mirror_size_check($disksize, $size) if $disksize;
1244
1245 push @$bootdevinfo, {
1246 esp => $efidev,
1247 devname => $devname,
1248 osdev => $osdev
1249 };
1250 $disksize = $size;
1251 }
1252
1253 &$udevadm_trigger_block();
1254
1255 foreach my $di (@$bootdevinfo) {
1256 my $devname = $di->{devname};
1257 $di->{by_id} = find_stable_path ("/dev/disk/by-id", $devname);
1258
1259 my $osdev = find_stable_path ("/dev/disk/by-id", $di->{osdev}) || $di->{osdev};
1260
1261 $vdev =~ s/ $devname/ $osdev/;
1262 }
1263
1264 zfs_create_rpool($vdev);
1265
1266 } else {
1267
1268 die "target '$target_hd' is not a valid block device\n" if ! -b $target_hd;
1269
1270 &$clean_disk($target_hd);
1271
1272 my ($os_size, $osdev, $efidev);
1273 ($os_size, $osdev, $efidev) =
1274 partition_bootable_disk($target_hd, $config_options->{hdsize}, '8E00');
1275
1276 &$udevadm_trigger_block();
1277
1278 my $by_id = find_stable_path ("/dev/disk/by-id", $target_hd);
1279 push @$bootdevinfo, { esp => $efidev, devname => $target_hd,
1280 osdev => $osdev, by_id => $by_id };
1281
1282 my $swap_size = compute_swapsize($os_size);
1283 ($rootdev, $swapfile, $datadev) =
1284 create_lvm_volumes($osdev, $os_size, $swap_size);
1285
1286 # trigger udev to create /dev/disk/by-uuid
1287 &$udevadm_trigger_block(1);
1288 }
1289
1290 if ($use_zfs) {
1291 # to be fast during installation
1292 syscmd("zfs set sync=disabled $zfspoolname") == 0 ||
1293 die "unable to set zfs properties\n";
1294 }
1295
1296 update_progress(0.03, 0, $maxper, "create swap space");
1297 if ($swapfile) {
1298 syscmd("mkswap -f $swapfile") == 0 ||
1299 die "unable to create swap space\n";
1300 }
1301
1302 update_progress(0.05, 0, $maxper, "creating filesystems");
1303
1304 foreach my $di (@$bootdevinfo) {
1305 next if !$di->{esp};
1306 syscmd("mkfs.vfat -F32 $di->{esp}") == 0 ||
1307 die "unable to initialize EFI ESP on device $di->{esp}\n";
1308 }
1309
1310 if ($use_zfs) {
1311 # do nothing
1312 } elsif ($use_btrfs) {
1313 # do nothing
1314 } else {
1315 create_filesystem($rootdev, 'root', $filesys, 0.05, $maxper, 0, 1);
1316 }
1317
1318 update_progress(1, 0.05, $maxper, "mounting target $rootdev");
1319
1320 if ($use_zfs) {
1321 # do nothing
1322 } else {
1323 my $mount_opts = 'noatime';
1324 $mount_opts .= ',nobarrier'
1325 if $use_btrfs || $filesys =~ /^ext\d$/;
1326
1327 syscmd("mount -n $rootdev -o $mount_opts $targetdir") == 0 ||
1328 die "unable to mount $rootdev\n";
1329 }
1330
1331 mkdir "$targetdir/boot";
1332 mkdir "$targetdir/boot/efi";
1333
1334 mkdir "$targetdir/var";
1335 mkdir "$targetdir/var/lib";
1336
1337 if ($setup->{product} eq 'pve') {
1338 mkdir "$targetdir/var/lib/vz";
1339 mkdir "$targetdir/var/lib/pve";
1340
1341 if ($use_btrfs) {
1342 syscmd("btrfs subvolume create $targetdir/var/lib/pve/local-btrfs") == 0 ||
1343 die "unable to create btrfs subvolume\n";
1344 }
1345 }
1346
1347 mkdir "$targetdir/mnt";
1348 mkdir "$targetdir/mnt/hostrun";
1349 syscmd("mount --bind /run $targetdir/mnt/hostrun") == 0 ||
1350 die "unable to bindmount run on $targetdir/mnt/hostrun\n";
1351
1352 update_progress(1, 0.05, $maxper, "extracting base system");
1353
1354 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) = stat ($basefile);
1355 $ino || die "unable to open file '$basefile' - $!\n";
1356
1357 my $files = file_read_firstline("${proxmox_cddir}/proxmox/$setup->{product}-base.cnt") ||
1358 die "unable to read base file count\n";
1359
1360 my $per = 0;
1361 my $count = 0;
1362
1363 run_command("unsquashfs -f -dest $targetdir -i $basefile", sub {
1364 my $line = shift;
1365 return if $line !~ m/^$targetdir/;
1366 $count++;
1367 my $nper = int (($count *100)/$files);
1368 if ($nper != $per) {
1369 $per = $nper;
1370 my $frac = $per > 100 ? 1 : $per/100;
1371 update_progress($frac, $maxper, 0.5);
1372 }
1373 });
1374
1375 syscmd("mount -n -t tmpfs tmpfs $targetdir/tmp") == 0 ||
1376 die "unable to mount tmpfs on $targetdir/tmp\n";
1377 syscmd("mount -n -t proc proc $targetdir/proc") == 0 ||
1378 die "unable to mount proc on $targetdir/proc\n";
1379 syscmd("mount -n -t sysfs sysfs $targetdir/sys") == 0 ||
1380 die "unable to mount sysfs on $targetdir/sys\n";
1381 if ($boot_type eq 'efi') {
1382 syscmd("mount -n -t efivarfs efivarfs $targetdir/sys/firmware/efi/efivars") == 0 ||
1383 die "unable to mount efivarfs on $targetdir/sys/firmware/efi/efivars: $!\n";
1384 }
1385 syscmd("chroot $targetdir mount --bind /mnt/hostrun /run") == 0 ||
1386 die "unable to re-bindmount hostrun on /run in chroot\n";
1387
1388 update_progress(1, $maxper, 0.5, "configuring base system");
1389
1390 # configure hosts
1391
1392 my $hosts =
1393 "127.0.0.1 localhost.localdomain localhost\n" .
1394 "$ipaddress $hostname.$domain $hostname\n\n" .
1395 "# The following lines are desirable for IPv6 capable hosts\n\n" .
1396 "::1 ip6-localhost ip6-loopback\n" .
1397 "fe00::0 ip6-localnet\n" .
1398 "ff00::0 ip6-mcastprefix\n" .
1399 "ff02::1 ip6-allnodes\n" .
1400 "ff02::2 ip6-allrouters\n" .
1401 "ff02::3 ip6-allhosts\n";
1402
1403 write_config($hosts, "$targetdir/etc/hosts");
1404
1405 write_config("$hostname\n", "$targetdir/etc/hostname");
1406
1407 syscmd("/bin/hostname $hostname") if !$opt_testmode;
1408
1409 # configure interfaces
1410
1411 my $ifaces = "auto lo\niface lo inet loopback\n\n";
1412
1413 my $ntype = $ipversion == 4 ? 'inet' : 'inet6';
1414
1415 my $ethdev = $ipconf->{ifaces}->{$ipconf->{selected}}->{name};
1416
1417 if ($setup->{bridged_network}) {
1418 $ifaces .= "iface $ethdev $ntype manual\n";
1419
1420 $ifaces .=
1421 "\nauto vmbr0\niface vmbr0 $ntype static\n" .
1422 "\taddress $ipaddress\n" .
1423 "\tnetmask $netmask\n" .
1424 "\tgateway $gateway\n" .
1425 "\tbridge_ports $ethdev\n" .
1426 "\tbridge_stp off\n" .
1427 "\tbridge_fd 0\n";
1428 } else {
1429 $ifaces .= "auto $ethdev\n" .
1430 "iface $ethdev $ntype static\n" .
1431 "\taddress $ipaddress\n" .
1432 "\tnetmask $netmask\n" .
1433 "\tgateway $gateway\n";
1434 }
1435
1436 foreach my $iface (sort keys %{$ipconf->{ifaces}}) {
1437 my $name = $ipconf->{ifaces}->{$iface}->{name};
1438 next if $name eq $ethdev;
1439
1440 $ifaces .= "\niface $name $ntype manual\n";
1441 }
1442
1443 write_config($ifaces, "$targetdir/etc/network/interfaces");
1444
1445 # configure dns
1446
1447 my $resolvconf = "search $domain\nnameserver $dnsserver\n";
1448 write_config($resolvconf, "$targetdir/etc/resolv.conf");
1449
1450 # configure fstab
1451
1452 my $fstab = "# <file system> <mount point> <type> <options> <dump> <pass>\n";
1453
1454 if ($use_zfs) {
1455 # do nothing
1456 } elsif ($use_btrfs) {
1457 my $fsuuid;
1458 my $cmd = "blkid -u filesystem -t TYPE=btrfs -o export $rootdev";
1459 run_command($cmd, sub {
1460 my $line = shift;
1461
1462 if ($line =~ m/^UUID=([A-Fa-f0-9\-]+)$/) {
1463 $fsuuid = $1;
1464 }
1465 });
1466
1467 die "unable to detect FS UUID" if !defined($fsuuid);
1468
1469 $fstab .= "UUID=$fsuuid / btrfs defaults 0 1\n";
1470 } else {
1471 my $root_mountopt = $fssetup->{$filesys}->{root_mountopt} || 'defaults';
1472 $fstab .= "$rootdev / $filesys ${root_mountopt} 0 1\n";
1473 }
1474
1475 # mount /boot/efi
1476 # Note: this is required by current grub, but really dangerous, because
1477 # vfat does not have journaling, so it triggers manual fsck after each crash
1478 # so we only mount /boot/efi if really required (efi systems).
1479 if ($boot_type eq 'efi' && !$use_zfs) {
1480 if (scalar(@$bootdevinfo)) {
1481 my $di = @$bootdevinfo[0]; # simply use first disk
1482
1483 if ($di->{esp}) {
1484 my $efi_boot_uuid = $di->{esp};
1485 if (my $uuid = find_dev_by_uuid ($di->{esp})) {
1486 $efi_boot_uuid = "UUID=$uuid";
1487 }
1488
1489 $fstab .= "${efi_boot_uuid} /boot/efi vfat defaults 0 1\n";
1490 }
1491 }
1492 }
1493
1494
1495 $fstab .= "$swapfile none swap sw 0 0\n" if $swapfile;
1496
1497 $fstab .= "proc /proc proc defaults 0 0\n";
1498
1499 write_config($fstab, "$targetdir/etc/fstab");
1500 write_config("", "$targetdir/etc/mtab");
1501
1502 syscmd("cp ${proxmox_libdir}/policy-disable-rc.d " .
1503 "$targetdir/usr/sbin/policy-rc.d") == 0 ||
1504 die "unable to copy policy-rc.d\n";
1505 syscmd("cp ${proxmox_libdir}/fake-start-stop-daemon " .
1506 "$targetdir/sbin/") == 0 ||
1507 die "unable to copy start-stop-daemon\n";
1508
1509 diversion_add($targetdir, "/sbin/start-stop-daemon", "/sbin/fake-start-stop-daemon");
1510 diversion_add($targetdir, "/usr/sbin/update-grub", "/bin/true");
1511 diversion_add($targetdir, "/usr/sbin/update-initramfs", "/bin/true");
1512
1513 syscmd("touch $targetdir/proxmox_install_mode");
1514
1515 my $grub_install_devices_txt = '';
1516 foreach my $di (@$bootdevinfo) {
1517 $grub_install_devices_txt .= ', ' if $grub_install_devices_txt;
1518 $grub_install_devices_txt .= $di->{by_id} || $di->{devname};
1519 }
1520
1521 # Note: keyboard-configuration/xbkb-keymap is used by console-setup
1522 my $xkmap = $cmap->{kmap}->{$keymap}->{x11} // 'us';
1523
1524 debconfig_set ($targetdir, <<_EOD);
1525 locales locales/default_environment_locale select en_US.UTF-8
1526 locales locales/locales_to_be_generated select en_US.UTF-8 UTF-8
1527 samba-common samba-common/dhcp boolean false
1528 samba-common samba-common/workgroup string WORKGROUP
1529 postfix postfix/main_mailer_type select No configuration
1530 keyboard-configuration keyboard-configuration/xkb-keymap select $xkmap
1531 d-i debian-installer/locale select en_US.UTF-8
1532 grub-pc grub-pc/install_devices select $grub_install_devices_txt
1533 _EOD
1534
1535 my $pkg_count = 0;
1536 while (<${proxmox_pkgdir}/*.deb>) { $pkg_count++ };
1537
1538 # btrfs/dpkg is extremely slow without --force-unsafe-io
1539 my $dpkg_opts = $use_btrfs ? "--force-unsafe-io" : "";
1540
1541 $count = 0;
1542 while (<${proxmox_pkgdir}/*.deb>) {
1543 chomp;
1544 my $path = $_;
1545 my ($deb) = $path =~ m/${proxmox_pkgdir}\/(.*\.deb)/;
1546 update_progress($count/$pkg_count, 0.5, 0.75, "extracting $deb");
1547 print "extracting: $deb\n";
1548 syscmd("cp $path $targetdir/tmp/$deb") == 0 ||
1549 die "installation of package $deb failed\n";
1550 syscmd("chroot $targetdir dpkg $dpkg_opts --force-depends --no-triggers --unpack /tmp/$deb") == 0 ||
1551 die "installation of package $deb failed\n";
1552 update_progress((++$count)/$pkg_count, 0.5, 0.75);
1553 }
1554
1555 # needed for postfix postinst in case no other NIC is active
1556 syscmd("chroot $targetdir ifup lo");
1557
1558 my $cmd = "chroot $targetdir dpkg $dpkg_opts --force-confold --configure -a";
1559 $count = 0;
1560 run_command($cmd, sub {
1561 my $line = shift;
1562 if ($line =~ m/Setting up\s+(\S+)/) {
1563 update_progress((++$count)/$pkg_count, 0.75, 0.95,
1564 "configuring $1");
1565 }
1566 });
1567
1568 unlink "$targetdir/etc/mailname";
1569 $postfix_main_cf =~ s/__FQDN__/${hostname}.${domain}/;
1570 write_config($postfix_main_cf, "$targetdir/etc/postfix/main.cf");
1571
1572 # make sure we have all postfix directories
1573 syscmd("chroot $targetdir /usr/sbin/postfix check");
1574 # cleanup mail queue
1575 syscmd("chroot $targetdir /usr/sbin/postsuper -d ALL");
1576
1577 # enable NTP (timedatectl set-ntp true does not work without DBUS)
1578 syscmd("chroot $targetdir /bin/systemctl enable systemd-timesyncd.service");
1579
1580 unlink "$targetdir/proxmox_install_mode";
1581
1582 # set timezone
1583 unlink ("$targetdir/etc/localtime");
1584 symlink ("/usr/share/zoneinfo/$timezone", "$targetdir/etc/localtime");
1585 write_config("$timezone\n", "$targetdir/etc/timezone");
1586
1587 # set apt mirror
1588 if (my $mirror = $cmap->{country}->{$country}->{mirror}) {
1589 my $fn = "$targetdir/etc/apt/sources.list";
1590 syscmd("sed -i 's/ftp\\.debian\\.org/$mirror/' '$fn'");
1591 }
1592
1593 # create extended_states for apt (avoid cron job warning if that
1594 # file does not exist)
1595 write_config('', "$targetdir/var/lib/apt/extended_states");
1596
1597 # allow ssh root login
1598 syscmd(['sed', '-i', 's/^#\?PermitRootLogin.*/PermitRootLogin yes/', "$targetdir/etc/ssh/sshd_config"]);
1599
1600 if ($setup->{product} eq 'pmg') {
1601 # install initial clamav DB
1602 my $srcdir = "${proxmox_cddir}/proxmox/clamav";
1603 foreach my $fn ("main.cvd", "bytecode.cvd", "daily.cvd", "safebrowsing.cvd") {
1604 syscmd("cp \"$srcdir/$fn\" \"$targetdir/var/lib/clamav\"") == 0 ||
1605 die "installation of clamav db file '$fn' failed\n";
1606 }
1607 syscmd("chroot $targetdir /bin/chown clamav:clamav -R /var/lib/clamav") == 0 ||
1608 die "unable to set owner for clamav database files\n";
1609 }
1610
1611 if ($setup->{product} eq 'pve') {
1612 # save installer settings
1613 my $ucc = uc ($country);
1614 debconfig_set($targetdir, "pve-manager pve-manager/country string $ucc\n");
1615 }
1616
1617 update_progress(0.8, 0.95, 1, "make system bootable");
1618
1619 if ($use_zfs) {
1620 syscmd("sed -i -e 's/^GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"root=ZFS=$zfspoolname\\/ROOT\\/$zfsrootvolname boot=zfs\"/' $targetdir/etc/default/grub") == 0 ||
1621 die "unable to update /etc/default/grub\n";
1622
1623 if ($boot_type eq 'efi') {
1624 write_config("root=ZFS=$zfspoolname/ROOT/$zfsrootvolname boot=zfs", "$targetdir/etc/kernel/cmdline");
1625 }
1626
1627 }
1628
1629 diversion_remove($targetdir, "/usr/sbin/update-grub");
1630 diversion_remove($targetdir, "/usr/sbin/update-initramfs");
1631
1632 my $kapi;
1633 foreach my $fn (<$targetdir/lib/modules/*>) {
1634 if ($fn =~ m!/(\d+\.\d+\.\d+-\d+-pve)$!) {
1635 die "found multiple kernels\n" if defined($kapi);
1636 $kapi = $1;
1637 }
1638 }
1639 die "unable to detect kernel version\n" if !defined($kapi);
1640
1641 if (!$opt_testmode) {
1642
1643 unlink ("$targetdir/etc/mtab");
1644 symlink ("/proc/mounts", "$targetdir/etc/mtab");
1645 syscmd("mount -n --bind /dev $targetdir/dev");
1646
1647 syscmd("chroot $targetdir /usr/sbin/update-initramfs -c -k $kapi") == 0 ||
1648 die "unable to install initramfs\n";
1649
1650 foreach my $di (@$bootdevinfo) {
1651 my $dev = $di->{devname};
1652 syscmd("chroot $targetdir /usr/sbin/grub-install --target i386-pc --no-floppy --bootloader-id='proxmox' $dev") == 0 ||
1653 die "unable to install the i386-pc boot loader on '$dev'\n";
1654
1655 if (my $esp = $di->{esp}) {
1656 if ($use_zfs) {
1657 prepare_systemd_boot_esp($esp, $targetdir);
1658 } else {
1659 prepare_grub_efi_boot_esp($dev, $esp, $targetdir);
1660 }
1661 }
1662 }
1663
1664 syscmd("chroot $targetdir /usr/sbin/update-grub") == 0 ||
1665 die "unable to update boot loader config\n";
1666
1667 if ($use_zfs && $boot_type eq 'efi') {
1668 syscmd("chroot $targetdir /etc/kernel/postinst.d/zz-pve-efiboot") == 0 ||
1669 die "unable to generate systemd-boot config\n";
1670 }
1671
1672 syscmd("umount $targetdir/dev");
1673 }
1674
1675 # cleanup
1676
1677 unlink "$targetdir/usr/sbin/policy-rc.d";
1678
1679 diversion_remove($targetdir, "/sbin/start-stop-daemon");
1680
1681 # set root password
1682 my $octets = encode("utf-8", $password);
1683 run_command("chroot $targetdir /usr/sbin/chpasswd", undef,
1684 "root:$octets\n");
1685
1686 if ($setup->{product} eq 'pmg') {
1687 # save admin email
1688 write_config("section: admin\n\temail ${mailto}\n",
1689 "$targetdir/etc/pmg/pmg.conf");
1690
1691 } elsif ($setup->{product} eq 'pve') {
1692
1693 # create pmxcfs DB
1694
1695 my $tmpdir = "$targetdir/tmp/pve";
1696 mkdir $tmpdir;
1697
1698 # write vnc keymap to datacenter.cfg
1699 my $vnckmap = $cmap->{kmap}->{$keymap}->{kvm} || 'en-us';
1700 write_config("keyboard: $vnckmap\n",
1701 "$tmpdir/datacenter.cfg");
1702
1703 # save admin email
1704 write_config("user:root\@pam:1:0:::${mailto}::\n",
1705 "$tmpdir/user.cfg");
1706
1707 # write storage.cfg
1708 my $storage_cfg_fn = "$tmpdir/storage.cfg";
1709 if ($use_zfs) {
1710 write_config($storage_cfg_zfs, $storage_cfg_fn);
1711 } elsif ($use_btrfs) {
1712 write_config($storage_cfg_btrfs, $storage_cfg_fn);
1713 } elsif ($datadev) {
1714 write_config($storage_cfg_lvmthin, $storage_cfg_fn);
1715 } else {
1716 write_config($storage_cfg_local, $storage_cfg_fn);
1717 }
1718
1719 run_command("chroot $targetdir /usr/bin/create_pmxcfs_db /tmp/pve /var/lib/pve-cluster/config.db");
1720
1721 syscmd("rm -rf $tmpdir");
1722 }
1723 };
1724
1725 my $err = $@;
1726
1727 update_progress(1, 0, 1, "");
1728
1729 print $err if $err;
1730
1731 if ($opt_testmode) {
1732 my $elapsed = Time::HiRes::tv_interval($starttime);
1733 print "Elapsed extract time: $elapsed\n";
1734
1735 syscmd("chroot $targetdir /usr/bin/dpkg-query -W --showformat='\${package}\n'> final.pkglist");
1736 }
1737
1738 syscmd("umount $targetdir/run");
1739 syscmd("umount $targetdir/mnt/hostrun");
1740 syscmd("umount $targetdir/tmp");
1741 syscmd("umount $targetdir/proc");
1742 syscmd("umount $targetdir/sys/firmware/efi/efivars");
1743 syscmd("umount $targetdir/sys");
1744
1745 if ($use_zfs) {
1746 syscmd("zfs umount -a") == 0 ||
1747 die "unable to unmount zfs\n";
1748 } else {
1749 syscmd("umount -d $targetdir");
1750 }
1751
1752 if (!$err && $use_zfs) {
1753 syscmd("zfs set sync=standard $zfspoolname") == 0 ||
1754 die "unable to set zfs properties\n";
1755
1756 syscmd("zfs set mountpoint=/ $zfspoolname/ROOT/$zfsrootvolname") == 0 ||
1757 die "zfs set mountpoint failed\n";
1758
1759 syscmd("zpool set bootfs=$zfspoolname/ROOT/$zfsrootvolname $zfspoolname") == 0 ||
1760 die "zfs set bootfs failed\n";
1761 syscmd("zpool export $zfspoolname");
1762 }
1763
1764 die $err if $err;
1765 }
1766
1767 my $last_display_change = 0;
1768
1769 my $display_info_counter = 0;
1770
1771 my $display_info_items = [
1772 "extract1-license.htm",
1773 "extract2-rulesystem.htm",
1774 "extract3-spam.htm",
1775 "extract4-virus.htm",
1776 ];
1777
1778 sub display_info {
1779
1780 my $min_display_time = 15;
1781
1782 my $ctime = time();
1783
1784 return if ($ctime - $last_display_change) < $min_display_time;
1785
1786 my $page = $display_info_items->[$display_info_counter % scalar(@$display_info_items)];
1787
1788 $display_info_counter++;
1789
1790 display_html($page);
1791 }
1792
1793 sub display_html {
1794 my ($filename) = @_;
1795
1796 $filename = $steps[$step_number]->{html} if !$filename;
1797
1798 my $path = "${proxmox_libdir}/html/$filename";
1799
1800 my $url = "file://$path";
1801
1802 my $data = file_get_contents($path);
1803
1804 if ($filename eq 'license.htm') {
1805 my $license = eval { decode('utf8', file_get_contents("${proxmox_cddir}/EULA")) };
1806 if (my $err = $@) {
1807 die $err if !$opt_testmode;
1808 $license = "TESTMODE: Ignore non existent EULA...\n";
1809 }
1810 my $title = "END USER LICENSE AGREEMENT (EULA)";
1811 $data =~ s/__LICENSE__/$license/;
1812 $data =~ s/__LICENSE_TITLE__/$title/;
1813 }
1814
1815 $htmlview->load_html($data, $url);
1816
1817 $last_display_change = time();
1818 }
1819
1820 sub prev_function {
1821
1822 my ($text, $fctn) = @_;
1823
1824 $fctn = $step_number if !$fctn;
1825 $text = "_Previous" if !$text;
1826 $prev_btn->set_label ($text);
1827
1828 $step_number--;
1829 $steps[$step_number]->{function}();
1830
1831 $prev_btn->grab_focus();
1832 }
1833
1834 sub set_next {
1835 my ($text, $fctn) = @_;
1836
1837 $next_fctn = $fctn;
1838 my $step = $steps[$step_number];
1839 $text //= $steps[$step_number]->{next_button} // '_Next';
1840 $next->set_label($text);
1841
1842 $next->grab_focus();
1843 }
1844
1845 sub create_main_window {
1846
1847 $window = Gtk3::Window->new();
1848 $window->set_default_size(1024, 768);
1849 $window->set_has_resize_grip(0);
1850 $window->set_decorated(0) if !$opt_testmode;
1851
1852 my $vbox = Gtk3::VBox->new(0, 0);
1853
1854 my $logofn = "$setup->{product}-banner.png";
1855 my $image = Gtk3::Image->new_from_file("${proxmox_libdir}/$logofn");
1856 $vbox->pack_start($image, 0, 0, 0);
1857
1858 my $hbox = Gtk3::HBox->new(0, 0);
1859 $vbox->pack_start($hbox, 1, 1, 0);
1860
1861 # my $f1 = Gtk3::Frame->new ('test');
1862 # $f1->set_shadow_type ('none');
1863 # $hbox->pack_start ($f1, 1, 1, 0);
1864
1865 my $sep1 = Gtk3::HSeparator->new();
1866 $vbox->pack_start($sep1, 0, 0, 0);
1867
1868 $cmdbox = Gtk3::HBox->new();
1869 $vbox->pack_start($cmdbox, 0, 0, 10);
1870
1871 $next = Gtk3::Button->new('_Next');
1872 $next->signal_connect(clicked => sub { $last_display_change = 0; &$next_fctn (); });
1873 $cmdbox->pack_end($next, 0, 0, 10);
1874
1875
1876 $prev_btn = Gtk3::Button->new('_Previous');
1877 $prev_btn->signal_connect(clicked => sub { $last_display_change = 0; &prev_function (); });
1878 $cmdbox->pack_end($prev_btn, 0, 0, 10);
1879
1880
1881 my $abort = Gtk3::Button->new('_Abort');
1882 $abort->set_can_focus(0);
1883 $cmdbox->pack_start($abort, 0, 0, 10);
1884 $abort->signal_connect(clicked => sub { exit (-1); });
1885
1886 my $vbox2 = Gtk3::VBox->new(0, 0);
1887 $hbox->add($vbox2);
1888
1889 $htmlview = Gtk3::WebKit2::WebView->new();
1890 my $scrolls = Gtk3::ScrolledWindow->new();
1891 $scrolls->add($htmlview);
1892
1893 my $hbox2 = Gtk3::HBox->new(0, 0);
1894 $hbox2->pack_start($scrolls, 1, 1, 0);
1895
1896 $vbox2->pack_start($hbox2, 1, 1, 0);
1897
1898 my $vbox3 = Gtk3::VBox->new(0, 0);
1899 $vbox2->pack_start($vbox3, 0, 0, 0);
1900
1901 my $sep2 = Gtk3::HSeparator->new;
1902 $vbox3->pack_start($sep2, 0, 0, 0);
1903
1904 $inbox = Gtk3::HBox->new(0, 0);
1905 $vbox3->pack_start($inbox, 0, 0, 0);
1906
1907 $window->add($vbox);
1908
1909 $window->show_all;
1910 $window->realize();
1911 }
1912
1913 sub cleanup_view {
1914 $inbox->foreach(sub {
1915 my $child = shift;
1916 $inbox->remove ($child);
1917 });
1918 }
1919
1920 # fixme: newer GTK3 has special properties to handle numbers with Entry
1921 # only allow floating point numbers with Gtk3::Entry
1922
1923 sub check_float {
1924 my ($entry, $event) = @_;
1925
1926 return check_number($entry, $event, 1);
1927 }
1928
1929 sub check_int {
1930 my ($entry, $event) = @_;
1931
1932 return check_number($entry, $event, 0);
1933 }
1934
1935 sub check_number {
1936 my ($entry, $event, $float) = @_;
1937
1938 my $val = $event->get_keyval;
1939
1940 if (($float && $val == ord '.') ||
1941 $val == Gtk3::Gdk::KEY_ISO_Left_Tab ||
1942 $val == Gtk3::Gdk::KEY_Shift_L ||
1943 $val == Gtk3::Gdk::KEY_Tab ||
1944 $val == Gtk3::Gdk::KEY_Left ||
1945 $val == Gtk3::Gdk::KEY_Right ||
1946 $val == Gtk3::Gdk::KEY_BackSpace ||
1947 $val == Gtk3::Gdk::KEY_Delete ||
1948 ($val >= ord '0' && $val <= ord '9') ||
1949 ($val >= Gtk3::Gdk::KEY_KP_0 &&
1950 $val <= Gtk3::Gdk::KEY_KP_9)) {
1951 return undef;
1952 }
1953
1954 return 1;
1955 }
1956
1957 sub create_text_input {
1958 my ($default, $text) = @_;
1959
1960 my $hbox = Gtk3::HBox->new(0, 0);
1961
1962 my $label = Gtk3::Label->new($text);
1963 $label->set_size_request(150, -1);
1964 $label->set_alignment(1, 0.5);
1965 $hbox->pack_start($label, 0, 0, 10);
1966 my $e1 = Gtk3::Entry->new();
1967 $e1->set_width_chars(30);
1968 $hbox->pack_start($e1, 0, 0, 0);
1969 $e1->set_text($default);
1970
1971 return ($hbox, $e1);
1972 }
1973
1974 sub get_ip_config {
1975
1976 my $ifaces = {};
1977 my $default;
1978
1979 my $links = `ip -o l`;
1980 foreach my $l (split /\n/,$links) {
1981 my ($index, $name, $flags, $state, $mac) = $l =~ m/^(\d+):\s+(\S+):\s+<(\S+)>.*\s+state\s+(\S+)\s+.*\s+link\/ether\s+(\S+)\s+/;
1982 next if !$name || $name eq 'lo';
1983
1984 my $driver = readlink "/sys/class/net/$name/device/driver" || 'unknown';
1985 $driver =~ s!^.*/!!;
1986
1987 $ifaces->{"$index"} = {
1988 name => $name,
1989 driver => $driver,
1990 flags => $flags,
1991 state => $state,
1992 mac => $mac,
1993 };
1994
1995 my $addresses = `ip -o a s $name`;
1996 foreach my $a (split /\n/,$addresses) {
1997 my ($family, $ip, $prefix) = $a =~ m/^\Q$index\E:\s+\Q$name\E\s+(inet|inet6)\s+($IPRE)\/(\d+)\s+/;
1998 next if !$ip;
1999 next if $a =~ /scope\s+link/; # ignore link local
2000
2001 my $mask = $prefix;
2002
2003 if ($family eq 'inet') {
2004 next if !$ip =~ /$IPV4RE/;
2005 next if $prefix < 8 || $prefix > 32;
2006 $mask = @$ipv4_reverse_mask[$prefix];
2007 } else {
2008 next if !$ip =~ /$IPV6RE/;
2009 }
2010
2011 $default = $index if !$default;
2012
2013 $ifaces->{"$index"}->{"$family"} = {
2014 mask => $mask,
2015 addr => $ip,
2016 };
2017 }
2018 }
2019
2020
2021 my $route = `ip route`;
2022 my ($gateway) = $route =~ m/^default\s+via\s+(\S+)\s+/m;
2023
2024 my $resolvconf = `cat /etc/resolv.conf`;
2025 my ($dnsserver) = $resolvconf =~ m/^nameserver\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/m;
2026 my ($domain) = $resolvconf =~ m/^domain\s+(\S+)$/m;
2027
2028 return {
2029 default => $default,
2030 ifaces => $ifaces,
2031 gateway => $gateway,
2032 dnsserver => $dnsserver,
2033 domain => $domain,
2034 }
2035 }
2036
2037 sub display_message {
2038 my ($msg) = @_;
2039
2040 my $dialog = Gtk3::MessageDialog->new($window, 'modal',
2041 'info', 'ok', $msg);
2042 $dialog->run();
2043 $dialog->destroy();
2044 }
2045
2046 sub display_error {
2047 my ($msg) = @_;
2048
2049 my $dialog = Gtk3::MessageDialog->new($window, 'modal',
2050 'error', 'ok', $msg);
2051 $dialog->run();
2052 $dialog->destroy();
2053 }
2054
2055 my $ipconf_first_view = 1;
2056
2057 sub create_ipconf_view {
2058
2059 cleanup_view();
2060 display_html();
2061
2062 my $vbox = Gtk3::VBox->new(0, 0);
2063 $inbox->pack_start($vbox, 1, 0, 0);
2064 my $hbox = Gtk3::HBox->new(0, 0);
2065 $vbox->pack_start($hbox, 0, 0, 10);
2066 my $vbox2 = Gtk3::VBox->new(0, 0);
2067 $hbox->add($vbox2);
2068
2069 my $ipaddr_text = $config->{ipaddress} // "192.168.100.2";
2070 my $ipbox;
2071 ($ipbox, $ipconf_entry_addr) =
2072 create_text_input($ipaddr_text, 'IP Address:');
2073
2074 my $netmask_text = $config->{netmask} // "255.255.255.0";
2075 my $maskbox;
2076 ($maskbox, $ipconf_entry_mask) =
2077 create_text_input($netmask_text, 'Netmask:');
2078
2079 my $device_cb = Gtk3::ComboBoxText->new();
2080 $device_cb->set_active(0);
2081 $device_cb->set_visible(1);
2082
2083 my $get_device_desc = sub {
2084 my $iface = shift;
2085 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
2086 };
2087
2088 my $device_active_map = {};
2089 my $device_active_reverse_map = {};
2090
2091 my $device_change_handler = sub {
2092 my $current = shift;
2093
2094 my $new = $device_active_map->{$current->get_active()};
2095 return if defined($ipconf->{selected}) && $new eq $ipconf->{selected};
2096
2097 $ipconf->{selected} = $new;
2098 my $iface = $ipconf->{ifaces}->{$ipconf->{selected}};
2099 $config->{mngmt_nic} = $iface->{name};
2100 $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
2101 if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
2102 $ipconf_entry_mask->set_text($iface->{inet}->{mask} || $iface->{inet6}->{mask})
2103 if $iface->{inet}->{mask} || $iface->{inet6}->{mask};
2104 };
2105
2106 my $i = 0;
2107 foreach my $index (sort keys %{$ipconf->{ifaces}}) {
2108 $device_cb->append_text(&$get_device_desc($ipconf->{ifaces}->{$index}));
2109 $device_active_map->{$i} = $index;
2110 $device_active_reverse_map->{$ipconf->{ifaces}->{$index}->{name}} = $i;
2111 if ($ipconf_first_view && $index == $ipconf->{default}) {
2112 $device_cb->set_active($i);
2113 &$device_change_handler($device_cb);
2114 $ipconf_first_view = 0;
2115 }
2116 $device_cb->signal_connect('changed' => $device_change_handler);
2117 $i++;
2118 }
2119
2120 if (my $nic = $config->{mngmt_nic}) {
2121 $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
2122 } else {
2123 $device_cb->set_active(0);
2124 }
2125
2126 my $devicebox = Gtk3::HBox->new(0, 0);
2127 my $label = Gtk3::Label->new("Management Interface:");
2128 $label->set_size_request(150, -1);
2129 $label->set_alignment(1, 0.5);
2130 $devicebox->pack_start($label, 0, 0, 10);
2131 $devicebox->pack_start($device_cb, 0, 0, 0);
2132
2133 $vbox2->pack_start($devicebox, 0, 0, 2);
2134
2135 my $hn = $config->{fqdn} // "$setup->{product}." . ($ipconf->{domain} // "example.invalid");
2136
2137 my ($hostbox, $hostentry) =
2138 create_text_input($hn, 'Hostname (FQDN):');
2139 $vbox2->pack_start($hostbox, 0, 0, 2);
2140
2141 $vbox2->pack_start($ipbox, 0, 0, 2);
2142
2143 $vbox2->pack_start($maskbox, 0, 0, 2);
2144
2145 $gateway = $config->{gateway} // $ipconf->{gateway} || '192.168.100.1';
2146
2147 my $gwbox;
2148 ($gwbox, $ipconf_entry_gw) =
2149 create_text_input($gateway, 'Gateway:');
2150
2151 $vbox2->pack_start($gwbox, 0, 0, 2);
2152
2153 $dnsserver = $config->{dnsserver} // $ipconf->{dnsserver} || $gateway;
2154
2155 my $dnsbox;
2156 ($dnsbox, $ipconf_entry_dns) =
2157 create_text_input($dnsserver, 'DNS Server:');
2158
2159 $vbox2->pack_start($dnsbox, 0, 0, 0);
2160
2161 $inbox->show_all;
2162 set_next(undef, sub {
2163
2164 # verify hostname
2165
2166 my $text = $hostentry->get_text();
2167
2168 $text =~ s/^\s+//;
2169 $text =~ s/\s+$//;
2170
2171 $config->{fqdn} = $text;
2172
2173 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
2174
2175 # Debian does not support purely numeric hostnames
2176 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
2177 display_message("Purely numeric hostnames are not allowed.");
2178 $hostentry->grab_focus();
2179 return;
2180 }
2181
2182 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
2183 $text =~ m/^([^\.]+)\.(\S+)$/) {
2184 $hostname = $1;
2185 $domain = $2;
2186 } else {
2187 display_message("Hostname does not look like a fully qualified domain name.");
2188 $hostentry->grab_focus();
2189 return;
2190 }
2191
2192 # verify ip address
2193
2194 $text = $ipconf_entry_addr->get_text();
2195 $text =~ s/^\s+//;
2196 $text =~ s/\s+$//;
2197 if ($text =~ m!^($IPV4RE)$!) {
2198 $ipaddress = $text;
2199 $ipversion = 4;
2200 } elsif ($text =~ m!^($IPV6RE)$!) {
2201 $ipaddress = $text;
2202 $ipversion = 6;
2203 } else {
2204 display_message("IP address is not valid.");
2205 $ipconf_entry_addr->grab_focus();
2206 return;
2207 }
2208 $config->{ipaddress} = $ipaddress;
2209
2210 $text = $ipconf_entry_mask->get_text();
2211 $text =~ s/^\s+//;
2212 $text =~ s/\s+$//;
2213 if (($ipversion == 6) && ($text =~ m/^(\d+)$/) && ($1 >= 8) && ($1 <= 126)) {
2214 $netmask = $text;
2215 } elsif (($ipversion == 4) && defined($ipv4_mask_hash->{$text})) {
2216 $netmask = $text;
2217 } else {
2218 display_message("Netmask is not valid.");
2219 $ipconf_entry_mask->grab_focus();
2220 return;
2221 }
2222 $config->{netmask} = $netmask;
2223
2224 $text = $ipconf_entry_gw->get_text();
2225 $text =~ s/^\s+//;
2226 $text =~ s/\s+$//;
2227 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2228 $gateway = $text;
2229 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2230 $gateway = $text;
2231 } else {
2232 display_message("Gateway is not valid.");
2233 $ipconf_entry_gw->grab_focus();
2234 return;
2235 }
2236 $config->{gateway} = $gateway;
2237
2238 $text = $ipconf_entry_dns->get_text();
2239 $text =~ s/^\s+//;
2240 $text =~ s/\s+$//;
2241 if (($ipversion == 4) && ($text =~ m!^($IPV4RE)$!)) {
2242 $dnsserver = $text;
2243 } elsif (($ipversion == 6) && ($text =~ m!^($IPV6RE)$!)) {
2244 $dnsserver = $text;
2245 } else {
2246 display_message("DNS server is not valid.");
2247 $ipconf_entry_dns->grab_focus();
2248 return;
2249 }
2250 $config->{dnsserver} = $dnsserver;
2251
2252 #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
2253
2254 $step_number++;
2255 create_ack_view();
2256 });
2257
2258 $hostentry->grab_focus();
2259 }
2260
2261 sub create_ack_view {
2262
2263 cleanup_view();
2264
2265 my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
2266 my $ack_html = "${proxmox_libdir}/html/$steps[$step_number]->{html}";
2267 my $html_data = file_get_contents($ack_template);
2268
2269 my %config_values = (
2270 __target_hd__ => join(' | ', @{$config_options->{target_hds}}),
2271 __target_fs__ => $config_options->{filesys},
2272 __country__ => $cmap->{country}->{$country}->{name},
2273 __timezone__ => $timezone,
2274 __keymap__ => $keymap,
2275 __mailto__ => $mailto,
2276 __interface__ => $ipconf->{ifaces}->{$ipconf->{selected}}->{name},
2277 __hostname__ => $hostname,
2278 __ip__ => $ipaddress,
2279 __netmask__ => $netmask,
2280 __gateway__ => $gateway,
2281 __dnsserver__ => $dnsserver,
2282 );
2283
2284 while ( my ($k, $v) = each %config_values) {
2285 $html_data =~ s/$k/$v/g;
2286 }
2287
2288 write_config($html_data, $ack_html);
2289
2290 display_html();
2291
2292 set_next(undef, sub {
2293 $step_number++;
2294 create_extract_view();
2295 });
2296 }
2297
2298 sub get_device_desc {
2299 my ($devname, $size, $model) = @_;
2300
2301 if ($size && ($size > 0)) {
2302 $size = int($size/2048); # size in MB, from 512B "sectors"
2303
2304 my $text = "$devname (";
2305 if ($size >= 1024) {
2306 $size = int($size/1024); # size in GB
2307 $text .= "${size}GB";
2308 } else {
2309 $text .= "${size}MB";
2310 }
2311
2312 $text .= ", $model" if $model;
2313 $text .= ")";
2314
2315 } else {
2316 return $devname;
2317 }
2318 }
2319
2320 sub update_layout {
2321 my ($cb, $kmap) = @_;
2322
2323 my $ind;
2324 my $def;
2325 my $i = 0;
2326 my $kmaphash = $cmap->{kmaphash};
2327 foreach my $layout (sort keys %$kmaphash) {
2328 $def = $i if $kmaphash->{$layout} eq 'en-us';
2329 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
2330 $i++;
2331 }
2332
2333 $cb->set_active($ind || $def || 0);
2334 }
2335
2336 my $lastzonecb;
2337 sub update_zonelist {
2338 my ($box, $cc) = @_;
2339
2340 my $cczones = $cmap->{cczones};
2341 my $zones = $cmap->{zones};
2342
2343 my $sel;
2344 if ($lastzonecb) {
2345 $sel = $lastzonecb->get_active_text();
2346 $box->remove ($lastzonecb);
2347 } else {
2348 $sel = $timezone; # used once to select default
2349 }
2350
2351 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
2352 $cb->set_size_request(200, -1);
2353
2354 $cb->signal_connect('changed' => sub {
2355 $timezone = $cb->get_active_text();
2356 });
2357
2358 my @za;
2359 if ($cc && defined ($cczones->{$cc})) {
2360 @za = keys %{$cczones->{$cc}};
2361 } else {
2362 @za = keys %$zones;
2363 }
2364 my $ind;
2365 my $i = 0;
2366 foreach my $zone (sort @za) {
2367 $ind = $i if $sel && $zone eq $sel;
2368 $cb->append_text($zone);
2369 $i++;
2370 }
2371
2372 $cb->set_active($ind || 0);
2373
2374 $cb->show;
2375 $box->pack_start($cb, 0, 0, 0);
2376 }
2377
2378 sub create_password_view {
2379
2380 cleanup_view();
2381
2382 my $vbox2 = Gtk3::VBox->new(0, 0);
2383 $inbox->pack_start($vbox2, 1, 0, 0);
2384 my $vbox = Gtk3::VBox->new(0, 0);
2385 $vbox2->pack_start($vbox, 0, 0, 10);
2386
2387 my $hbox1 = Gtk3::HBox->new(0, 0);
2388 my $label = Gtk3::Label->new("Password");
2389 $label->set_size_request(150, -1);
2390 $label->set_alignment(1, 0.5);
2391 $hbox1->pack_start($label, 0, 0, 10);
2392 my $pwe1 = Gtk3::Entry->new();
2393 $pwe1->set_visibility(0);
2394 $pwe1->set_text($password) if $password;
2395 $pwe1->set_size_request(200, -1);
2396 $hbox1->pack_start($pwe1, 0, 0, 0);
2397
2398 my $hbox2 = Gtk3::HBox->new(0, 0);
2399 $label = Gtk3::Label->new("Confirm");
2400 $label->set_size_request(150, -1);
2401 $label->set_alignment(1, 0.5);
2402 $hbox2->pack_start($label, 0, 0, 10);
2403 my $pwe2 = Gtk3::Entry->new();
2404 $pwe2->set_visibility(0);
2405 $pwe2->set_text($password) if $password;
2406 $pwe2->set_size_request(200, -1);
2407 $hbox2->pack_start($pwe2, 0, 0, 0);
2408
2409 my $hbox3 = Gtk3::HBox->new(0, 0);
2410 $label = Gtk3::Label->new("E-Mail");
2411 $label->set_size_request(150, -1);
2412 $label->set_alignment(1, 0.5);
2413 $hbox3->pack_start($label, 0, 0, 10);
2414 my $eme = Gtk3::Entry->new();
2415 $eme->set_size_request(200, -1);
2416 $eme->set_text($mailto);
2417 $hbox3->pack_start($eme, 0, 0, 0);
2418
2419
2420 $vbox->pack_start($hbox1, 0, 0, 5);
2421 $vbox->pack_start($hbox2, 0, 0, 5);
2422 $vbox->pack_start($hbox3, 0, 0, 15);
2423
2424 $inbox->show_all;
2425
2426 display_html();
2427
2428 set_next (undef, sub {
2429
2430 my $t1 = $pwe1->get_text;
2431 my $t2 = $pwe2->get_text;
2432
2433 if (length ($t1) < 5) {
2434 display_message("Password is too short.");
2435 $pwe1->grab_focus();
2436 return;
2437 }
2438
2439 if ($t1 ne $t2) {
2440 display_message("Password does not match.");
2441 $pwe1->grab_focus();
2442 return;
2443 }
2444
2445 my $t3 = $eme->get_text;
2446 if ($t3 !~ m/^\S+\@\S+\.\S+$/) {
2447 display_message("E-Mail does not look like a valid address" .
2448 " (user\@domain.tld)");
2449 $eme->grab_focus();
2450 return;
2451 }
2452
2453 if ($t3 eq 'mail@example.invalid') {
2454 display_message("Please enter a valid E-Mail address");
2455 $eme->grab_focus();
2456 return;
2457 }
2458
2459 $password = $t1;
2460 $mailto = $t3;
2461
2462 $step_number++;
2463 create_ipconf_view();
2464 });
2465
2466 $pwe1->grab_focus();
2467
2468 }
2469
2470 sub create_country_view {
2471
2472 cleanup_view();
2473
2474 my $countryhash = $cmap->{countryhash};
2475 my $ctr = $cmap->{country};
2476
2477 my $vbox2 = Gtk3::VBox->new(0, 0);
2478 $inbox->pack_start($vbox2, 1, 0, 0);
2479 my $vbox = Gtk3::VBox->new(0, 0);
2480 $vbox2->pack_start($vbox, 0, 0, 10);
2481
2482 my $w = Gtk3::Entry->new();
2483 $w->set_size_request(200, -1);
2484
2485 my $c = Gtk3::EntryCompletion->new();
2486 $c->set_text_column(0);
2487 $c->set_minimum_key_length(0);
2488 $c->set_popup_set_width(1);
2489 $c->set_inline_completion(1);
2490
2491 my $hbox2 = Gtk3::HBox->new(0, 0);
2492 my $label = Gtk3::Label->new("Time zone");
2493 $label->set_size_request(150, -1);
2494 $label->set_alignment(1, 0.5);
2495 $hbox2->pack_start($label, 0, 0, 10);
2496 update_zonelist ($hbox2);
2497
2498 my $hbox3 = Gtk3::HBox->new(0, 0);
2499 $label = Gtk3::Label->new("Keyboard Layout");
2500 $label->set_size_request(150, -1);
2501 $label->set_alignment(1, 0.5);
2502 $hbox3->pack_start($label, 0, 0, 10);
2503
2504 my $kmapcb = Gtk3::ComboBoxText->new();
2505 $kmapcb->set_size_request (200, -1);
2506 foreach my $layout (sort keys %{$cmap->{kmaphash}}) {
2507 $kmapcb->append_text ($layout);
2508 }
2509
2510 update_layout($kmapcb);
2511 $hbox3->pack_start ($kmapcb, 0, 0, 0);
2512
2513 $kmapcb->signal_connect ('changed' => sub {
2514 my $sel = $kmapcb->get_active_text();
2515 if (my $kmap = $cmap->{kmaphash}->{$sel}) {
2516 my $xkmap = $cmap->{kmap}->{$kmap}->{x11};
2517 my $xvar = $cmap->{kmap}->{$kmap}->{x11var};
2518 syscmd ("setxkbmap $xkmap $xvar") if !$opt_testmode;
2519 $keymap = $kmap;
2520 }
2521 });
2522
2523 $w->signal_connect ('changed' => sub {
2524 my ($entry, $event) = @_;
2525 my $text = $entry->get_text;
2526
2527 if (my $cc = $countryhash->{lc($text)}) {
2528 update_zonelist($hbox2, $cc);
2529 my $kmap = $ctr->{$cc}->{kmap} || 'en-us';
2530 update_layout($kmapcb, $kmap);
2531 }
2532 });
2533
2534 $w->signal_connect (key_press_event => sub {
2535 my ($entry, $event) = @_;
2536 my $text = $entry->get_text;
2537
2538 my $val = $event->get_keyval;
2539
2540 if ($val == Gtk3::Gdk::KEY_Tab) {
2541 my $cc = $countryhash->{lc($text)};
2542
2543 my $found = 0;
2544 my $compl;
2545
2546 if ($cc) {
2547 $found = 1;
2548 $compl = $ctr->{$cc}->{name};
2549 } else {
2550 foreach my $cc (keys %$ctr) {
2551 my $ct = $ctr->{$cc}->{name};
2552 if ($ct =~ m/^\Q$text\E.*$/i) {
2553 $found++;
2554 $compl = $ct;
2555 }
2556 last if $found > 1;
2557 }
2558 }
2559
2560 if ($found == 1) {
2561 $entry->set_text($compl);
2562 $c->complete();
2563 return undef;
2564 } else {
2565 #Gtk3::Gdk::beep();
2566 print chr(7); # beep ?
2567 }
2568
2569 $c->complete();
2570
2571 my $buf = $w->get_buffer();
2572 $buf->insert_text(-1, '', -1); # popup selection
2573
2574 return 1;
2575 }
2576
2577 return undef;
2578 });
2579
2580 my $ls = Gtk3::ListStore->new('Glib::String');
2581 foreach my $cc (sort {$ctr->{$a}->{name} cmp $ctr->{$b}->{name} } keys %$ctr) {
2582 my $iter = $ls->append();
2583 $ls->set ($iter, 0, $ctr->{$cc}->{name});
2584 }
2585 $c->set_model ($ls);
2586
2587 $w->set_completion ($c);
2588
2589 my $hbox = Gtk3::HBox->new(0, 0);
2590
2591 $label = Gtk3::Label->new("Country");
2592 $label->set_alignment(1, 0.5);
2593 $label->set_size_request(150, -1);
2594 $hbox->pack_start($label, 0, 0, 10);
2595 $hbox->pack_start($w, 0, 0, 0);
2596
2597 $vbox->pack_start($hbox, 0, 0, 5);
2598 $vbox->pack_start($hbox2, 0, 0, 5);
2599 $vbox->pack_start($hbox3, 0, 0, 5);
2600
2601 if ($country && $ctr->{$country}) {
2602 $w->set_text ($ctr->{$country}->{name});
2603 }
2604
2605 $inbox->show_all;
2606
2607 display_html();
2608 set_next (undef, sub {
2609
2610 my $text = $w->get_text;
2611
2612 if (my $cc = $countryhash->{lc($text)}) {
2613 $country = $cc;
2614 $step_number++;
2615 create_password_view();
2616 return;
2617 } else {
2618 display_message("Please select a country first.");
2619 $w->grab_focus();
2620 }
2621 });
2622
2623 $w->grab_focus();
2624 }
2625
2626 my $target_hd_combo;
2627 my $target_hd_label;
2628
2629 my $hdoption_first_setup = 1;
2630
2631 my $create_basic_grid = sub {
2632 my $grid = Gtk3::Grid->new();
2633 $grid->set_visible(1);
2634 $grid->set_column_spacing(10);
2635 $grid->set_row_spacing(10);
2636 $grid->set_hexpand(1);
2637
2638 $grid->set_margin_start(5);
2639 $grid->set_margin_end(5);
2640 $grid->set_margin_top(5);
2641 $grid->set_margin_bottom(5);
2642
2643 return $grid;
2644 };
2645
2646 my $create_label_widget_grid = sub {
2647 my ($labeled_widgets) = @_;
2648
2649 my $grid = &$create_basic_grid();
2650 my $row = 0;
2651
2652 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
2653 my $widget = @$labeled_widgets[$i+1];
2654 my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
2655 $label->set_visible(1);
2656 $label->set_alignment (1, 0.5);
2657 $grid->attach($label, 0, $row, 1, 1);
2658 $widget->set_visible(1);
2659 $grid->attach($widget, 1, $row, 1, 1);
2660 $row++;
2661 }
2662
2663 return $grid;
2664 };
2665
2666 my $create_raid_disk_grid = sub {
2667 my $disk_labeled_widgets = [];
2668 for (my $i = 0; $i < @$hds; $i++) {
2669 my $disk_selector = Gtk3::ComboBoxText->new();
2670 $disk_selector->append_text("-- do not use --");
2671 $disk_selector->set_active(0);
2672 $disk_selector->set_visible(1);
2673 foreach my $hd (@$hds) {
2674 my ($disk, $devname, $size, $model) = @$hd;
2675 $disk_selector->append_text(get_device_desc ($devname, $size, $model));
2676 $disk_selector->{pve_disk_id} = $i;
2677 $disk_selector->signal_connect (changed => sub {
2678 my $w = shift;
2679 my $diskid = $w->{pve_disk_id};
2680 my $a = $w->get_active - 1;
2681 $config_options->{"disksel${diskid}"} = ($a >= 0) ? $hds->[$a] : undef;
2682 });
2683 }
2684
2685 if ($hdoption_first_setup) {
2686 $disk_selector->set_active ($i+1) if $hds->[$i];
2687 } else {
2688 my $hdind = 0;
2689 if (my $cur_hd = $config_options->{"disksel$i"}) {
2690 foreach my $hd (@$hds) {
2691 if (@$hd[1] eq @$cur_hd[1]) {
2692 $disk_selector->set_active($hdind+1);
2693 last;
2694 }
2695 $hdind++;
2696 }
2697 }
2698 }
2699
2700 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
2701 }
2702
2703 my $scrolled_window = Gtk3::ScrolledWindow->new();
2704 $scrolled_window->set_hexpand(1);
2705 $scrolled_window->set_propagate_natural_height(1) if @$hds > 4;
2706 $scrolled_window->add(&$create_label_widget_grid($disk_labeled_widgets));
2707 $scrolled_window->set_policy('never', 'automatic');
2708
2709 return $scrolled_window;
2710 # &$create_label_widget_grid($disk_labeled_widgets)
2711 };
2712
2713 # shared between different ui parts (e.g., ZFS and "normal" single disk FS)
2714 my $hdsize_size_adj;
2715 my $hdsize_entry_buffer;
2716
2717 my $get_hdsize_spinbtn = sub {
2718 my $hdsize = shift;
2719
2720 $hdsize_entry_buffer //= Gtk3::EntryBuffer->new(undef, 1);
2721
2722 if (defined($hdsize)) {
2723 $hdsize_size_adj = Gtk3::Adjustment->new($config_options->{hdsize} || $hdsize, 0, $hdsize+1, 1, 1, 1);
2724 } else {
2725 die "called get_hdsize_spinbtn with \$hdsize_size_adj not defined but did not pass hdsize!\n"
2726 if !defined($hdsize_size_adj);
2727 }
2728
2729 my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
2730 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
2731 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
2732 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
2733 return $spinbutton_hdsize;
2734 };
2735
2736 my $create_raid_advanced_grid = sub {
2737 my $labeled_widgets = [];
2738 my $spinbutton_ashift = Gtk3::SpinButton->new_with_range(9,13,1);
2739 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
2740 $spinbutton_ashift->signal_connect ("value-changed" => sub {
2741 my $w = shift;
2742 $config_options->{ashift} = $w->get_value_as_int();
2743 });
2744 $config_options->{ashift} = 12 if ! defined($config_options->{ashift});
2745 $spinbutton_ashift->set_value($config_options->{ashift});
2746 push @$labeled_widgets, "ashift";
2747 push @$labeled_widgets, $spinbutton_ashift;
2748
2749 my $combo_compress = Gtk3::ComboBoxText->new();
2750 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
2751 # note: gzip / lze not allowed for bootfs vdevs
2752 my $comp_opts = ["on","off","lzjb","lz4"];
2753 foreach my $opt (@$comp_opts) {
2754 $combo_compress->append($opt, $opt);
2755 }
2756 $config_options->{compress} = "on" if !defined($config_options->{compress});
2757 $combo_compress->set_active_id($config_options->{compress});
2758 $combo_compress->signal_connect (changed => sub {
2759 my $w = shift;
2760 $config_options->{compress} = $w->get_active_text();
2761 });
2762 push @$labeled_widgets, "compress";
2763 push @$labeled_widgets, $combo_compress;
2764
2765 my $combo_checksum = Gtk3::ComboBoxText->new();
2766 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
2767 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
2768 foreach my $opt (@$csum_opts) {
2769 $combo_checksum->append($opt, $opt);
2770 }
2771 $config_options->{checksum} = "on" if !($config_options->{checksum});
2772 $combo_checksum->set_active_id($config_options->{checksum});
2773 $combo_checksum->signal_connect (changed => sub {
2774 my $w = shift;
2775 $config_options->{checksum} = $w->get_active_text();
2776 });
2777 push @$labeled_widgets, "checksum";
2778 push @$labeled_widgets, $combo_checksum;
2779
2780 my $spinbutton_copies = Gtk3::SpinButton->new_with_range(1,3,1);
2781 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
2782 $spinbutton_copies->signal_connect ("value-changed" => sub {
2783 my $w = shift;
2784 $config_options->{copies} = $w->get_value_as_int();
2785 });
2786 $config_options->{copies} = 1 if !defined($config_options->{copies});
2787 $spinbutton_copies->set_value($config_options->{copies});
2788 push @$labeled_widgets, "copies", $spinbutton_copies;
2789
2790 push @$labeled_widgets, "hdsize", $get_hdsize_spinbtn->();
2791 return &$create_label_widget_grid($labeled_widgets);;
2792 };
2793
2794 sub create_hdoption_view {
2795
2796 my $dialog = Gtk3::Dialog->new();
2797
2798 $dialog->set_title("Harddisk options");
2799
2800 $dialog->add_button("_OK", 1);
2801
2802 my $contarea = $dialog->get_content_area();
2803
2804 my $hbox2 = Gtk3::Box->new('horizontal', 0);
2805 $contarea->pack_start($hbox2, 1, 1, 10);
2806
2807 my $grid = Gtk3::Grid->new();
2808 $grid->set_column_spacing(10);
2809 $grid->set_row_spacing(10);
2810
2811 $hbox2->pack_start($grid, 1, 0, 10);
2812
2813 my $row = 0;
2814
2815 # Filesystem type
2816
2817 my $label0 = Gtk3::Label->new("Filesystem");
2818 $label0->set_alignment (1, 0.5);
2819 $grid->attach($label0, 0, $row, 1, 1);
2820
2821 my $fstypecb = Gtk3::ComboBoxText->new();
2822
2823 my $fstype = ['ext3', 'ext4', 'xfs',
2824 'zfs (RAID0)', 'zfs (RAID1)',
2825 'zfs (RAID10)', 'zfs (RAIDZ-1)',
2826 'zfs (RAIDZ-2)', 'zfs (RAIDZ-3)'];
2827
2828 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
2829 if $setup->{enable_btrfs};
2830
2831 my $tcount = 0;
2832 foreach my $tmp (@$fstype) {
2833 $fstypecb->append_text($tmp);
2834 $fstypecb->set_active ($tcount)
2835 if $config_options->{filesys} eq $tmp;
2836 $tcount++;
2837 }
2838
2839 $grid->attach($fstypecb, 1, $row, 1, 1);
2840
2841 $hbox2->show_all();
2842
2843 $row++;
2844
2845 my $sep = Gtk3::HSeparator->new();
2846 $sep->set_visible(1);
2847 $grid->attach($sep, 0, $row, 2, 1);
2848 $row++;
2849
2850 my $hw_raid_note = Gtk3::Label->new("Note: ZFS is not compatible with disks backed by a hardware RAID controller. For details see the reference documentation.");
2851 $hw_raid_note->set_line_wrap(1);
2852 $hw_raid_note->set_max_width_chars(30);
2853 $hw_raid_note->set_visible(0);
2854 $grid->attach($hw_raid_note, 0, $row++, 2, 1);
2855
2856 my $hdsize_labeled_widgets = [];
2857
2858 # size compute
2859 my $hdsize = 0;
2860 if ( -b $target_hd) {
2861 $hdsize = int(hd_size ($target_hd) / (1024*1024.0)); # size in GB
2862 } elsif ($target_hd) {
2863 $hdsize = int((-s $target_hd) / (1024*1024*1024.0));
2864 }
2865
2866 my $spinbutton_hdsize = $get_hdsize_spinbtn->($hdsize);
2867 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize;
2868
2869 my $entry_swapsize = Gtk3::Entry->new();
2870 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
2871 $entry_swapsize->signal_connect (key_press_event => \&check_float);
2872 $entry_swapsize->set_text($config_options->{swapsize}) if defined($config_options->{swapsize});
2873 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
2874
2875 my $entry_maxroot = Gtk3::Entry->new();
2876 if ($setup->{product} eq 'pve') {
2877 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
2878 $entry_maxroot->signal_connect (key_press_event => \&check_float);
2879 $entry_maxroot->set_text($config_options->{maxroot}) if $config_options->{maxroot};
2880 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
2881 }
2882
2883 my $entry_minfree = Gtk3::Entry->new();
2884 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
2885 $entry_minfree->signal_connect (key_press_event => \&check_float);
2886 $entry_minfree->set_text($config_options->{minfree}) if defined($config_options->{minfree});
2887 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
2888
2889 my $entry_maxvz;
2890 if ($setup->{product} eq 'pve') {
2891 $entry_maxvz = Gtk3::Entry->new();
2892 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
2893 $entry_maxvz->signal_connect (key_press_event => \&check_float);
2894 $entry_maxvz->set_text($config_options->{maxvz}) if defined($config_options->{maxvz});
2895 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
2896 }
2897
2898 my $options_stack = Gtk3::Stack->new();
2899 $options_stack->set_visible(1);
2900 $options_stack->set_hexpand(1);
2901 $options_stack->set_vexpand(1);
2902 $options_stack->add_titled(&$create_raid_disk_grid(), "raiddisk", "Disk Setup");
2903 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
2904 $options_stack->add_titled(&$create_raid_advanced_grid("zfs"), "raidzfsadvanced", "Advanced Options");
2905 $options_stack->set_visible_child_name("raiddisk");
2906 my $options_stack_switcher = Gtk3::StackSwitcher->new();
2907 $options_stack_switcher->set_halign('center');
2908 $options_stack_switcher->set_stack($options_stack);
2909 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
2910 $row++;
2911 $grid->attach($options_stack, 0, $row, 2, 1);
2912 $row++;
2913
2914 $hdoption_first_setup = 0;
2915
2916 my $switch_view = sub {
2917 my $raid = $config_options->{filesys} =~ m/zfs|btrfs/;
2918 my $enable_zfs_opts = $config_options->{filesys} =~ m/zfs/;
2919
2920 $target_hd_combo->set_visible(!$raid);
2921 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
2922 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
2923 $hw_raid_note->set_visible($raid);
2924 $options_stack_switcher->set_visible($enable_zfs_opts);
2925 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($enable_zfs_opts);
2926 if ($raid) {
2927 $target_hd_label->set_text("Target: $config_options->{filesys} ");
2928 $options_stack->set_visible_child_name("raiddisk");
2929 } else {
2930 $target_hd_label->set_text("Target Harddisk: ");
2931 }
2932 my (undef, $pref_width) = $dialog->get_preferred_width();
2933 my (undef, $pref_height) = $dialog->get_preferred_height();
2934 $pref_height = 750 if $pref_height > 750;
2935 $dialog->resize($pref_width, $pref_height);
2936 };
2937
2938 &$switch_view();
2939
2940 $fstypecb->signal_connect (changed => sub {
2941 $config_options->{filesys} = $fstypecb->get_active_text();
2942 &$switch_view();
2943 });
2944
2945 my $sep2 = Gtk3::HSeparator->new();
2946 $sep2->set_visible(1);
2947 $contarea->pack_end($sep2, 1, 1, 10);
2948
2949 $dialog->show();
2950
2951 $dialog->run();
2952
2953 my $get_float = sub {
2954 my ($entry) = @_;
2955
2956 my $text = $entry->get_text();
2957 return undef if !defined($text);
2958
2959 $text =~ s/^\s+//;
2960 $text =~ s/\s+$//;
2961
2962 return undef if $text !~ m/^\d+(\.\d+)?$/;
2963
2964 return $text;
2965 };
2966
2967 my $tmp;
2968
2969 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
2970 $config_options->{hdsize} = $tmp;
2971 } else {
2972 delete $config_options->{hdsize};
2973 }
2974
2975 if (defined($tmp = &$get_float($entry_swapsize))) {
2976 $config_options->{swapsize} = $tmp;
2977 } else {
2978 delete $config_options->{swapsize};
2979 }
2980
2981 if (defined($tmp = &$get_float($entry_maxroot))) {
2982 $config_options->{maxroot} = $tmp;
2983 } else {
2984 delete $config_options->{maxroot};
2985 }
2986
2987 if (defined($tmp = &$get_float($entry_minfree))) {
2988 $config_options->{minfree} = $tmp;
2989 } else {
2990 delete $config_options->{minfree};
2991 }
2992
2993 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
2994 $config_options->{maxvz} = $tmp;
2995 } else {
2996 delete $config_options->{maxvz};
2997 }
2998
2999 $dialog->destroy();
3000 }
3001
3002 my $get_raid_devlist = sub {
3003
3004 my $dev_name_hash = {};
3005
3006 my $devlist = [];
3007 for (my $i = 0; $i < @$hds; $i++) {
3008 if (my $hd = $config_options->{"disksel$i"}) {
3009 my ($disk, $devname, $size, $model) = @$hd;
3010 die "device '$devname' is used more than once\n"
3011 if $dev_name_hash->{$devname};
3012 $dev_name_hash->{$devname} = $hd;
3013 push @$devlist, $hd;
3014 }
3015 }
3016
3017 return $devlist;
3018 };
3019
3020 sub zfs_mirror_size_check {
3021 my ($expected, $actual) = @_;
3022
3023 die "mirrored disks must have same size\n"
3024 if abs($expected - $actual) > $expected / 10;
3025 }
3026
3027 sub get_zfs_raid_setup {
3028
3029 my $filesys = $config_options->{filesys};
3030
3031 my $devlist = &$get_raid_devlist();
3032
3033 my $diskcount = scalar(@$devlist);
3034 die "$filesys needs at least one device\n" if $diskcount < 1;
3035
3036 my $bootdevlist = [];
3037
3038 my $cmd= '';
3039 if ($filesys eq 'zfs (RAID0)') {
3040 push @$bootdevlist, @$devlist[0];
3041 foreach my $hd (@$devlist) {
3042 $cmd .= " @$hd[1]";
3043 }
3044 } elsif ($filesys eq 'zfs (RAID1)') {
3045 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
3046 $cmd .= ' mirror ';
3047 my $hd = @$devlist[0];
3048 my $expected_size = @$hd[2]; # all disks need approximately same size
3049 foreach $hd (@$devlist) {
3050 zfs_mirror_size_check($expected_size, @$hd[2]);
3051 $cmd .= " @$hd[1]";
3052 push @$bootdevlist, $hd;
3053 }
3054 } elsif ($filesys eq 'zfs (RAID10)') {
3055 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
3056 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
3057
3058 push @$bootdevlist, @$devlist[0], @$devlist[1];
3059
3060 for (my $i = 0; $i < $diskcount; $i+=2) {
3061 my $hd1 = @$devlist[$i];
3062 my $hd2 = @$devlist[$i+1];
3063 zfs_mirror_size_check(@$hd1[2], @$hd2[2]); # pairs need approximately same size
3064 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
3065 }
3066
3067 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
3068 my $level = $1;
3069 my $mindisks = 2 + $level;
3070 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
3071 my $hd = @$devlist[0];
3072 my $expected_size = @$hd[2]; # all disks need approximately same size
3073 $cmd .= " raidz$level";
3074 foreach $hd (@$devlist) {
3075 zfs_mirror_size_check($expected_size, @$hd[2]);
3076 $cmd .= " @$hd[1]";
3077 push @$bootdevlist, $hd;
3078 }
3079 } else {
3080 die "unknown zfs mode '$filesys'\n";
3081 }
3082
3083 return ($devlist, $bootdevlist, $cmd);
3084 }
3085
3086 sub get_btrfs_raid_setup {
3087
3088 my $filesys = $config_options->{filesys};
3089
3090 my $devlist = &$get_raid_devlist();
3091
3092 my $diskcount = scalar(@$devlist);
3093 die "$filesys needs at least one device\n" if $diskcount < 1;
3094
3095 my $mode;
3096
3097 if ($diskcount == 1) {
3098 $mode = 'single';
3099 } else {
3100 if ($filesys eq 'btrfs (RAID0)') {
3101 $mode = 'raid0';
3102 } elsif ($filesys eq 'btrfs (RAID1)') {
3103 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
3104 $mode = 'raid1';
3105 } elsif ($filesys eq 'btrfs (RAID10)') {
3106 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
3107 $mode = 'raid10';
3108 } else {
3109 die "unknown btrfs mode '$filesys'\n";
3110 }
3111 }
3112
3113 return ($devlist, $mode);
3114 }
3115
3116 my $last_hd_selected = 0;
3117 sub create_hdsel_view {
3118
3119 $prev_btn->set_sensitive(1); # enable previous button at this point
3120
3121 cleanup_view();
3122
3123 my $vbox = Gtk3::VBox->new(0, 0);
3124 $inbox->pack_start($vbox, 1, 0, 0);
3125 my $hbox = Gtk3::HBox->new(0, 0);
3126 $vbox->pack_start($hbox, 0, 0, 10);
3127
3128 my ($disk, $devname, $size, $model) = @{@$hds[0]};
3129 $target_hd = $devname if !defined($target_hd);
3130
3131 $target_hd_label = Gtk3::Label->new("Target Harddisk: ");
3132 $hbox->pack_start($target_hd_label, 0, 0, 0);
3133
3134 $target_hd_combo = Gtk3::ComboBoxText->new();
3135
3136 foreach my $hd (@$hds) {
3137 ($disk, $devname, $size, $model) = @$hd;
3138 $target_hd_combo->append_text (get_device_desc($devname, $size, $model));
3139 }
3140
3141 my $raid = $config_options->{filesys} =~ m/zfs|btrfs/;
3142 if ($raid) {
3143 $target_hd_label->set_text("Target: $config_options->{filesys} ");
3144 $target_hd_combo->set_visible(0);
3145 $target_hd_combo->set_no_show_all(1);
3146 }
3147 $target_hd_combo->set_active($last_hd_selected);
3148 $target_hd_combo->signal_connect(changed => sub {
3149 $a = shift->get_active;
3150 my ($disk, $devname) = @{@$hds[$a]};
3151 $last_hd_selected = $a;
3152 $target_hd = $devname;
3153 });
3154
3155 $hbox->pack_start($target_hd_combo, 0, 0, 10);
3156
3157 my $options = Gtk3::Button->new('_Options');
3158 $options->signal_connect (clicked => \&create_hdoption_view);
3159 $hbox->pack_start ($options, 0, 0, 0);
3160
3161
3162 $inbox->show_all;
3163
3164 display_html();
3165
3166 set_next(undef, sub {
3167
3168 if ($config_options->{filesys} =~ m/zfs/) {
3169 my ($devlist) = eval { get_zfs_raid_setup() };
3170 if (my $err = $@) {
3171 display_message("Warning: $err\nPlease fix ZFS setup first.");
3172 return;
3173 }
3174 $config_options->{target_hds} = [ map { $_->[1] } @$devlist ];
3175 } elsif ($config_options->{filesys} =~ m/btrfs/) {
3176 my ($devlist) = eval { get_btrfs_raid_setup() };
3177 if (my $err = $@) {
3178 display_message("Warning: $err\nPlease fix BTRFS setup first.");
3179 return;
3180 }
3181 $config_options->{target_hds} = [ map { $_->[1] } @$devlist ];
3182 } else {
3183 $config_options->{target_hds} = [ $target_hd ];
3184 }
3185
3186 $step_number++;
3187 create_country_view();
3188 });
3189 }
3190
3191 sub create_extract_view {
3192
3193 cleanup_view();
3194
3195 display_info();
3196
3197 $next->set_sensitive(0);
3198 $prev_btn->set_sensitive(0);
3199 $prev_btn->hide();
3200
3201 my $vbox = Gtk3::VBox->new(0, 0);
3202 $inbox->pack_start ($vbox, 1, 0, 0);
3203 my $hbox = Gtk3::HBox->new(0, 0);
3204 $vbox->pack_start ($hbox, 0, 0, 10);
3205
3206 my $vbox2 = Gtk3::VBox->new(0, 0);
3207 $hbox->pack_start ($vbox2, 0, 0, 0);
3208
3209 $progress_status = Gtk3::Label->new('');
3210 $vbox2->pack_start ($progress_status, 1, 1, 0);
3211
3212 $progress = Gtk3::ProgressBar->new;
3213 $progress->set_show_text(1);
3214 $progress->set_size_request (600, -1);
3215
3216 $vbox2->pack_start($progress, 0, 0, 0);
3217
3218 $inbox->show_all();
3219
3220 my $tdir = $opt_testmode ? "target" : "/target";
3221 mkdir $tdir;
3222 my $base = "${proxmox_cddir}/$setup->{product}-base.squashfs";
3223
3224 eval { extract_data($base, $tdir); };
3225 my $err = $@;
3226
3227 $next->set_sensitive(1);
3228
3229 set_next("_Reboot", sub { exit (0); } );
3230
3231 if ($err) {
3232 display_html("fail.htm");
3233 display_error($err);
3234 } else {
3235 cleanup_view();
3236 display_html("success.htm");
3237 }
3238 }
3239
3240 sub create_intro_view {
3241
3242 $prev_btn->set_sensitive(0);
3243
3244 cleanup_view();
3245
3246 if (int($total_memory) < 1024) {
3247 my $fullname = $product_fullname->{$setup->{product}};
3248
3249 display_error("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
3250 "See 'System Requirements' in the $fullname documentation.");
3251 }
3252
3253 if ($setup->{product} eq 'pve') {
3254 eval {
3255 my $cpuinfo = file_get_contents('/proc/cpuinfo');
3256 if ($cpuinfo && !($cpuinfo =~ /^flags\s*:.*(vmx|svm)/m)) {
3257 display_error("No support for KVM virtualization detected.\n\n" .
3258 "Check BIOS settings for Intel VT / AMD-V / SVM.")
3259 }
3260 };
3261 }
3262
3263 display_html();
3264
3265 $step_number++;
3266 set_next("I a_gree", \&create_hdsel_view);
3267 }
3268
3269 $ipconf = get_ip_config();
3270
3271 $country = detect_country() if $ipconf->{default} || $opt_testmode;
3272
3273 # read country, kmap and timezone infos
3274 $cmap = read_cmap();
3275
3276 if (!defined($cmap->{country}->{$country})) {
3277 print $logfd "ignoring detected country '$country', invalid or unknown\n";
3278 $country = undef;
3279 }
3280
3281 create_main_window ();
3282
3283 my $initial_error = 0;
3284
3285 if (!defined ($hds) || (scalar (@$hds) <= 0)) {
3286 print "no hardisks found\n";
3287 $initial_error = 1;
3288 display_html("nohds.htm");
3289 set_next("Reboot", sub { exit(0); } );
3290 } else {
3291 foreach my $hd (@$hds) {
3292 my ($disk, $devname) = @$hd;
3293 next if $devname =~ m|^/dev/md\d+$|;
3294 print "found Disk$disk N:$devname\n";
3295 }
3296 }
3297
3298 if (!$initial_error && (scalar keys %{ $ipconf->{ifaces} } == 0)) {
3299 print "no network interfaces found\n";
3300 $initial_error = 1;
3301 display_html("nonics.htm");
3302 set_next("Reboot", sub { exit(0); } );
3303 }
3304
3305 create_intro_view () if !$initial_error;
3306
3307 Gtk3->main;
3308
3309 exit 0;