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