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