]> git.proxmox.com Git - pve-installer.git/commitdiff
re-use geoip-resolved country from runtime env
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 19 Jun 2023 19:13:35 +0000 (21:13 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 19 Jun 2023 19:49:00 +0000 (21:49 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxinstall

index ebb9544e81775760c8d1739c347f25867848f007..781efe318d36540270af5975b40860e316016a59 100755 (executable)
@@ -152,7 +152,7 @@ my $hostname = 'proxmox';
 my $domain = 'domain.tld';
 my $cmdline = file_read_firstline("/proc/cmdline");
 my $ipconf;
-my $country;
+my $country = $run_env->{country};
 my $timezone = 'Europe/Vienna';
 my $keymap = 'en-us';
 my $password;
@@ -249,46 +249,6 @@ sub app_quit {
     exit($exit_code);
 }
 
-sub detect_country {
-    print STDERR "trying to detect country...\n";
-    my $cpid = open2(my $TRACEROUTE_FH, undef, "traceroute -N 1 -q 1 -n 8.8.8.8");
-    return undef if !$cpid;
-
-    my $country;
-
-    my $previous_alarm = alarm (10);
-    eval  {
-       local $SIG{ALRM} = sub { die "timed out!\n" };
-       my $line;
-       while (defined ($line = <$TRACEROUTE_FH>)) {
-           log_debug("DC TRACEROUTE: $line");
-           if ($line =~ m/\s*\d+\s+(\d+\.\d+\.\d+\.\d+)\s/) {
-               my $geoip = `geoiplookup $1`;
-               log_debug("DC GEOIP: $geoip");
-               if ($geoip =~ m/GeoIP Country Edition:\s*([A-Z]+),/) {
-                   $country = lc ($1);
-                   log_info("DC FOUND: $country\n");
-                   last;
-               }
-           }
-       }
-    };
-    my $err = $@;
-    alarm ($previous_alarm);
-
-    close($TRACEROUTE_FH);
-
-    if ($err) {
-       print STDERR "unable to detect country - $err\n";
-    } elsif ($country) {
-       print STDERR "detected country: " . uc($country) . "\n";
-    } else {
-       print STDERR "unable to detect country\n";
-    }
-
-    return $country;
-}
-
 sub update_progress {
     my ($frac, $start, $end, $text) = @_;
 
@@ -2978,8 +2938,6 @@ sub create_intro_view {
 
 $ipconf = Proxmox::Sys::Net::get_ip_config();
 
-$country = detect_country() if $ipconf->{default} || is_test_mode();
-
 if (!defined($iso_env->{locales}->{country}->{$country})) {
     log_warn("ignoring detected country '$country', invalid or unknown\n");
     $country = undef;