]> git.proxmox.com Git - pve-installer.git/blobdiff - proxinstall
use a more telling variable name for previous button
[pve-installer.git] / proxinstall
index 5aece6b3074be050d2f02749eabdab00191a38f3..46e8ed6718318164c85338a8e459a812a49f511a 100755 (executable)
@@ -216,10 +216,15 @@ my @steps = (
     },
     {
        step => 'ipconf',
-       next_button => '_Install',
        html => 'ipconf.htm',
        function => \&create_ipconf_view,
     },
+    {
+       step => 'ack',
+       html => 'ack.htm',
+       next_button => '_Install',
+       function => \&create_ack_view,
+    },
     {
        step => 'extract',
        next_button => '_Reboot',
@@ -229,7 +234,7 @@ my @steps = (
 
 # GUI global variables
 my ($window, $cmdbox, $inbox, $htmlview);
-my $prev;
+my $prev_btn;
 my ($next, $next_fctn, $target_hd);
 my ($progress, $progress_status);
 
@@ -248,26 +253,21 @@ my $password;
 my $mailto = 'mail@example.invalid';
 my $cmap;
 
-# Format: screen/function name => settings for that screen
-my $global_configuration = {
-
-    # TODO: add all the user-provided options during the install
-    # to be able to call them back if necessary
-
-    hdsel => {},
-    country => {
-       country => $country,
-       timezone => $timezone,
-       keymap => $keymap,
-    },
-    password => {
-       password => $password,
-       mailto => $mailto,
-    },
-    ipconf => {
-       hostname => $hostname,
-       domain => $domain,
-    },
+my $config = {
+    # TODO: add all the user-provided options for previous button
+    country => $country,
+    timezone => $timezone,
+    keymap => $keymap,
+
+    password => $password,
+    mailto => $mailto,
+
+    mngmt_nic => undef,
+    hostname => $hostname,
+    fqdn => undef,
+    ipaddress => undef,
+    netmask => undef,
+    gateway => undef,
 };
 
 # parse command line args
@@ -559,7 +559,11 @@ sub hd_list {
     my $res = ();
 
     if ($opt_testmode) {
-       push @$res, [-1, $opt_testmode, int((-s $opt_testmode)/512), "TESTDISK"];
+       my @disks = split /,/, $opt_testmode;
+
+       for my $disk (@disks) {
+           push @$res, [-1, $disk, int((-s $disk)/512), "TESTDISK"];
+       }
        return $res;
     }
 
@@ -1752,12 +1756,12 @@ sub prev_function {
 
     $fctn = $step_number if !$fctn;
     $text = "_Previous" if !$text;
-    $prev->set_label ($text);
+    $prev_btn->set_label ($text);
 
     $step_number--;
     $steps[$step_number]->{function}();
 
-    $prev->grab_focus ();
+    $prev_btn->grab_focus ();
 }
 
 sub set_next {
@@ -1802,9 +1806,9 @@ sub create_main_window {
     $cmdbox->pack_end ($next, 0, 0, 10);
 
 
-    $prev = Gtk3::Button->new ('_Previous');
-    $prev->signal_connect (clicked => sub { $last_display_change = 0; &prev_function (); });
-    $cmdbox->pack_end ($prev, 0, 0, 10);
+    $prev_btn = Gtk3::Button->new ('_Previous');
+    $prev_btn->signal_connect (clicked => sub { $last_display_change = 0; &prev_function (); });
+    $cmdbox->pack_end ($prev_btn, 0, 0, 10);
 
 
     my $abort = Gtk3::Button->new ('_Abort');
@@ -1995,13 +1999,15 @@ sub create_ipconf_view {
     my $vbox2 =  Gtk3::VBox->new (0, 0);
     $hbox->add ($vbox2);
 
+    my $ipaddr_text = $config->{ipaddress} // "192.168.100.2";
     my $ipbox;
     ($ipbox, $ipconf_entry_addr) =
-       create_text_input ("192.168.100.2", 'IP Address:');
+       create_text_input ($ipaddr_text, 'IP Address:');
 
+    my $netmask_text = $config->{netmask} // "255.255.255.0";
     my $maskbox;
     ($maskbox, $ipconf_entry_mask) =
-       create_text_input ("255.255.255.0", 'Netmask:');
+       create_text_input ($netmask_text, 'Netmask:');
 
     my $device_cb = Gtk3::ComboBoxText->new();
     $device_cb->set_active(0);
@@ -2013,11 +2019,13 @@ sub create_ipconf_view {
     };
 
     my $device_active_map = {};
+    my $device_active_reverse_map = {};
 
     my $device_change_handler = sub {
        my $current = shift;
        $ipconf->{selected} = $device_active_map->{$current->get_active()};
        my $iface = $ipconf->{ifaces}->{$ipconf->{selected}};
+       $config->{mngmt_nic} = $iface->{name};
        $ipconf_entry_addr->set_text($iface->{inet}->{addr} || $iface->{inet6}->{addr})
            if $iface->{inet}->{addr} || $iface->{inet6}->{addr};
        $ipconf_entry_mask->set_text($iface->{inet}->{mask} || $iface->{inet6}->{mask})
@@ -2027,7 +2035,8 @@ sub create_ipconf_view {
     my $i = 0;
     foreach my $index (sort keys %{$ipconf->{ifaces}}) {
        $device_cb->append_text(&$get_device_desc($ipconf->{ifaces}->{$index}));
-        $device_active_map->{$i} = $index;
+       $device_active_map->{$i} = $index;
+       $device_active_reverse_map->{$ipconf->{ifaces}->{$index}->{name}} = $i;
        if ($ipconf_first_view && $index == $ipconf->{default}) {
            $device_cb->set_active($i);
            &$device_change_handler($device_cb);
@@ -2037,8 +2046,11 @@ sub create_ipconf_view {
        $i++;
     }
 
-    $device_cb->set_active(0)
-       if !($ipconf->{selected});
+    if (my $nic = $config->{mngmt_nic}) {
+       $device_cb->set_active($device_active_reverse_map->{$nic} // 0);
+    } else {
+       $device_cb->set_active(0);
+    }
 
     my $devicebox = Gtk3::HBox->new (0, 0);
     my $label = Gtk3::Label->new ("Management Interface:");
@@ -2049,8 +2061,7 @@ sub create_ipconf_view {
 
     $vbox2->pack_start ($devicebox, 0, 0, 2);
 
-    my $hn = $ipconf->{domain} ?
-       "$setup->{product}.$ipconf->{domain}" : "$setup->{product}.example.invalid";
+    my $hn = $config->{fqdn} //  "$setup->{product}." . ($ipconf->{domain} // "example.invalid");
 
     my ($hostbox, $hostentry) =
        create_text_input ($hn, 'Hostname (FQDN):');
@@ -2060,7 +2071,7 @@ sub create_ipconf_view {
 
     $vbox2->pack_start ($maskbox, 0, 0, 2);
 
-    $gateway = $ipconf->{gateway} || '192.168.100.1';
+    $gateway = $config->{gateway} // $ipconf->{gateway} || '192.168.100.1';
 
     my $gwbox;
     ($gwbox, $ipconf_entry_gw) =
@@ -2068,7 +2079,7 @@ sub create_ipconf_view {
 
     $vbox2->pack_start ($gwbox, 0, 0, 2);
 
-    $dnsserver = $ipconf->{dnsserver} || $gateway;
+    $dnsserver = $config->{dnsserver} // $ipconf->{dnsserver} || $gateway;
 
     my $dnsbox;
     ($dnsbox, $ipconf_entry_dns) =
@@ -2086,6 +2097,8 @@ sub create_ipconf_view {
        $text =~ s/^\s+//;
        $text =~ s/\s+$//;
 
+       $config->{fqdn} = $text;
+
        my $namere = "([a-zA-Z0-9]([a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
 
        # Debian does not support purely numeric hostnames
@@ -2121,6 +2134,7 @@ sub create_ipconf_view {
            $ipconf_entry_addr->grab_focus();
            return;
        }
+       $config->{ipaddress} = $ipaddress;
 
        $text = $ipconf_entry_mask->get_text();
        $text =~ s/^\s+//;
@@ -2134,6 +2148,7 @@ sub create_ipconf_view {
            $ipconf_entry_mask->grab_focus();
            return;
        }
+       $config->{netmask} = $netmask;
 
        $text = $ipconf_entry_gw->get_text();
        $text =~ s/^\s+//;
@@ -2147,6 +2162,7 @@ sub create_ipconf_view {
            $ipconf_entry_gw->grab_focus();
            return;
        }
+       $config->{gateway} = $gateway;
 
        $text = $ipconf_entry_dns->get_text();
        $text =~ s/^\s+//;
@@ -2160,16 +2176,54 @@ sub create_ipconf_view {
            $ipconf_entry_dns->grab_focus();
            return;
        }
+       $config->{dnsserver} = $dnsserver;
 
        #print "TEST $ipaddress $netmask $gateway $dnsserver\n";
 
        $step_number++;
-       create_extract_view();
+       create_ack_view();
     });
 
     $hostentry->grab_focus();
 }
 
+sub create_ack_view {
+
+    cleanup_view();
+
+    my $ack_template = "${proxmox_libdir}/html/ack_template.htm";
+    my $ack_html = "${proxmox_libdir}/html/$steps[$step_number]->{html}";
+    my $html_data = file_get_contents($ack_template);
+
+    my %config_values = (
+       __target_hd__ => $target_hd,
+       __target_fs__ => $config_options->{filesys},
+       __country__ => $country,
+       __timezone__ => $timezone,
+       __keymap__ => $keymap,
+       __mailto__ => $mailto,
+       __interface__ => $ipconf->{ifaces}->{$ipconf->{selected}}->{name},
+       __hostname__ => $hostname,
+       __ip__ => $ipaddress,
+       __netmask__ => $netmask,
+       __gateway__ => $gateway,
+       __dnsserver__ => $dnsserver,
+    );
+
+    while ( my ($k, $v) = each %config_values) {
+       $html_data =~ s/$k/$v/g;
+    }
+
+    write_config($html_data, $ack_html);
+
+    display_html();
+
+    set_next(undef, sub {
+       $step_number++;
+       create_extract_view();
+    });
+}
+
 sub get_device_desc {
     my ($devname, $size, $model) = @_;
 
@@ -2979,7 +3033,7 @@ sub get_btrfs_raid_setup {
 
 sub create_hdsel_view {
 
-    $prev->set_sensitive(1); # enable previous button at this point
+    $prev_btn->set_sensitive(1); # enable previous button at this point
 
     cleanup_view ();
 
@@ -3095,7 +3149,7 @@ sub create_extract_view {
 
 sub create_intro_view {
 
-    $prev->set_sensitive(0);
+    $prev_btn->set_sensitive(0);
 
     cleanup_view();