From 66e975cfae9f3f07a77778594d3908f842a52e53 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 19 Jun 2023 21:13:35 +0200 Subject: [PATCH] re-use geoip-resolved country from runtime env Signed-off-by: Thomas Lamprecht --- proxinstall | 44 +------------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/proxinstall b/proxinstall index ebb9544..781efe3 100755 --- a/proxinstall +++ b/proxinstall @@ -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; -- 2.39.5