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