Changeset 2488 in ProjectBuilder for devel/pb-modules/lib/ProjectBuilder/Distribution.pm
- Timestamp:
- Mar 30, 2020, 8:21:44 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb-modules/lib/ProjectBuilder/Distribution.pm
r2468 r2488 3 3 # Creates common environment for distributions 4 4 # 5 # Copyright B. Cornec 2007- 20165 # Copyright B. Cornec 2007-today 6 6 # Eric Anderson's changes are (c) Copyright 2012 Hewlett Packard 7 7 # Provided under the GPL v2 … … 33 33 34 34 our @ISA = qw(Exporter); 35 our @EXPORT = qw(pb_distro_init pb_distro_conffile pb_distro_sysconffile pb_distro_api pb_distro_get pb_distro_get lsb pb_distro_installdeps pb_distro_installpkgs pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_setuposrepo pb_distro_setuprepo_gen pb_distro_get_parampb_distro_get_context pb_distro_to_keylist pb_distro_conf_print pb_apply_conf_proxy);35 our @EXPORT = qw(pb_distro_init pb_distro_conffile pb_distro_sysconffile pb_distro_api pb_distro_get pb_distro_get_if pb_distro_getlsb pb_distro_installdeps pb_distro_installpkgs pb_distro_getdeps pb_distro_only_deps_needed pb_distro_setuprepo pb_distro_setuposrepo pb_distro_setuprepo_gen pb_distro_get_context pb_distro_to_keylist pb_distro_conf_print pb_apply_conf_proxy); 36 36 ($VERSION,$REVISION,$PBCONFVER) = pb_version_init(); 37 37 … … 63 63 # Return information on the running distro 64 64 # 65 my ($ddir,$dver) = pb_distro_g et();65 my ($ddir,$dver) = pb_distro_guess(); 66 66 67 67 =head1 USAGE … … 159 159 160 160 # If we don't know which distribution we're on, then guess it 161 ($pbos->{'name'},$pbos->{'version'}) = pb_distro_g et() if ((not defined $pbos->{'name'}) || (not defined $pbos->{'version'}));161 ($pbos->{'name'},$pbos->{'version'}) = pb_distro_guess() if ((not defined $pbos->{'name'}) || (not defined $pbos->{'version'})); 162 162 163 163 # For some rare cases, typically nover ones … … 174 174 # Do NOT factorize here, as it won't work as of now for hash creation 175 175 # Do NOT change order without caution 176 $pbos->{'useminor'} = pb_distro_get_param($pbos,pb_conf_get("osuseminorrel")); 177 $pbos->{'family'} = pb_distro_get_param($pbos,pb_conf_get("osfamily")); 178 $pbos->{'type'} = pb_distro_get_param($pbos,pb_conf_get("ostype")); 179 ($pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("os","osins","ossuffix","osnover","osremovedotinver","osupd")); 180 ($pbos->{'localinstall'}) = pb_distro_get_param($pbos,pb_conf_get_if("oslocalins")); 181 #($pbos->{'family'},$pbos->{'type'},$pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'nover'},$pbos->{'rmdot'},$pbos->{'update'}) = pb_distro_get_param($pbos,pb_conf_get("osfamily","ostype","os","osins","ossuffix","osnover","osremovedotinver","osupd")); 176 $pbos->{'useminor'} = pb_distro_get($pbos,"osuseminorrel"); 177 $pbos->{'family'} = pb_distro_get($pbos,"osfamily"); 178 $pbos->{'type'} = pb_distro_get($pbos,"ostype"); 179 ($pbos->{'os'},$pbos->{'install'},$pbos->{'suffix'},$pbos->{'update'}) = pb_distro_get($pbos,("os","osins","ossuffix","osupd")); 180 ($pbos->{'localinstall'},$pbos->{'nover'},$pbos->{'rmdot'}) = pb_distro_get_if($pbos,"oslocalins","osnover","osremovedotinver"); 182 181 183 182 # Some OS have no interesting version … … 204 203 } 205 204 206 =item B<pb_distro_g et>205 =item B<pb_distro_guess> 207 206 208 207 This function returns a list of 2 parameters indicating the distribution name and version of the underlying Linux distribution. The value of those 2 fields may be "unknown" in case the function was unable to recognize on which distribution it is running. … … 212 211 =cut 213 212 214 sub pb_distro_g et{213 sub pb_distro_guess { 215 214 216 215 # 1: List of files that unambiguously indicates what distro we have … … 360 359 my ($pbos) = @_; 361 360 362 my $ftp_proxy = pb_distro_get_ param($pbos,pb_conf_get_if("ftp_proxy"));363 my $http_proxy = pb_distro_get_ param($pbos,pb_conf_get_if("http_proxy"));364 my $https_proxy = pb_distro_get_ param($pbos,pb_conf_get_if("https_proxy"));361 my $ftp_proxy = pb_distro_get_if($pbos,"ftp_proxy"); 362 my $http_proxy = pb_distro_get_if($pbos,"http_proxy"); 363 my $https_proxy = pb_distro_get_if($pbos,"https_proxy"); 365 364 366 365 # We do not overwrite shell settings … … 626 625 # Adds conf file for availability of conf elements either from the local build env or from a VE/VM/RM in which the conf file has been passed 627 626 $h = pb_conf_cache(pb_distro_conffile(),$h); 628 my ($osrepo) = pb_conf_get_in_hash_if($h,"osrepo");629 my $repo = pb_distro_get_ param($pbos,$osrepo);627 #my $repo = pb_distro_get_param($pbos,$osrepo); 628 my $repo = pb_distro_get_in_hash_if($pbos,$h,"osrepo"); 630 629 return(pb_distro_setuprepo_gen($pbos,$repo)); 631 630 } … … 649 648 $h = pb_conf_cache("$ENV{'PBDESTDIR'}/pbrc.yml",$h) if ((defined $ENV{'PBDESTDIR'}) && (-f "$ENV{'PBDESTDIR'}/pbrc.yml")); 650 649 651 my ($addrepo) = pb_conf_get_in_hash_if($h,"add".$repotype."repo"); 652 my $repo = pb_distro_get_param($pbos,$addrepo); 650 my $repo = pb_distro_get_in_hash_if($pbos,$h,"add".$repotype."repo"); 653 651 # If no repo then set it up as undef so the return value is correct from pb_distro_setuprepo_gen 654 652 $repo = undef if ($repo eq ""); … … 656 654 # Give a probable default if nothing is provided to avoid overloading conf files 657 655 # 658 if ( (not defined $addrepo) || (not defined $repo)) {656 if (not defined $repo) { 659 657 my ($pbrepo) = pb_conf_get_in_hash_if($h,"pbrepo"); 660 658 if (not defined $pbrepo) { … … 870 868 =item B<pb_distro_get_param> 871 869 872 This function gets the parameterin the conf file from the most precise tuple up to default870 This internal function gets the parameters in the conf file from the most precise tuple up to default 873 871 874 872 =cut … … 876 874 sub pb_distro_get_param { 877 875 876 my $pbos = shift; 877 my $var = shift; 878 878 my @param = (); 879 my $pbos = shift; 879 my $i = 0; 880 pb_log(3,"var: ".Dumper($var)); 880 881 881 882 my @keylist = pb_distro_to_keylist($pbos,"default"); 882 pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} for ".Dumper(@_)."\n"); 883 foreach my $opt (@_) { 884 my $param = ""; 883 pb_log(3,"keylist: ".Dumper(@keylist)); 884 885 my $p = $var->{"ptr"}; 886 foreach my $opt (@$p) { 887 pb_log(3,'opt: '.Dumper($opt)); 888 my $param = undef; 889 my $fkey = undef; 885 890 foreach my $key (@keylist) { 891 pb_log(3,"key: $key\n"); 886 892 if (defined $opt->{$key}) { 887 893 $param = $opt->{$key}; 894 $fkey = $key; 888 895 last; 889 896 } 890 897 } 891 # Allow replacement of variables inside the parameter such as name, version, arch for rpmbootstrap 892 # but not shell variable which are backslashed 893 if ($param =~ /[^\\]\$/) { 894 pb_log(3,"Expanding variable on $param\n"); 895 eval { $param =~ s/(\$\w+->\{\'\w+\'\})/$1/eeg }; 898 my $field = $var->{"val"}; 899 pb_log(3,"field: ".Dumper($field)); 900 $fkey = "default" if (not defined $fkey); 901 pb_log(3,"key: $fkey\n"); 902 pb_log(2,"DEBUG: pb_distro_get_if on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} for $field->[$i]".'{'.$fkey.'}'." returns "); 903 if (defined $param) { 904 # Allow replacement of variables inside the parameter such as name, version, arch for rpmbootstrap 905 # but not shell variable which are backslashed 906 if ($param =~ /[^\\]\$/) { 907 pb_log(3,"Expanding variable on $param\n"); 908 eval { $param =~ s/(\$\w+->\{\'\w+\'\})/$1/eeg }; 909 } 910 pb_log(2,"$param\n"); 911 } else { 912 pb_log(2,"undefined\n"); 896 913 } 897 914 push @param,$param; 898 } 899 900 pb_log(2,"DEBUG: pb_distro_get_param on $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} returns ==".Dumper(@param)."==\n"); 915 $i++; 916 } 901 917 902 918 # Return one param if user only asked for one lookup, an array if not. 903 919 my $nb = @param; 920 pb_log(3,"Param".Dumper(@param)." has $nb members\n"); 904 921 if ($nb eq 1) { 922 pb_log(3,"Retrun Param $param[0]\n"); 905 923 return($param[0]); 906 924 } else { 907 925 return(@param); 908 926 } 927 } 928 929 930 =item B<pb_distro_get_if> 931 932 This function gets the parameters in the conf file from the most precise tuple up to default 933 934 =cut 935 936 sub pb_distro_get_if { 937 938 my $pbos = shift; 939 my @ptr = pb_conf_get_if(@_); 940 my $var; 941 $var->{"ptr"} = \@ptr; 942 $var->{"val"} = \@_; 943 return(pb_distro_get_param($pbos,$var)); 944 } 945 946 =item B<pb_distro_get> 947 948 This function gets the parameters in the conf file from the most precise tuple up to default. 949 Aborts of one param doesn't exist whereas it should 950 951 =cut 952 953 sub pb_distro_get { 954 955 my $pbos = shift; 956 my @param = @_; 957 my @return = pb_distro_get_if($pbos,@param); 958 959 foreach my $i (0..$#param) { 960 confess "No $param[$i] defined for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}" if (not defined $return[$i]); 961 } 962 my $nb = @return; 963 if ($nb eq 1) { 964 return($return[0]); 965 } else { 966 return(@return); 967 } 968 } 969 970 =item B<pb_distro_get_in_hash_if> 971 972 This function gets the parameters in the conf file passed as hash from the most precise tuple up to default 973 974 =cut 975 976 sub pb_distro_get_in_hash_if { 977 978 my $pbos = shift; 979 my $lh = shift || return(()); 980 981 my @ptr = pb_conf_get_in_hash_if($lh,@_); 982 my $var; 983 $var->{"ptr"} = \@ptr; 984 $var->{"val"} = \@_; 985 return(pb_distro_get_param($pbos,$var)); 986 } 987 988 =item B<pb_distro_get_in_conf_if> 989 990 This function gets the parameters in the conf file passed as name from the most precise tuple up to default 991 992 =cut 993 994 sub pb_distro_get_in_conf_if { 995 996 my $pbos = shift; 997 my $conffile = shift; 998 999 my @ptr = pb_conf_read($conffile,@_); 1000 my $var; 1001 $var->{"ptr"} = \@ptr; 1002 $var->{"val"} = \@_; 1003 return(pb_distro_get_param($pbos,$var)); 909 1004 } 910 1005 … … 962 1057 my $i = 0; 963 1058 # Index on distro 964 foreach my $r (pb_distro_get _param($pbos,pb_conf_get(@keys))) {1059 foreach my $r (pb_distro_get($pbos,@keys)) { 965 1060 $rep{$keys[$i]} = $r if (defined $keys[$i]); 966 1061 $i++;
Note:
See TracChangeset
for help on using the changeset viewer.