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