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