]> git.proxmox.com Git - pve-installer.git/blob - proxinstall
proxinstall: cleanup imports
[pve-installer.git] / proxinstall
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Getopt::Long;
7 use IO::File;
8 use Glib;
9 use Gtk3;
10 use Gtk3::WebKit2;
11 use POSIX ":sys_wait_h";
12 use JSON;
13
14 use Proxmox::Log;
15 Proxmox::Log::init("/tmp/install.log");
16
17 { # NOTE: order is important here
18 my $test_image;
19 GetOptions(
20 'test-image|t=s' => \$test_image
21 ) or die "usage error\n";
22
23 Proxmox::Install::ISOEnv::set_test_image($test_image) if $test_image;
24 }
25
26
27 use Proxmox::Install::ISOEnv;
28 use Proxmox::Install::RunEnv;
29
30 # init singletons
31 my $iso_env = Proxmox::Install::ISOEnv::get();
32 my $run_env = Proxmox::Install::RunEnv::get();
33
34 use Proxmox::Install;
35 use Proxmox::Install::Config;
36 use Proxmox::Install::StorageConfig;
37
38 use Proxmox::Sys::Block qw(get_cached_disks);
39 use Proxmox::Sys::Command qw(syscmd);
40 use Proxmox::Sys::File qw(file_read_all file_write_all);
41 use Proxmox::Sys::Net qw(parse_ip_address parse_ip_mask);
42 use Proxmox::UI;
43
44 if (!$ENV{G_SLICE} || $ENV{G_SLICE} ne "always-malloc") {
45 die "do not use slice allocator (run with 'G_SLICE=always-malloc ./proxinstall ...')\n";
46 }
47
48 my $step_number = 0; # Init number for global function list
49
50 my @steps = (
51 {
52 step => 'intro',
53 html => 'license.htm',
54 next_button => 'I a_gree',
55 function => \&create_intro_view,
56 },
57 {
58 step => 'intro',
59 html => 'page1.htm',
60 function => \&create_hdsel_view,
61 },
62 {
63 step => 'country',
64 html => 'country.htm',
65 function => \&create_country_view,
66 },
67 {
68 step => 'password',
69 html => 'passwd.htm',
70 function => \&create_password_view,
71 },
72 {
73 step => 'ipconf',
74 html => 'ipconf.htm',
75 function => \&create_ipconf_view,
76 },
77 {
78 step => 'ack',
79 html => 'ack.htm',
80 next_button => '_Install',
81 function => \&create_ack_view,
82 },
83 {
84 step => 'extract',
85 next_button => '_Reboot',
86 function => \&create_extract_view,
87 },
88 );
89
90 # GUI global variables
91 my $gtk_state = {};
92
93 my $target_hds; # only for the summary view
94 my $autoreboot_seconds = 5;
95
96 sub app_quit {
97 my ($exit_code) = @_;
98
99 Gtk3->main_quit() if Gtk3->main_level() > 0;
100
101 # reap left over zombie processes
102 while ((my $child = waitpid(-1, POSIX::WNOHANG)) > 0) {
103 print STDERR "reaped child $child\n";
104 }
105 exit($exit_code);
106 }
107
108 sub prev_function {
109 my ($text, $fctn) = @_;
110
111 $fctn = $step_number if !$fctn;
112 $text = "_Previous" if !$text;
113 $gtk_state->{prev_btn}->set_label($text);
114
115 $step_number--;
116 $steps[$step_number]->{function}();
117
118 $gtk_state->{prev_btn}->grab_focus();
119 }
120
121 sub set_next {
122 my ($text, $fctn) = @_;
123
124 $gtk_state->{next_btn_callback} = $fctn;
125 my $step = $steps[$step_number];
126 $text //= $steps[$step_number]->{next_button} // '_Next';
127 $gtk_state->{next_btn}->set_label($text);
128
129 $gtk_state->{next_btn}->grab_focus();
130 }
131
132 sub create_main_window {
133
134 my $window = Gtk3::Window->new();
135 $window->set_default_size(1024, 768);
136 $window->signal_connect(map => sub { $window->set_resizable(0); });
137 $window->fullscreen() if !is_test_mode();
138 $window->set_decorated(0) if !is_test_mode();
139 $window->signal_connect(destroy => sub { Gtk3->main_quit(); });
140
141 my $vbox = Gtk3::Box->new('vertical', 0);
142
143 my $logofn = "$iso_env->{product}-banner.png";
144 my $proxmox_libdir = $iso_env->{locations}->{lib};
145 my $image = Gtk3::Image->new_from_file("${proxmox_libdir}/$logofn");
146
147 my $provider = Gtk3::CssProvider->new();
148 my $theming = "* {\nbackground: #171717;\n}";
149 $provider->load_from_data ([map ord, split //, $theming]);
150 my $context = $image->get_style_context();
151 $context->add_provider($provider, 600);
152
153 $vbox->pack_start($image, 0, 0, 0);
154
155 my $hbox = Gtk3::Box->new('horizontal', 0);
156 $vbox->pack_start($hbox, 1, 1, 0);
157
158 # my $f1 = Gtk3::Frame->new ('test');
159 # $f1->set_shadow_type ('none');
160 # $hbox->pack_start ($f1, 1, 1, 0);
161
162 my $sep1 = Gtk3::Separator->new('horizontal');
163 $vbox->pack_start($sep1, 0, 0, 0);
164
165 my $cmdbox = Gtk3::Box->new('horizontal', 0);
166 $vbox->pack_start($cmdbox, 0, 0, 10);
167
168 my $next_btn = Gtk3::Button->new('_Next');
169 $next_btn->signal_connect(clicked => sub {
170 Proxmox::Install::reset_last_display_change();
171 $gtk_state->{next_btn_callback}->();
172 });
173 $cmdbox->pack_end($next_btn, 0, 0, 10);
174
175 my $prev_btn = Gtk3::Button->new('_Previous');
176 $prev_btn->signal_connect(clicked => sub {
177 Proxmox::Install::reset_last_display_change();
178 prev_function();
179 });
180 $cmdbox->pack_end($prev_btn, 0, 0, 10);
181
182
183 my $abort = Gtk3::Button->new('_Abort');
184 $abort->set_can_focus(0);
185 $cmdbox->pack_start($abort, 0, 0, 10);
186 $abort->signal_connect(clicked => sub { app_quit(-1); });
187
188 my $vbox2 = Gtk3::Box->new('vertical', 0);
189 $hbox->add($vbox2);
190
191 my $html_view = Gtk3::WebKit2::WebView->new();
192 $html_view->set_hexpand(1);
193 my $scrolls = Gtk3::ScrolledWindow->new();
194 $scrolls->add($html_view);
195
196 my $hbox2 = Gtk3::Box->new('horizontal', 0);
197 $hbox2->pack_start($scrolls, 1, 1, 0);
198
199 $vbox2->pack_start($hbox2, 1, 1, 0);
200
201 my $vbox3 = Gtk3::Box->new('vertical', 0);
202 $vbox2->pack_start($vbox3, 0, 0, 0);
203
204 my $sep2 = Gtk3::Separator->new('horizontal');
205 $vbox3->pack_start($sep2, 0, 0, 0);
206
207 my $inbox = Gtk3::Box->new('horizontal', 0);
208 $vbox3->pack_start($inbox, 0, 0, 0);
209
210 $window->add($vbox);
211
212 $gtk_state->{window} = $window;
213 $gtk_state->{html_view} = $html_view;
214 $gtk_state->{inbox} = $inbox;
215 $gtk_state->{prev_btn} = $prev_btn;
216 $gtk_state->{next_btn} = $next_btn;
217 $gtk_state->{progress_bar} = Gtk3::ProgressBar->new();
218 $gtk_state->{progress_status} = Gtk3::Label->new('');
219
220 Proxmox::UI::init_gtk($gtk_state, $iso_env);
221
222 $window->show_all;
223 $window->present();
224 }
225
226 sub cleanup_view {
227 $gtk_state->{inbox}->foreach(sub {
228 my $child = shift;
229 $gtk_state->{inbox}->remove ($child);
230 });
231 }
232
233 # fixme: newer GTK3 has special properties to handle numbers with Entry
234 # only allow floating point numbers with Gtk3::Entry
235
236 sub check_float {
237 my ($entry, $event) = @_;
238
239 return check_number($entry, $event, 1);
240 }
241
242 sub check_int {
243 my ($entry, $event) = @_;
244
245 return check_number($entry, $event, 0);
246 }
247
248 sub check_number {
249 my ($entry, $event, $float) = @_;
250
251 my $val = $event->get_keyval;
252
253 if (($float && $val == ord '.') ||
254 $val == Gtk3::Gdk::KEY_ISO_Left_Tab ||
255 $val == Gtk3::Gdk::KEY_Shift_L ||
256 $val == Gtk3::Gdk::KEY_Tab ||
257 $val == Gtk3::Gdk::KEY_Left ||
258 $val == Gtk3::Gdk::KEY_Right ||
259 $val == Gtk3::Gdk::KEY_BackSpace ||
260 $val == Gtk3::Gdk::KEY_Delete ||
261 ($val >= ord '0' && $val <= ord '9') ||
262 ($val >= Gtk3::Gdk::KEY_KP_0 &&
263 $val <= Gtk3::Gdk::KEY_KP_9)) {
264 return undef;
265 }
266
267 return 1;
268 }
269
270 sub create_text_input {
271 my ($default, $text) = @_;
272
273 my $hbox = Gtk3::Box->new('horizontal', 0);
274
275 my $label = Gtk3::Label->new($text);
276 $label->set_size_request(150, -1);
277 $label->set_xalign(1.0);
278 $hbox->pack_start($label, 0, 0, 10);
279 my $e1 = Gtk3::Entry->new();
280 $e1->set_width_chars(35);
281 $hbox->pack_start($e1, 0, 0, 0);
282 $e1->set_text($default);
283
284 return ($hbox, $e1);
285 }
286 sub create_cidr_inputs {
287 my ($cidr) = @_;
288
289 my ($default_ip, $default_mask) = split('/', $cidr);
290
291 my $hbox = Gtk3::Box->new('horizontal', 0);
292
293 my $label = Gtk3::Label->new('IP Address (CIDR)');
294 $label->set_size_request(150, -1);
295 $label->set_xalign(1.0);
296 $hbox->pack_start($label, 0, 0, 10);
297
298 my $ip_el = Gtk3::Entry->new();
299 $ip_el->set_width_chars(28);
300 $hbox->pack_start($ip_el, 0, 0, 0);
301 $ip_el->set_text($default_ip);
302
303 $label = Gtk3::Label->new('/');
304 $label->set_size_request(10, -1);
305 $hbox->pack_start($label, 0, 0, 2);
306
307 my $cidr_el = Gtk3::Entry->new();
308 $cidr_el->set_width_chars(3);
309 $hbox->pack_start($cidr_el, 0, 0, 0);
310 $cidr_el->set_text($default_mask);
311
312 return ($hbox, $ip_el, $cidr_el);
313 }
314
315 my $ipconf_first_view = 1;
316
317 sub create_ipconf_view {
318
319 cleanup_view();
320 Proxmox::UI::display_html('ipconf.htm');
321
322 my $vcontainer = Gtk3::Box->new('vertical', 0);
323 $gtk_state->{inbox}->pack_start($vcontainer, 1, 0, 0);
324 my $hcontainer = Gtk3::Box->new('horizontal', 0);
325 $vcontainer->pack_start($hcontainer, 0, 0, 10);
326 my $vbox = Gtk3::Box->new('vertical', 0);
327 $hcontainer->add($vbox);
328
329 my $cidr = Proxmox::Install::Config::get_cidr() // '192.168.100.2/24';
330
331 my ($cidr_box, $ipconf_entry_addr, $ipconf_entry_mask) = create_cidr_inputs($cidr);
332
333 my $device_cb = Gtk3::ComboBoxText->new();
334 $device_cb->set_active(0);
335 $device_cb->set_visible(1);
336
337 my $get_device_desc = sub {
338 my $iface = shift;
339 return "$iface->{name} - $iface->{mac} ($iface->{driver})";
340 };
341
342 my $ipconf = $run_env->{ipconf};
343
344 my ($device_active_map, $device_active_reverse_map) = ({}, {});
345
346 my $device_change_handler = sub {
347 my $current = shift;
348
349 my $new = $device_active_map->{$current->get_active()};
350 my $selected = Proxmox::Install::Config::get_mngmt_nic_id();
351 return if defined($selected) && $new eq $selected;
352
353 Proxmox::Install::Config::set_mngmt_nic_id($new);
354 my $iface = $ipconf->{ifaces}->{$new};
355 Proxmox::Install::Config::set_mngmt_nic($iface->{name});
356 $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
357 if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
358 $ipconf_entry_mask->set_text($iface->{inet}->{prefix} || $iface->{inet6}->{prefix})
359 if $iface->{inet}->{prefix} || $iface->{inet6}->{prefix};
360 };
361
362 my $i = 0;
363 for my $index (sort keys $ipconf->{ifaces}->%*) {
364 my $iface = $ipconf->{ifaces}->{$index};
365 $device_cb->append_text($get_device_desc->($iface));
366 $device_active_map->{$i} = $index;
367 $device_active_reverse_map->{$iface->{name}} = $i;
368 if ($ipconf_first_view && $index == $ipconf->{default}) {
369 $device_cb->set_active($i);
370 &$device_change_handler($device_cb);
371 $ipconf_first_view = 0;
372 }
373 $device_cb->signal_connect('changed' => $device_change_handler);
374 $i++;
375 }
376
377 if (my $nic = Proxmox::Install::Config::get_mngmt_nic()) {
378 $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
379 } else {
380 $device_cb->set_active(0);
381 }
382
383 my $devicebox = Gtk3::Box->new('horizontal', 0);
384 my $label = Gtk3::Label->new("Management Interface:");
385 $label->set_size_request(150, -1);
386 $label->set_xalign(1.0);
387 $devicebox->pack_start($label, 0, 0, 10);
388 $devicebox->pack_start($device_cb, 0, 0, 0);
389
390 $vbox->pack_start($devicebox, 0, 0, 2);
391
392 my $fqdn = Proxmox::Install::Config::get_fqdn();
393 my $hn = $fqdn // "$iso_env->{product}." . ($ipconf->{domain} // "example.invalid");
394
395 my ($hostbox, $hostentry) = create_text_input($hn, 'Hostname (FQDN):');
396 $vbox->pack_start($hostbox, 0, 0, 2);
397
398 $vbox->pack_start($cidr_box, 0, 0, 2);
399
400 my $cfg_gateway = Proxmox::Install::Config::get_gateway();
401 my $gateway = $cfg_gateway // $ipconf->{gateway} || '192.168.100.1';
402
403 my ($gwbox, $ipconf_entry_gw) = create_text_input($gateway, 'Gateway:');
404 $vbox->pack_start($gwbox, 0, 0, 2);
405
406 my $cfg_dns = Proxmox::Install::Config::get_dns();
407 my $dnsserver = $cfg_dns // $ipconf->{dnsserver} || $gateway;
408
409 my ($dnsbox, $ipconf_entry_dns) = create_text_input($dnsserver, 'DNS Server:');
410
411 $vbox->pack_start($dnsbox, 0, 0, 0);
412
413 $gtk_state->{inbox}->show_all;
414 set_next(undef, sub {
415 # verify hostname
416 my $text = $hostentry->get_text();
417 $text =~ s/^\s+//;
418 $text =~ s/\s+$//;
419
420 my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
421
422 # Debian does not support purely numeric hostnames
423 if ($text && $text =~ /^[0-9]+(?:\.|$)/) {
424 Proxmox::UI::message("Purely numeric hostnames are not allowed.");
425 $hostentry->grab_focus();
426 return;
427 }
428
429 if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
430 $text =~ m/^([^\.]+)\.(\S+)$/) {
431 Proxmox::Install::Config::set_hostname($1);
432 Proxmox::Install::Config::set_domain($2);
433 } else {
434 Proxmox::UI::message("Hostname does not look like a fully qualified domain name.");
435 $hostentry->grab_focus();
436 return;
437 }
438
439 # verify ip address
440 $text = $ipconf_entry_addr->get_text();
441 my ($ipaddress, $ipversion) = parse_ip_address($text);
442 if (!defined($ipaddress)) {
443 Proxmox::UI::message("IP address is not valid.");
444 $ipconf_entry_addr->grab_focus();
445 return;
446 }
447
448 $text = $ipconf_entry_mask->get_text();
449 my $netmask = parse_ip_mask($text, $ipversion);
450 if (!defined($netmask)) {
451 Proxmox::UI::message("Netmask is not valid.");
452 $ipconf_entry_mask->grab_focus();
453 return;
454 }
455 Proxmox::Install::Config::set_cidr("$ipaddress/$netmask");
456
457 $text = $ipconf_entry_gw->get_text();
458 my ($gateway_ip, $gateway_ip_version) = parse_ip_address($text);
459 if (!defined($gateway_ip) || $gateway_ip_version != $ipversion) {
460 my $msg = defined($gateway_ip)
461 ? "Gateway and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
462 : "Gateway is not valid.";
463 Proxmox::UI::message($msg);
464 $ipconf_entry_gw->grab_focus();
465 return;
466 }
467 Proxmox::Install::Config::set_gateway($gateway_ip);
468
469 $text = $ipconf_entry_dns->get_text();
470 my ($dns_ip, $dns_ip_version) = parse_ip_address($text);
471 if (!defined($dns_ip) || $dns_ip_version != $ipversion) {
472 my $msg = defined($gateway_ip)
473 ? "DNS and host IP version must not differ (IPv$gateway_ip_version != IPv$ipversion)."
474 : "DNS IP is not valid.";
475 Proxmox::UI::message($msg);
476 $ipconf_entry_dns->grab_focus();
477 return;
478 }
479 Proxmox::Install::Config::set_dns($dns_ip);
480
481 #print STDERR "TEST $ipaddress/$netmask $gateway_ip $dns_ip\n";
482
483 $step_number++;
484 create_ack_view();
485 });
486
487 $hostentry->grab_focus();
488 }
489
490 sub create_ack_view {
491
492 cleanup_view();
493
494 my $vbox = Gtk3::Box->new('vertical', 0);
495 $gtk_state->{inbox}->pack_start($vbox, 1, 0, 0);
496
497 my $reboot_checkbox = Gtk3::CheckButton->new('Automatically reboot after successful installation');
498 $reboot_checkbox->set_active(1);
499 $reboot_checkbox->signal_connect ("toggled" => sub {
500 my $cb = shift;
501 Proxmox::Install::Config::set_autoreboot(!!$cb->get_active());
502 });
503 $vbox->pack_start($reboot_checkbox, 0, 0, 2);
504
505 my $proxmox_libdir = $iso_env->{locations}->{lib};
506 my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
507 my $ack_html = "${proxmox_libdir}/html/$iso_env->{product}/$steps[$step_number]->{html}";
508 my $html_data = file_read_all($ack_template);
509
510 my $country = Proxmox::Install::Config::get_country();
511
512 my %config_values = (
513 __target_hd__ => join(' | ', $target_hds->@*),
514 __target_fs__ => Proxmox::Install::Config::get_filesys(),
515 __country__ => $iso_env->{locales}->{country}->{$country}->{name},
516 __timezone__ => Proxmox::Install::Config::get_timezone(),
517 __keymap__ => Proxmox::Install::Config::get_keymap(),
518 __mailto__ => Proxmox::Install::Config::get_mailto(),
519 __interface__ => Proxmox::Install::Config::get_mngmt_nic(),
520 __hostname__ => Proxmox::Install::Config::get_hostname(),
521 __cidr__ => Proxmox::Install::Config::get_cidr(),
522 __gateway__ => Proxmox::Install::Config::get_gateway(),
523 __dnsserver__ => Proxmox::Install::Config::get_dns(),
524 );
525
526 while (my ($k, $v) = each %config_values) {
527 $html_data =~ s/$k/$v/g;
528 }
529
530 eval {
531 my $config = Proxmox::Install::Config::get();
532 file_write_all(
533 "$iso_env->{locations}->{run}/config-ack.json",
534 to_json($config, { utf8 => 1, canonical => 1 }) ."\n",
535 );
536 };
537 warn "failed to write config-for-ack - $@" if $@;
538
539 file_write_all($ack_html, $html_data);
540
541 Proxmox::UI::display_html('ack.htm');
542
543 $gtk_state->{inbox}->show_all;
544
545 set_next(undef, sub {
546 $step_number++;
547 create_extract_view();
548 });
549 }
550
551 sub get_device_desc {
552 my ($devname, $size, $model) = @_;
553
554 if ($size && ($size > 0)) {
555 $size = int($size/2048); # size in MiB, from 512B "sectors"
556
557 my $text = "$devname (";
558 if ($size >= 1024) {
559 $size = $size/1024; # size in GiB
560 if ($size >= 1024) {
561 $size = $size/1024; # size in TiB
562 $text .= sprintf("%.2f", $size) . "TiB";
563 } else {
564 $text .= sprintf("%.2f", $size) . "GiB";
565 }
566 } else {
567 $text .= "${size}MiB";
568 }
569
570 $text .= ", $model" if $model;
571 $text .= ")";
572 return $text;
573
574 } else {
575 return $devname;
576 }
577 }
578
579 my $last_layout;
580 my $country_layout;
581 sub update_layout {
582 my ($cb, $kmap) = @_;
583
584 my $ind;
585 my $def;
586 my $i = 0;
587 my $kmaphash = $iso_env->{locales}->{kmaphash};
588 foreach my $layout (sort keys %$kmaphash) {
589 $def = $i if $kmaphash->{$layout} eq 'en-us';
590 $ind = $i if $kmap && $kmaphash->{$layout} eq $kmap;
591 $i++;
592 }
593
594 my $val = $ind || $def || 0;
595
596 if (!defined($kmap)) {
597 $last_layout //= $val;
598 } elsif (!defined($country_layout) || $country_layout != $val) {
599 $last_layout = $country_layout = $val;
600 }
601 $cb->set_active($last_layout);
602 }
603
604 my $lastzonecb;
605 sub update_zonelist {
606 my ($box, $cc) = @_;
607
608 my $sel = Proxmox::Install::Config::get_timezone(); # initial default
609 if ($lastzonecb) {
610 $sel = $lastzonecb->get_active_text();
611 $box->remove($lastzonecb);
612 }
613
614 my $cb = $lastzonecb = Gtk3::ComboBoxText->new();
615 $cb->set_size_request(200, -1);
616 $cb->signal_connect('changed' => sub {
617 my $timezone = $cb->get_active_text();
618 Proxmox::Install::Config::set_timezone($timezone);
619 });
620
621 my ($cczones, $zones) = $iso_env->{locales}->@{'cczones', 'zones'};
622 my @available_zones = $cc && defined($cczones->{$cc}) ? keys %{$cczones->{$cc}} : keys %$zones;
623
624 my ($i, $selected_index) = (0, undef);
625 for my $zone (sort @available_zones) {
626 $selected_index = $i if $sel && $zone eq $sel;
627 $cb->append_text($zone);
628 $i++;
629 }
630
631 # Append UTC here, so it is always the last item and never the default for any country.
632 $cb->append_text('UTC');
633
634 $cb->set_active($selected_index || 0);
635
636 $cb->show;
637 $box->pack_start($cb, 0, 0, 0);
638 }
639
640 sub create_password_view {
641
642 cleanup_view();
643
644 my $password = Proxmox::Install::Config::get_password();
645
646 my $vbox2 = Gtk3::Box->new('vertical', 0);
647 $gtk_state->{inbox}->pack_start($vbox2, 1, 0, 0);
648 my $vbox = Gtk3::Box->new('vertical', 0);
649 $vbox2->pack_start($vbox, 0, 0, 10);
650
651 my $hbox1 = Gtk3::Box->new('horizontal', 0);
652 my $label = Gtk3::Label->new("Password");
653 $label->set_size_request(150, -1);
654 $label->set_xalign(1.0);
655 $hbox1->pack_start($label, 0, 0, 10);
656 my $pwe1 = Gtk3::Entry->new();
657 $pwe1->set_visibility(0);
658 $pwe1->set_text($password) if $password;
659 $pwe1->set_size_request(200, -1);
660 $hbox1->pack_start($pwe1, 0, 0, 0);
661
662 my $hbox2 = Gtk3::Box->new('horizontal', 0);
663 $label = Gtk3::Label->new("Confirm");
664 $label->set_size_request(150, -1);
665 $label->set_xalign(1.0);
666 $hbox2->pack_start($label, 0, 0, 10);
667 my $pwe2 = Gtk3::Entry->new();
668 $pwe2->set_visibility(0);
669 $pwe2->set_text($password) if $password;
670 $pwe2->set_size_request(200, -1);
671 $hbox2->pack_start($pwe2, 0, 0, 0);
672
673 my $hbox3 = Gtk3::Box->new('horizontal', 0);
674 $label = Gtk3::Label->new("Email");
675 $label->set_size_request(150, -1);
676 $label->set_xalign(1.0);
677 $hbox3->pack_start($label, 0, 0, 10);
678 my $eme = Gtk3::Entry->new();
679 $eme->set_size_request(200, -1);
680 $eme->set_text(Proxmox::Install::Config::get_mailto());
681 $hbox3->pack_start($eme, 0, 0, 0);
682
683
684 $vbox->pack_start($hbox1, 0, 0, 5);
685 $vbox->pack_start($hbox2, 0, 0, 5);
686 $vbox->pack_start($hbox3, 0, 0, 15);
687
688 $gtk_state->{inbox}->show_all;
689
690 Proxmox::UI::display_html('passwd.htm');
691
692 set_next (undef, sub {
693
694 my $t1 = $pwe1->get_text;
695 my $t2 = $pwe2->get_text;
696
697 if (length ($t1) < 5) {
698 Proxmox::UI::message("Password is too short.");
699 $pwe1->grab_focus();
700 return;
701 }
702
703 if ($t1 ne $t2) {
704 Proxmox::UI::message("Password does not match.");
705 $pwe1->grab_focus();
706 return;
707 }
708
709 my $t3 = $eme->get_text;
710 if ($t3 !~ m/^[\w\+\-\~]+(\.[\w\+\-\~]+)*@[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$/) {
711 Proxmox::UI::message("Email does not look like a valid address (user\@domain.tld)");
712 $eme->grab_focus();
713 return;
714 }
715
716 if ($t3 eq 'mail@example.invalid') {
717 Proxmox::UI::message("Please enter a valid Email address");
718 $eme->grab_focus();
719 return;
720 }
721
722 Proxmox::Install::Config::set_password($t1);
723 Proxmox::Install::Config::set_mailto($t3);
724
725 $step_number++;
726 create_ipconf_view();
727 });
728
729 $pwe1->grab_focus();
730
731 }
732
733 my $installer_kmap;
734 sub create_country_view {
735
736 cleanup_view();
737
738 my $locales = $iso_env->{locales};
739
740 my $vbox2 = Gtk3::Box->new('vertical', 0);
741 $gtk_state->{inbox}->pack_start($vbox2, 1, 0, 0);
742 my $vbox = Gtk3::Box->new('vertical', 0);
743 $vbox2->pack_start($vbox, 0, 0, 10);
744
745 my $w = Gtk3::Entry->new();
746 $w->set_size_request(200, -1);
747
748 my $c = Gtk3::EntryCompletion->new();
749 $c->set_text_column(0);
750 $c->set_minimum_key_length(0);
751 $c->set_popup_set_width(1);
752 $c->set_inline_completion(1);
753
754 my $hbox2 = Gtk3::Box->new('horizontal', 0);
755 my $label = Gtk3::Label->new("Time zone");
756 $label->set_size_request(150, -1);
757 $label->set_xalign(1.0);
758 $hbox2->pack_start($label, 0, 0, 10);
759 update_zonelist ($hbox2);
760
761 my $hbox3 = Gtk3::Box->new('horizontal', 0);
762 $label = Gtk3::Label->new("Keyboard Layout");
763 $label->set_size_request(150, -1);
764 $label->set_xalign(1.0);
765 $hbox3->pack_start($label, 0, 0, 10);
766
767 my $kmapcb = Gtk3::ComboBoxText->new();
768 $kmapcb->set_size_request (200, -1);
769 for my $layout (sort keys %{$locales->{kmaphash}}) {
770 $kmapcb->append_text($layout);
771 }
772
773 update_layout($kmapcb);
774 $hbox3->pack_start ($kmapcb, 0, 0, 0);
775
776 $kmapcb->signal_connect ('changed' => sub {
777 my $sel = $kmapcb->get_active_text();
778 $last_layout = $kmapcb->get_active();
779 if (my $kmap = $locales->{kmaphash}->{$sel}) {
780 my $xkmap = $locales->{kmap}->{$kmap}->{x11};
781 my $xvar = $locales->{kmap}->{$kmap}->{x11var};
782
783 Proxmox::Install::Config::set_keymap($kmap);
784
785 return if (defined($installer_kmap) && $installer_kmap eq $kmap);
786 $installer_kmap = $kmap;
787
788 if (!is_test_mode()) {
789 syscmd("setxkbmap $xkmap $xvar");
790
791 my $kbd_config = qq{
792 XKBLAYOUT="$xkmap"
793 XKBVARIANT="$xvar"
794 BACKSPACE="guess"
795 };
796 $kbd_config =~ s/^\s+//gm;
797
798 Proxmox::Sys::Command::run_in_background(sub {
799 file_write_all('/etc/default/keyboard', $kbd_config);
800 system("setupcon");
801 });
802 }
803 }
804 });
805
806 $w->signal_connect ('changed' => sub {
807 my ($entry, $event) = @_;
808 my $text = $entry->get_text;
809
810 if (my $cc = $locales->{countryhash}->{lc($text)}) {
811 update_zonelist($hbox2, $cc);
812 my $kmap = $locales->{country}->{$cc}->{kmap} || 'en-us';
813 update_layout($kmapcb, $kmap);
814 }
815 });
816
817 $w->signal_connect (key_press_event => sub {
818 my ($entry, $event) = @_;
819 my $text = $entry->get_text;
820
821 my $val = $event->get_keyval;
822
823 if ($val == Gtk3::Gdk::KEY_Tab) {
824 my $cc = $locales->{countryhash}->{lc($text)};
825
826 my $found = 0;
827 my $compl;
828
829 if ($cc) {
830 $found = 1;
831 $compl = $locales->{country}->{$cc}->{name};
832 } else {
833 for my $country (values $locales->{country}->%*) {
834 if ($country->{name} =~ m/^\Q$text\E.*$/i) {
835 $found++;
836 $compl = $country->{name};
837 }
838 last if $found > 1;
839 }
840 }
841
842 if ($found == 1) {
843 $entry->set_text($compl);
844 $c->complete();
845 return undef;
846 } else {
847 # beep ?
848 }
849
850 $c->complete();
851
852 my $buf = $w->get_buffer();
853 $buf->insert_text(-1, '', -1); # popup selection
854
855 return 1;
856 }
857
858 return undef;
859 });
860
861 my $country_store = Gtk3::ListStore->new('Glib::String');
862 my $countries = $locales->{country};
863 for my $cc (sort { $countries->{$a}->{name} cmp $countries->{$b}->{name} } keys %$countries) {
864 my $iter = $country_store->append();
865 $country_store->set($iter, 0, $countries->{$cc}->{name});
866 }
867 $c->set_model($country_store);
868
869 $w->set_completion ($c);
870
871 my $hbox = Gtk3::Box->new('horizontal', 0);
872
873 $label = Gtk3::Label->new("Country");
874 $label->set_xalign(1.0);
875 $label->set_size_request(150, -1);
876 $hbox->pack_start($label, 0, 0, 10);
877 $hbox->pack_start($w, 0, 0, 0);
878
879 $vbox->pack_start($hbox, 0, 0, 5);
880 $vbox->pack_start($hbox2, 0, 0, 5);
881 $vbox->pack_start($hbox3, 0, 0, 5);
882
883 my $country = Proxmox::Install::Config::get_country();
884 if ($country && (my $entry = $locales->{country}->{$country})) {
885 $w->set_text($entry->{name});
886 }
887
888 $gtk_state->{inbox}->show_all;
889
890 Proxmox::UI::display_html('country.htm');
891 set_next (undef, sub {
892
893 my $text = $w->get_text;
894
895 if (my $cc = $locales->{countryhash}->{lc($text)}) {
896 Proxmox::Install::Config::set_country($cc);
897 $step_number++;
898 create_password_view();
899 return;
900 } else {
901 Proxmox::UI::message("Please select a country first.");
902 $w->grab_focus();
903 }
904 });
905
906 $w->grab_focus();
907 }
908
909 my $target_hd_combo;
910 my $target_hd_label;
911
912 my $hdoption_first_setup = 1;
913
914 my $create_basic_grid = sub {
915 my $grid = Gtk3::Grid->new();
916 $grid->set_visible(1);
917 $grid->set_column_spacing(10);
918 $grid->set_row_spacing(10);
919 $grid->set_hexpand(1);
920
921 $grid->set_margin_start(10);
922 $grid->set_margin_end(20);
923 $grid->set_margin_top(5);
924 $grid->set_margin_bottom(5);
925
926 return $grid;
927 };
928
929 my $create_label_widget_grid = sub {
930 my ($labeled_widgets) = @_;
931
932 my $grid = &$create_basic_grid();
933 my $row = 0;
934
935 for (my $i = 0; $i < @$labeled_widgets; $i += 2) {
936 my $widget = @$labeled_widgets[$i+1];
937 my $label = Gtk3::Label->new(@$labeled_widgets[$i]);
938 $label->set_visible(1);
939 $label->set_xalign(1.0);
940 $grid->attach($label, 0, $row, 1, 1);
941 $widget->set_visible(1);
942 $grid->attach($widget, 1, $row, 1, 1);
943 $row++;
944 }
945
946 return $grid;
947 };
948
949 # only relevant for raid with its multipl diskX to diskY mappings.
950 my $get_selected_hdsize = sub {
951 my $hdsize = shift;
952 return $hdsize if defined($hdsize);
953
954 # compute the smallest disk size of the actually selected disks
955 my $cached_disks = get_cached_disks();
956 my $disk_count = scalar(@$cached_disks);
957 for (my $i = 0; $i < $disk_count; $i++) {
958 next if !Proxmox::Install::Config::get_disk_selection($i);
959 my $cur_hd = $cached_disks->[$i];
960 my $disksize = int(@$cur_hd[2] / (2 * 1024 * 1024.0)); # size in GB
961 $hdsize //= $disksize;
962 $hdsize = $disksize if $disksize < $hdsize;
963 }
964
965 if (my $cfg_hdsize = Proxmox::Install::Config::get_hdsize()) {
966 # had the dialog open previously and set an even lower size than the disk selection allows
967 $hdsize = $cfg_hdsize if $cfg_hdsize < $hdsize;
968 }
969 return $hdsize // 0; # fall back to zero, e.g., if none is selected hdsize cannot be any size
970 };
971
972 my sub update_hdsize_adjustment {
973 my ($adjustment, $hdsize) = @_;
974
975 $hdsize = $get_selected_hdsize->($hdsize);
976 # expect that lower = 0 and step increments = 1 still are valid
977 $adjustment->set_upper($hdsize + 1);
978 $adjustment->set_value($hdsize);
979 }
980
981 my sub create_hdsize_adjustment {
982 my ($hdsize) = @_;
983 $hdsize = $get_selected_hdsize->($hdsize);
984 my $cfg_hdsize = Proxmox::Install::Config::get_hdsize();
985 # params are: initial value, lower, upper, step increment, page increment, page size
986 return Gtk3::Adjustment->new($cfg_hdsize || $hdsize, 0, $hdsize+1, 1, 1, 1);
987 }
988
989 my sub get_hdsize_spin_button {
990 my $hdsize = shift;
991
992 my $hdsize_entry_buffer = Gtk3::EntryBuffer->new(undef, 1);
993 my $hdsize_size_adj = create_hdsize_adjustment($hdsize);
994
995 my $spinbutton_hdsize = Gtk3::SpinButton->new($hdsize_size_adj, 1, 1);
996 $spinbutton_hdsize->set_buffer($hdsize_entry_buffer);
997 $spinbutton_hdsize->set_adjustment($hdsize_size_adj);
998 $spinbutton_hdsize->set_tooltip_text("only use specified size (GB) of the harddisk (rest left unpartitioned)");
999 return $spinbutton_hdsize;
1000 };
1001
1002 my $create_raid_disk_grid = sub {
1003 my ($hdsize_buttons) = @_;
1004
1005 my $cached_disks = get_cached_disks();
1006 my $disk_count = scalar(@$cached_disks);
1007 my $disk_labeled_widgets = [];
1008 for (my $i = 0; $i < $disk_count; $i++) {
1009 my $disk_selector = Gtk3::ComboBoxText->new();
1010 $disk_selector->append_text("-- do not use --");
1011 $disk_selector->set_active(0);
1012 $disk_selector->set_visible(1);
1013
1014 for my $hd (@$cached_disks) {
1015 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
1016 $disk_selector->append_text(get_device_desc($devname, $size, $model));
1017 }
1018
1019 $disk_selector->{pve_disk_id} = $i;
1020 $disk_selector->signal_connect(changed => sub {
1021 my $w = shift;
1022 my $diskid = $w->{pve_disk_id};
1023 my $a = $w->get_active - 1;
1024 Proxmox::Install::Config::set_disk_selection($diskid, $a >= 0);
1025 for my $btn (@$hdsize_buttons) {
1026 update_hdsize_adjustment($btn->get_adjustment());
1027 }
1028 });
1029
1030 if ($hdoption_first_setup) {
1031 $disk_selector->set_active ($i+1) if $cached_disks->[$i];
1032 } else {
1033 my $hdind = 0;
1034 if (Proxmox::Install::Config::get_disk_selection($i)) {
1035 my $cur_hd = $cached_disks->[$i];
1036 foreach my $hd (@$cached_disks) {
1037 if (@$hd[1] eq @$cur_hd[1]) {
1038 $disk_selector->set_active($hdind+1);
1039 last;
1040 }
1041 $hdind++;
1042 }
1043 }
1044 }
1045
1046 push @$disk_labeled_widgets, "Harddisk $i", $disk_selector;
1047 }
1048
1049 my $clear_all_button = Gtk3::Button->new('_Deselect All');
1050 if ($disk_count > 3) {
1051 $clear_all_button->signal_connect('clicked', sub {
1052 my $is_widget = 0;
1053 for my $disk_selector (@$disk_labeled_widgets) {
1054 $disk_selector->set_active(0) if $is_widget;
1055 $is_widget ^= 1;
1056 }
1057 });
1058 $clear_all_button->set_visible(1);
1059 }
1060
1061 my $scrolled_window = Gtk3::ScrolledWindow->new();
1062 $scrolled_window->set_hexpand(1);
1063 $scrolled_window->set_propagate_natural_height(1) if $disk_count > 4;
1064
1065 my $diskgrid = $create_label_widget_grid->($disk_labeled_widgets);
1066
1067 $scrolled_window->add($diskgrid);
1068 $scrolled_window->set_policy('never', 'automatic');
1069 $scrolled_window->set_visible(1);
1070 $scrolled_window->set_min_content_height(190);
1071
1072 my $vbox = Gtk3::Box->new('vertical', 0);
1073 $vbox->pack_start($scrolled_window, 1, 1, 10);
1074
1075 my $hbox = Gtk3::Box->new('horizontal', 0);
1076 $hbox->pack_end($clear_all_button, 0, 0, 20);
1077 $hbox->set_visible(1);
1078 $vbox->pack_end($hbox, 0, 0, 0);
1079
1080 return $vbox;
1081 };
1082
1083 my $create_raid_advanced_grid = sub {
1084 my ($hdsize_btn) = @_;
1085 my $labeled_widgets = [];
1086 my $spinbutton_ashift = Gtk3::SpinButton->new_with_range(9, 13, 1);
1087 $spinbutton_ashift->set_tooltip_text("zpool ashift property (pool sector size, default 2^12)");
1088 $spinbutton_ashift->signal_connect ("value-changed" => sub {
1089 my $w = shift;
1090 Proxmox::Install::Config::set_zfs_opt('ashift', $w->get_value_as_int());
1091 });
1092 my $ashift = Proxmox::Install::Config::get_zfs_opt('ashift') // 12;
1093 $spinbutton_ashift->set_value($ashift);
1094 push @$labeled_widgets, "ashift";
1095 push @$labeled_widgets, $spinbutton_ashift;
1096
1097 my $combo_compress = Gtk3::ComboBoxText->new();
1098 $combo_compress->set_tooltip_text("zfs compression algorithm for rpool dataset");
1099 my $comp_opts = ["on","off","lzjb","lz4", "zle", "gzip", "zstd"];
1100 foreach my $opt (@$comp_opts) {
1101 $combo_compress->append($opt, $opt);
1102 }
1103 my $compress = Proxmox::Install::Config::get_zfs_opt('compress') // 'on';
1104 $combo_compress->set_active_id($compress);
1105 $combo_compress->signal_connect (changed => sub {
1106 my $w = shift;
1107 Proxmox::Install::Config::set_zfs_opt('compress', $w->get_active_text());
1108 });
1109 push @$labeled_widgets, "compress";
1110 push @$labeled_widgets, $combo_compress;
1111
1112 my $combo_checksum = Gtk3::ComboBoxText->new();
1113 $combo_checksum->set_tooltip_text("zfs checksum algorithm for rpool dataset");
1114 my $csum_opts = ["on", "off","fletcher2", "fletcher4", "sha256"];
1115 foreach my $opt (@$csum_opts) {
1116 $combo_checksum->append($opt, $opt);
1117 }
1118 my $checksum = Proxmox::Install::Config::get_zfs_opt('checksum') // 'on';
1119 $combo_checksum->set_active_id($checksum);
1120 $combo_checksum->signal_connect (changed => sub {
1121 my $w = shift;
1122 Proxmox::Install::Config::set_zfs_opt('checksum', $w->get_active_text());
1123 });
1124 push @$labeled_widgets, "checksum";
1125 push @$labeled_widgets, $combo_checksum;
1126
1127 my $spinbutton_copies = Gtk3::SpinButton->new_with_range(1,3,1);
1128 $spinbutton_copies->set_tooltip_text("zfs copies property for rpool dataset (in addition to RAID redundancy!)");
1129 $spinbutton_copies->signal_connect ("value-changed" => sub {
1130 my $w = shift;
1131 Proxmox::Install::Config::set_zfs_opt('copies', $w->get_value_as_int());
1132 });
1133 my $copies = Proxmox::Install::Config::get_zfs_opt('copies') // 1;
1134 $spinbutton_copies->set_value($copies);
1135 push @$labeled_widgets, "copies", $spinbutton_copies;
1136
1137 push @$labeled_widgets, "hdsize", $hdsize_btn;
1138 return $create_label_widget_grid->($labeled_widgets);;
1139 };
1140
1141 my $create_btrfs_raid_advanced_grid = sub {
1142 my ($hdsize_btn) = @_;
1143 my $labeled_widgets = [];
1144 push @$labeled_widgets, "hdsize", $hdsize_btn;
1145 return $create_label_widget_grid->($labeled_widgets);;
1146 };
1147
1148 sub create_hdoption_view {
1149 my $dialog = Gtk3::Dialog->new();
1150
1151 $dialog->set_title("Harddisk options");
1152
1153 $dialog->add_button("_OK", 1);
1154
1155 my $contarea = $dialog->get_content_area();
1156
1157 my $hbox2 = Gtk3::Box->new('horizontal', 0);
1158 $contarea->pack_start($hbox2, 1, 1, 5);
1159
1160 my $grid = Gtk3::Grid->new();
1161 $grid->set_column_spacing(10);
1162 $grid->set_row_spacing(10);
1163
1164 $hbox2->pack_start($grid, 1, 0, 5);
1165
1166 my $row = 0;
1167
1168 # Filesystem type
1169 my $label0 = Gtk3::Label->new("Filesystem");
1170 $label0->set_xalign(1.0);
1171 $grid->attach($label0, 0, $row, 1, 1);
1172
1173 my $fstypecb = Gtk3::ComboBoxText->new();
1174 my $fstype = [
1175 'ext4',
1176 'xfs',
1177 'zfs (RAID0)',
1178 'zfs (RAID1)',
1179 'zfs (RAID10)',
1180 'zfs (RAIDZ-1)',
1181 'zfs (RAIDZ-2)',
1182 'zfs (RAIDZ-3)',
1183 ];
1184 push @$fstype, 'btrfs (RAID0)', 'btrfs (RAID1)', 'btrfs (RAID10)'
1185 if $iso_env->{cfg}->{enable_btrfs};
1186
1187 my $filesys = Proxmox::Install::Config::get_filesys();
1188 my $tcount = 0;
1189 foreach my $tmp (@$fstype) {
1190 $fstypecb->append_text($tmp);
1191 $fstypecb->set_active ($tcount) if $filesys eq $tmp;
1192 $tcount++;
1193 }
1194
1195 $grid->attach($fstypecb, 1, $row, 1, 1);
1196
1197 $hbox2->show_all();
1198
1199 $row++;
1200
1201 my $sep = Gtk3::Separator->new('horizontal');
1202 $sep->set_visible(1);
1203 $grid->attach($sep, 0, $row, 2, 1);
1204 $row++;
1205
1206 my $hw_raid_note = Gtk3::Label->new(""); # text will be set below, before making it visible
1207 $hw_raid_note->set_line_wrap(1);
1208 $hw_raid_note->set_max_width_chars(30);
1209 $hw_raid_note->set_visible(0);
1210 $grid->attach($hw_raid_note, 0, $row++, 2, 1);
1211
1212 my $hdsize_labeled_widgets = [];
1213
1214 my $target_hd = Proxmox::Install::Config::get_target_hd();
1215 my $hdsize = 0; # size compute
1216 if ( -b $target_hd) {
1217 $hdsize = int(Proxmox::Sys::Block::hd_size($target_hd) / (1024 * 1024.0)); # size in GB
1218 } elsif ($target_hd) {
1219 $hdsize = int((-s $target_hd) / (1024 * 1024 * 1024.0));
1220 }
1221
1222 my $spinbutton_hdsize_nonraid = get_hdsize_spin_button($hdsize);
1223 push @$hdsize_labeled_widgets, "hdsize", $spinbutton_hdsize_nonraid;
1224 my $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
1225
1226 my $entry_swapsize = Gtk3::Entry->new();
1227 $entry_swapsize->set_tooltip_text("maximum SWAP size (GB)");
1228 $entry_swapsize->signal_connect (key_press_event => \&check_float);
1229 my $swapsize = Proxmox::Install::Config::get_swapsize();
1230 $entry_swapsize->set_text($swapsize) if defined($swapsize);
1231 push @$hdsize_labeled_widgets, "swapsize", $entry_swapsize;
1232
1233 my $entry_maxroot = Gtk3::Entry->new();
1234 if ($iso_env->{product} eq 'pve') {
1235 $entry_maxroot->set_tooltip_text("maximum size (GB) for LVM root volume");
1236 $entry_maxroot->signal_connect (key_press_event => \&check_float);
1237 if (my $maxroot = Proxmox::Install::Config::get_maxroot()) {
1238 $entry_maxroot->set_text($maxroot);
1239 }
1240 push @$hdsize_labeled_widgets, "maxroot", $entry_maxroot;
1241 }
1242
1243 my $entry_minfree = Gtk3::Entry->new();
1244 $entry_minfree->set_tooltip_text("minimum free LVM space (GB, required for LVM snapshots)");
1245 $entry_minfree->signal_connect (key_press_event => \&check_float);
1246 if (defined(my $minfree = Proxmox::Install::Config::get_minfree())) {
1247 $entry_minfree->set_text($minfree);
1248 }
1249 push @$hdsize_labeled_widgets, "minfree", $entry_minfree;
1250
1251 my $entry_maxvz;
1252 if ($iso_env->{product} eq 'pve') {
1253 $entry_maxvz = Gtk3::Entry->new();
1254 $entry_maxvz->set_tooltip_text("maximum size (GB) for LVM data volume");
1255 $entry_maxvz->signal_connect (key_press_event => \&check_float);
1256 if (defined(my $maxvz = Proxmox::Install::Config::get_maxvz())) {
1257 $entry_maxvz->set_text($maxvz);
1258 }
1259 push @$hdsize_labeled_widgets, "maxvz", $entry_maxvz;
1260 }
1261
1262 my $spinbutton_hdsize_zfs = get_hdsize_spin_button($hdsize);
1263 my $spinbutton_hdsize_btrfs = get_hdsize_spin_button($hdsize);
1264 my $hdsize_buttons = [ $spinbutton_hdsize_zfs, $spinbutton_hdsize_btrfs ];
1265 my $options_stack = Gtk3::Stack->new();
1266 $options_stack->set_visible(1);
1267 $options_stack->set_hexpand(1);
1268 $options_stack->set_vexpand(1);
1269 $options_stack->add_titled(&$create_raid_disk_grid($hdsize_buttons), "raiddisk", "Disk Setup");
1270 $options_stack->add_titled(&$create_label_widget_grid($hdsize_labeled_widgets), "hdsize", "Size Options");
1271 $options_stack->add_titled(&$create_raid_advanced_grid($spinbutton_hdsize_zfs), "raidzfsadvanced", "Advanced Options");
1272 $options_stack->add_titled(&$create_btrfs_raid_advanced_grid($spinbutton_hdsize_btrfs), "raidbtrfsadvanced", "Advanced Options");
1273 $options_stack->set_visible_child_name("raiddisk");
1274 my $options_stack_switcher = Gtk3::StackSwitcher->new();
1275 $options_stack_switcher->set_halign('center');
1276 $options_stack_switcher->set_stack($options_stack);
1277 $grid->attach($options_stack_switcher, 0, $row, 2, 1);
1278 $row++;
1279 $grid->attach($options_stack, 0, $row, 2, 1);
1280 $row++;
1281
1282 $hdoption_first_setup = 0;
1283
1284 my $switch_view = sub {
1285 my $filesys = Proxmox::Install::Config::get_filesys();
1286 my $raid = $filesys =~ m/zfs|btrfs/;
1287 my $is_zfs = $filesys =~ m/zfs/;
1288
1289 $target_hd_combo->set_visible(!$raid);
1290 $options_stack->get_child_by_name("hdsize")->set_visible(!$raid);
1291 $options_stack->get_child_by_name("raiddisk")->set_visible($raid);
1292
1293 if ($raid) {
1294 my $msg = "<b>Note</b>: " . ($is_zfs
1295 ? "ZFS is not compatible with hardware RAID controllers, for details see the documentation."
1296 : "BTRFS integration in $iso_env->{cfg}->{fullname} is a technology preview!"
1297 );
1298 $hw_raid_note->set_markup($msg);
1299 }
1300 $hw_raid_note->set_visible($raid);
1301 $options_stack_switcher->set_visible($raid);
1302 $options_stack->get_child_by_name("raidzfsadvanced")->set_visible($is_zfs);
1303 $options_stack->get_child_by_name("raidbtrfsadvanced")->set_visible(!$is_zfs);
1304 if ($raid) {
1305 $target_hd_label->set_text("Target: $filesys ");
1306 $options_stack->set_visible_child_name("raiddisk");
1307 } else {
1308 $target_hd_label->set_text("Target Harddisk: ");
1309 }
1310
1311 if ($raid) {
1312 $spinbutton_hdsize = $is_zfs ? $spinbutton_hdsize_zfs : $spinbutton_hdsize_btrfs;
1313 } else {
1314 $spinbutton_hdsize = $spinbutton_hdsize_nonraid;
1315 }
1316
1317 my (undef, $pref_width) = $dialog->get_preferred_width();
1318 my (undef, $pref_height) = $dialog->get_preferred_height();
1319 $pref_height = 750 if $pref_height > 750;
1320 $dialog->resize($pref_width, $pref_height);
1321 };
1322
1323 &$switch_view();
1324
1325 $fstypecb->signal_connect (changed => sub {
1326 my $new_filesys = $fstypecb->get_active_text();
1327 Proxmox::Install::Config::set_filesys($new_filesys);
1328 &$switch_view();
1329 });
1330
1331 my $sep2 = Gtk3::Separator->new('horizontal');
1332 $sep2->set_visible(1);
1333 $contarea->pack_end($sep2, 1, 1, 10);
1334
1335 $dialog->show();
1336
1337 $dialog->run();
1338
1339 my $get_float = sub {
1340 my ($entry) = @_;
1341
1342 my $text = $entry->get_text();
1343 return undef if !defined($text);
1344
1345 $text =~ s/^\s+//;
1346 $text =~ s/\s+$//;
1347
1348 return undef if $text !~ m/^\d+(\.\d+)?$/;
1349
1350 return $text;
1351 };
1352
1353 my $tmp;
1354
1355 if (($tmp = &$get_float($spinbutton_hdsize)) && ($tmp != $hdsize)) {
1356 Proxmox::Install::Config::set_hdsize($tmp);
1357 } else {
1358 Proxmox::Install::Config::set_hdsize(undef);
1359 }
1360
1361 if (defined($tmp = &$get_float($entry_swapsize))) {
1362 Proxmox::Install::Config::set_swapsize($tmp);
1363 } else {
1364 Proxmox::Install::Config::set_swapsize(undef);
1365 }
1366
1367 if (defined($tmp = &$get_float($entry_maxroot))) {
1368 Proxmox::Install::Config::set_maxroot($tmp);
1369 } else {
1370 Proxmox::Install::Config::set_maxroot(undef);
1371 }
1372
1373 if (defined($tmp = &$get_float($entry_minfree))) {
1374 Proxmox::Install::Config::set_minfree($tmp);
1375 } else {
1376 Proxmox::Install::Config::set_minfree(undef);
1377 }
1378
1379 if ($entry_maxvz && defined($tmp = &$get_float($entry_maxvz))) {
1380 Proxmox::Install::Config::set_maxvz($tmp);
1381 } else {
1382 Proxmox::Install::Config::set_maxvz(undef);
1383 }
1384
1385 $dialog->destroy();
1386 }
1387
1388 my $get_raid_devlist = sub {
1389
1390 my $dev_name_hash = {};
1391
1392 my $cached_disks = get_cached_disks();
1393 my $devlist = [];
1394 for (my $i = 0; $i < @$cached_disks; $i++) {
1395 next if !Proxmox::Install::Config::get_disk_selection($i);
1396
1397 my $hd = $cached_disks->[$i];
1398 my ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
1399 die "device '$devname' is used more than once\n" if $dev_name_hash->{$devname};
1400 $dev_name_hash->{$devname} = $hd;
1401 push @$devlist, $hd;
1402 }
1403
1404 return $devlist;
1405 };
1406
1407 sub zfs_mirror_size_check {
1408 my ($expected, $actual) = @_;
1409
1410 die "mirrored disks must have same size\n"
1411 if abs($expected - $actual) > $expected / 10;
1412 }
1413
1414 sub legacy_bios_4k_check {
1415 my ($lbs) = @_;
1416 die "Booting from 4kn drive in legacy BIOS mode is not supported.\n"
1417 if $run_env->{boot_type} ne 'efi' && $lbs == 4096;
1418 }
1419
1420 sub get_zfs_raid_setup {
1421 my $filesys = Proxmox::Install::Config::get_filesys();
1422
1423 my $devlist = &$get_raid_devlist();
1424
1425 my $diskcount = scalar(@$devlist);
1426 die "$filesys needs at least one device\n" if $diskcount < 1;
1427
1428 my $cmd= '';
1429 if ($filesys eq 'zfs (RAID0)') {
1430 foreach my $hd (@$devlist) {
1431 legacy_bios_4k_check(@$hd[4]);
1432 $cmd .= " @$hd[1]";
1433 }
1434 } elsif ($filesys eq 'zfs (RAID1)') {
1435 die "zfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
1436 $cmd .= ' mirror ';
1437 my $hd = @$devlist[0];
1438 my $expected_size = @$hd[2]; # all disks need approximately same size
1439 foreach my $hd (@$devlist) {
1440 zfs_mirror_size_check($expected_size, @$hd[2]);
1441 legacy_bios_4k_check(@$hd[4]);
1442 $cmd .= " @$hd[1]";
1443 }
1444 } elsif ($filesys eq 'zfs (RAID10)') {
1445 die "zfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
1446 die "zfs (RAID10) needs an even number of devices\n" if $diskcount & 1;
1447
1448 for (my $i = 0; $i < $diskcount; $i+=2) {
1449 my $hd1 = @$devlist[$i];
1450 my $hd2 = @$devlist[$i+1];
1451 zfs_mirror_size_check(@$hd1[2], @$hd2[2]); # pairs need approximately same size
1452 legacy_bios_4k_check(@$hd1[4]);
1453 legacy_bios_4k_check(@$hd2[4]);
1454 $cmd .= ' mirror ' . @$hd1[1] . ' ' . @$hd2[1];
1455 }
1456
1457 } elsif ($filesys =~ m/^zfs \(RAIDZ-([123])\)$/) {
1458 my $level = $1;
1459 my $mindisks = 2 + $level;
1460 die "zfs (RAIDZ-$level) needs at least $mindisks devices\n" if scalar(@$devlist) < $mindisks;
1461 my $hd = @$devlist[0];
1462 my $expected_size = @$hd[2]; # all disks need approximately same size
1463 $cmd .= " raidz$level";
1464 foreach my $hd (@$devlist) {
1465 zfs_mirror_size_check($expected_size, @$hd[2]);
1466 legacy_bios_4k_check(@$hd[4]);
1467 $cmd .= " @$hd[1]";
1468 }
1469 } else {
1470 die "unknown zfs mode '$filesys'\n";
1471 }
1472
1473 return ($devlist, $cmd);
1474 }
1475
1476 sub get_btrfs_raid_setup {
1477 my $filesys = Proxmox::Install::Config::get_filesys();
1478
1479 my $devlist = &$get_raid_devlist();
1480
1481 my $diskcount = scalar(@$devlist);
1482 die "$filesys needs at least one device\n" if $diskcount < 1;
1483
1484 my $mode;
1485
1486 if ($diskcount == 1) {
1487 $mode = 'single';
1488 } else {
1489 if ($filesys eq 'btrfs (RAID0)') {
1490 $mode = 'raid0';
1491 } elsif ($filesys eq 'btrfs (RAID1)') {
1492 die "btrfs (RAID1) needs at least 2 device\n" if $diskcount < 2;
1493 $mode = 'raid1';
1494 } elsif ($filesys eq 'btrfs (RAID10)') {
1495 die "btrfs (RAID10) needs at least 4 device\n" if $diskcount < 4;
1496 $mode = 'raid10';
1497 } else {
1498 die "unknown btrfs mode '$filesys'\n";
1499 }
1500 }
1501
1502 return ($devlist, $mode);
1503 }
1504
1505 my $last_hd_selected = 0;
1506 sub create_hdsel_view {
1507
1508 $gtk_state->{prev_btn}->set_sensitive(1); # enable previous button at this point
1509
1510 cleanup_view();
1511
1512 my $vbox = Gtk3::Box->new('vertical', 0);
1513 $gtk_state->{inbox}->pack_start($vbox, 1, 0, 0);
1514 my $hbox = Gtk3::Box->new('horizontal', 0);
1515 $vbox->pack_start($hbox, 0, 0, 10);
1516
1517 my $cached_disks = get_cached_disks();
1518 my ($disk, $devname, $size, $model, $logical_bsize) = $cached_disks->[0]->@*;
1519 if (!defined(Proxmox::Install::Config::get_target_hd())) {
1520 Proxmox::Install::Config::set_target_hd($devname);
1521 }
1522
1523 $target_hd_label = Gtk3::Label->new("Target Harddisk: ");
1524 $hbox->pack_start($target_hd_label, 0, 0, 0);
1525
1526 $target_hd_combo = Gtk3::ComboBoxText->new();
1527
1528 foreach my $hd ($cached_disks->@*) {
1529 ($disk, $devname, $size, $model, $logical_bsize) = @$hd;
1530 $target_hd_combo->append_text(get_device_desc($devname, $size, $model));
1531 }
1532
1533 my $raid = Proxmox::Install::Config::get_filesys() =~ m/zfs|btrfs/;
1534 if ($raid) {
1535 my $filesys = Proxmox::Install::Config::get_filesys();
1536 $target_hd_label->set_text("Target: $filesys ");
1537 $target_hd_combo->set_visible(0);
1538 $target_hd_combo->set_no_show_all(1);
1539 }
1540 $target_hd_combo->set_active($last_hd_selected);
1541 $target_hd_combo->signal_connect(changed => sub {
1542 $a = shift->get_active;
1543 my ($disk, $devname) = @{@$cached_disks[$a]};
1544 $last_hd_selected = $a;
1545 Proxmox::Install::Config::set_target_hd($devname);
1546 });
1547
1548 $hbox->pack_start($target_hd_combo, 0, 0, 10);
1549
1550 my $options = Gtk3::Button->new('_Options');
1551 $options->signal_connect (clicked => \&create_hdoption_view);
1552 $hbox->pack_start ($options, 0, 0, 0);
1553
1554
1555 $gtk_state->{inbox}->show_all;
1556
1557 Proxmox::UI::display_html('page1.htm');
1558
1559 set_next(undef, sub {
1560 my $filesys = Proxmox::Install::Config::get_filesys();
1561 if ($filesys =~ m/zfs/) {
1562 my ($devlist) = eval { get_zfs_raid_setup() };
1563 if (my $err = $@) {
1564 Proxmox::UI::message("Warning: $err\nPlease fix ZFS setup first.");
1565 return;
1566 }
1567 $target_hds = [ map { $_->[1] } @$devlist ];
1568 } elsif ($filesys =~ m/btrfs/) {
1569 my ($devlist) = eval { get_btrfs_raid_setup() };
1570 if (my $err = $@) {
1571 Proxmox::UI::message("Warning: $err\nPlease fix BTRFS setup first.");
1572 return;
1573 }
1574 $target_hds = [ map { $_->[1] } @$devlist ];
1575 } else {
1576 my $target_hd = Proxmox::Install::Config::get_target_hd();
1577 eval {
1578 my $target_block_size = Proxmox::Sys::Block::logical_blocksize($target_hd);
1579 legacy_bios_4k_check($target_block_size);
1580 };
1581 if (my $err = $@) {
1582 Proxmox::UI::message("Warning: $err\n");
1583 return;
1584 }
1585 $target_hds = [ $target_hd ];
1586 }
1587
1588 $step_number++;
1589 create_country_view();
1590 });
1591 }
1592
1593 sub create_extract_view {
1594 cleanup_view();
1595
1596 Proxmox::Install::display_info();
1597
1598 $gtk_state->{next_btn}->set_sensitive(0);
1599 $gtk_state->{prev_btn}->set_sensitive(0);
1600 $gtk_state->{prev_btn}->hide();
1601
1602 my $vbox = Gtk3::Box->new('vertical', 0);
1603 $gtk_state->{inbox}->pack_start ($vbox, 1, 0, 0);
1604 my $hbox = Gtk3::Box->new('horizontal', 0);
1605 $vbox->pack_start ($hbox, 0, 0, 10);
1606
1607 my $vbox2 = Gtk3::Box->new('vertical', 0);
1608 $hbox->pack_start ($vbox2, 0, 0, 0);
1609
1610 $vbox2->pack_start($gtk_state->{progress_status}, 1, 1, 0);
1611
1612 $gtk_state->{progress_bar}->set_show_text(1);
1613 $gtk_state->{progress_bar}->set_size_request (600, -1);
1614
1615 $vbox2->pack_start($gtk_state->{progress_bar}, 0, 0, 0);
1616
1617 $gtk_state->{inbox}->show_all();
1618
1619 eval { Proxmox::Install::extract_data() };
1620 my $err = $@;
1621
1622 $gtk_state->{next_btn}->set_sensitive(1);
1623
1624 set_next("_Reboot", sub { app_quit(0); } );
1625
1626 my $autoreboot = Proxmox::Install::Config::get_autoreboot();
1627 my $success_transform = sub {
1628 my ($raw_html, $iso_env) = @_;
1629
1630 my $ip_addr = Proxmox::Install::Config::get_ip_addr();
1631 my $ip_version = Proxmox::Install::Config::get_ip_version();
1632
1633 my $addr = $ip_version == 6 ? "[${ip_addr}]" : "$ip_addr";
1634 $raw_html =~ s/__IPADDR__/$addr/g;
1635 $raw_html =~ s/__PORT__/$iso_env->{cfg}->{port}/g;
1636
1637 my $autoreboot_msg = $autoreboot ? "Automatic reboot scheduled in $autoreboot_seconds seconds." : '';
1638 $raw_html =~ s/__AUTOREBOOT_MSG__/$autoreboot_msg/;
1639
1640 return $raw_html;
1641 };
1642
1643 if ($err) {
1644 Proxmox::UI::display_html("fail.htm");
1645 # suppress "empty" error as we got some case where the user choose to abort on a prompt,
1646 # there it doesn't make sense to show them an error again, they "caused" it after all.
1647 Proxmox::UI::error($err) if $err ne "\n";
1648 } else {
1649 cleanup_view();
1650 Proxmox::UI::display_html("success.htm", $success_transform);
1651
1652 if ($autoreboot) {
1653 Glib::Timeout->add(1000, sub {
1654 if ($autoreboot_seconds > 0) {
1655 $autoreboot_seconds--;
1656 Proxmox::UI::display_html("success.htm", $success_transform);
1657 } else {
1658 app_quit(0);
1659 }
1660 });
1661 }
1662 }
1663 }
1664
1665 sub create_intro_view {
1666
1667 $gtk_state->{prev_btn}->set_sensitive(0);
1668
1669 cleanup_view();
1670
1671 if (int($run_env->{total_memory}) < 1024) {
1672 Proxmox::UI::error("Less than 1 GiB of usable memory detected, installation will probably fail.\n\n".
1673 "See 'System Requirements' in the $iso_env->{cfg}->{fullname} documentation.");
1674 }
1675
1676 if ($iso_env->{product} eq 'pve') {
1677 my $cpuinfo = eval { file_read_all('/proc/cpuinfo') };
1678 if (!$cpuinfo || $cpuinfo !~ /^flags\s*:.*(vmx|svm)/m) {
1679 Proxmox::UI::error(
1680 "No support for hardware-accelerated KVM virtualization detected.\n\n"
1681 ."Check BIOS settings for Intel VT / AMD-V / SVM."
1682 );
1683 }
1684 }
1685
1686 Proxmox::UI::display_html('license.htm', sub {
1687 my ($raw_html, $iso_env) = @_;
1688
1689 my $proxmox_cddir = $iso_env->{locations}->{iso};
1690 my $license = eval { decode('utf8', file_read_all("${proxmox_cddir}/EULA")) };
1691 if (my $err = $@) {
1692 die $err if !is_test_mode();
1693 $license = "TESTMODE: Ignore non existent EULA...\n";
1694 }
1695 my $title = "END USER LICENSE AGREEMENT (EULA)";
1696 $raw_html =~ s/__LICENSE__/$license/;
1697 $raw_html =~ s/__LICENSE_TITLE__/$title/;
1698
1699 return $raw_html;
1700 });
1701
1702 $step_number++;
1703 set_next("I a_gree", \&create_hdsel_view);
1704 }
1705
1706 Gtk3::init();
1707
1708 create_main_window ();
1709
1710 my $initial_error = 0;
1711
1712 {
1713 my $cached_disks = get_cached_disks();
1714 if (!defined($cached_disks) || (scalar (@$cached_disks) <= 0)) {
1715 print STDERR "no harddisks found\n";
1716 $initial_error = 1;
1717 Proxmox::UI::display_html("nohds.htm");
1718 set_next("Reboot", sub { app_quit(0); } );
1719 } else {
1720 foreach my $hd (@$cached_disks) {
1721 my ($disk, $devname) = @$hd;
1722 next if $devname =~ m|^/dev/md\d+$|;
1723 print STDERR "found Disk$disk N:$devname\n";
1724 }
1725 }
1726 }
1727
1728 if (!$initial_error && (scalar keys $run_env->{ipconf}->{ifaces}->%* == 0)) {
1729 print STDERR "no network interfaces found\n";
1730 $initial_error = 1;
1731 Proxmox::UI::display_html("nonics.htm");
1732 set_next("Reboot", sub { app_quit(0); } );
1733 }
1734
1735 create_intro_view () if !$initial_error;
1736
1737 Gtk3->main;
1738
1739 app_quit(0);