From: Thomas Lamprecht Date: Sat, 8 Apr 2023 15:38:01 +0000 (+0200) Subject: move cmap/zone parsing to env module X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=d5165292aaf3bdfd58a86290f88903ea5a12b126;p=pve-installer.git move cmap/zone parsing to env module Signed-off-by: Thomas Lamprecht --- diff --git a/Proxmox/Install/Env.pm b/Proxmox/Install/Env.pm index 9ec0c3a..5cdf638 100644 --- a/Proxmox/Install/Env.pm +++ b/Proxmox/Install/Env.pm @@ -29,6 +29,62 @@ my $product_cfg = { }, }; +my sub read_cmap { + my ($lib_dir) = @_; + my $countryfn = "${lib_dir}/country.dat"; + open (my $TMP, "<:encoding(utf8)", "$countryfn") || die "unable to open '$countryfn' - $!\n"; + my ($country, $countryhash, $kmap, $kmaphash) = ({}, {}, {}, {}); + while (defined (my $line = <$TMP>)) { + if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) { + $kmap->{$1} = { + name => $2, + kvm => $3, + console => $4, + x11 => $5, + x11var => $6, + }; + $kmaphash->{$2} = $1; + } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) { + $country->{$1} = { + name => $2, + kmap => $3, + mirror => $4, + }; + $countryhash->{lc($2)} = $1; + } else { + warn "unable to parse 'country.dat' line: $line"; + } + } + close ($TMP); + $TMP = undef; + + my $zones = {}; + my $cczones = {}; + my $zonefn = "/usr/share/zoneinfo/zone.tab"; + open ($TMP, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n"; + while (defined (my $line = <$TMP>)) { + next if $line =~ m/^\#/; + next if $line =~ m/^\s*$/; + if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) { + my $cc = lc($1); + $cczones->{$cc}->{$2} = 1; + $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone}); + $zones->{$2} = 1; + + } + } + close ($TMP); + + return { + zones => $zones, + cczones => $cczones, + country => $country, + countryhash => $countryhash, + kmap => $kmap, + kmaphash => $kmaphash, + } +} + my sub get_cd_info { my $info_fn = '/.cd-info'; # default place in the ISO environment if (!-f $info_fn && -f "cd-info.test") { diff --git a/proxinstall b/proxinstall index c6da822..f5d224d 100755 --- a/proxinstall +++ b/proxinstall @@ -297,61 +297,6 @@ sub get_memtotal { my $total_memory = get_memtotal(); -sub read_cmap { - my $countryfn = "${proxmox_libdir}/country.dat"; - open (my $TMP, "<:encoding(utf8)", "$countryfn") || die "unable to open '$countryfn' - $!\n"; - my ($country, $countryhash, $kmap, $kmaphash) = ({}, {}, {}, {}); - while (defined (my $line = <$TMP>)) { - if ($line =~ m|^map:([^\s:]+):([^:]+):([^:]+):([^:]+):([^:]+):([^:]*):$|) { - $kmap->{$1} = { - name => $2, - kvm => $3, - console => $4, - x11 => $5, - x11var => $6, - }; - $kmaphash->{$2} = $1; - } elsif ($line =~ m|^([a-z]{2}):([^:]+):([^:]*):([^:]*):$|) { - $country->{$1} = { - name => $2, - kmap => $3, - mirror => $4, - }; - $countryhash->{lc($2)} = $1; - } else { - warn "unable to parse 'country.dat' line: $line"; - } - } - close ($TMP); - $TMP = undef; - - my $zones = {}; - my $cczones = {}; - my $zonefn = "/usr/share/zoneinfo/zone.tab"; - open ($TMP, '<', "$zonefn") || die "unable to open '$zonefn' - $!\n"; - while (defined (my $line = <$TMP>)) { - next if $line =~ m/^\#/; - next if $line =~ m/^\s*$/; - if ($line =~ m|^([A-Z][A-Z])\s+\S+\s+(([^/]+)/\S+)\s|) { - my $cc = lc($1); - $cczones->{$cc}->{$2} = 1; - $country->{$cc}->{zone} = $2 if !defined ($country->{$cc}->{zone}); - $zones->{$2} = 1; - - } - } - close ($TMP); - - return { - zones => $zones, - cczones => $cczones, - country => $country, - countryhash => $countryhash, - kmap => $kmap, - kmaphash => $kmaphash, - } -} - sub update_progress { my ($frac, $start, $end, $text) = @_; @@ -3098,7 +3043,7 @@ $ipconf = Proxmox::Sys::Net::get_ip_config(); $country = detect_country() if $ipconf->{default} || is_test_mode(); # read country, kmap and timezone infos -$cmap = read_cmap(); +$cmap = Proxmox::Install::Env::read_cmap($env->{locations}->{lib}); if (!defined($cmap->{country}->{$country})) { log_warn("ignoring detected country '$country', invalid or unknown\n");