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