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