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