]> git.proxmox.com Git - pve-installer.git/commitdiff
switch "hostname" & "domain" over to central config
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Jun 2023 07:51:40 +0000 (09:51 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 20 Jun 2023 07:51:40 +0000 (09:51 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Proxmox/Install/Config.pm
proxinstall

index 958d197233147f8e815e5a245edf037e0b21e832..f959f014fc81b8731e7179a2c50a1549fe2d9a98 100644 (file)
@@ -41,6 +41,8 @@ my sub init_cfg {
        # network related
        mngmt_nic => undef,
        mngmt_nic_id => undef,
+       hostname => 'proxmox',
+       domain => 'example.invalid',
     };
 
     # TODO add disksel$i => undef entries
@@ -153,4 +155,15 @@ sub get_mngmt_nic { return get('mngmt_nic'); }
 sub set_mngmt_nic_id { set_key('mngmt_nic_id', $_[0]); }
 sub get_mngmt_nic_id { return get('mngmt_nic_id'); }
 
+sub set_hostname { set_key('hostname', $_[0]); }
+sub get_hostname { return get('hostname'); }
+
+sub set_domain { set_key('domain', $_[0]); }
+sub get_domain { return get('domain'); }
+
+sub get_fqdn { # virtual config
+    my ($hostname, $domain) = (get('hostname'), get('domain'));
+    return defined($hostname) && defined($domain) ? "${hostname}.${domain}" : undef;
+}
+
 1;
index 46b8267159ac24534970b333236696d96de7b928..fb365d4759e98441aa6c09c3573e08d71614b397 100755 (executable)
@@ -104,16 +104,12 @@ my ($ipversion, $ipaddress, $cidr, $ipconf_entry_addr);
 my ($netmask, $ipconf_entry_mask);
 my ($gateway, $ipconf_entry_gw);
 my ($dnsserver, $ipconf_entry_dns);
-my $hostname = 'proxmox';
-my $domain = 'domain.tld';
 my $ipconf;
 my $autoreboot_seconds = 5;
 
 # TODO: single source of config state
 my $config = {
     # TODO: add all the user-provided options for previous button
-    hostname => $hostname,
-    fqdn => undef,
     ipaddress => undef,
     netmask => undef,
     gateway => undef,
@@ -848,6 +844,8 @@ sub extract_data {
        update_progress(1, $maxper, 0.5, "configuring base system");
 
        # configure hosts
+       my $hostname = Proxmox::Install::Config::get_hostname();
+       my $domain = Proxmox::Install::Config::get_domain();
 
        my $hosts =
            "127.0.0.1 localhost.localdomain localhost\n" .
@@ -1559,7 +1557,8 @@ sub create_ipconf_view {
 
     $vbox->pack_start($devicebox, 0, 0, 2);
 
-    my $hn = $config->{fqdn} // "$iso_env->{product}." . ($ipconf->{domain} // "example.invalid");
+    my $fqdn = Proxmox::Install::Config::get_fqdn();
+    my $hn = $fqdn // "$iso_env->{product}." . ($ipconf->{domain} // "example.invalid");
 
     my ($hostbox, $hostentry) = create_text_input($hn, 'Hostname (FQDN):');
     $vbox->pack_start($hostbox, 0, 0, 2);
@@ -1584,16 +1583,11 @@ sub create_ipconf_view {
 
     $gtk_state->{inbox}->show_all;
     set_next(undef, sub {
-
        # verify hostname
-
        my $text = $hostentry->get_text();
-
        $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
@@ -1605,8 +1599,8 @@ sub create_ipconf_view {
 
        if ($text && $text =~ m/^(${namere}\.)*${namere}$/ && $text !~ m/.example.invalid$/ &&
            $text =~ m/^([^\.]+)\.(\S+)$/) {
-           $hostname = $1;
-           $domain = $2;
+           Proxmox::Install::Config::set_hostname($1);
+           Proxmox::Install::Config::set_domain($2);
        } else {
            Proxmox::UI::message("Hostname does not look like a fully qualified domain name.");
            $hostentry->grab_focus();
@@ -1695,7 +1689,7 @@ sub create_ack_view {
        __keymap__ => Proxmox::Install::Config::get_keymap(),
        __mailto__ => Proxmox::Install::Config::get_mailto(),
        __interface__ =>  Proxmox::Install::Config::get_mngmt_nic(),
-       __hostname__ => $hostname,
+       __hostname__ => Proxmox::Install::Config::get_hostname(),
        __ip__ => $ipaddress,
        __cidr__ => $cidr,
        __netmask__ => $netmask,