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