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