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