From e481268d942ca2f2e3754343847678fa4daa8dec Mon Sep 17 00:00:00 2001 From: Michael van Elst Date: Tue, 21 Jan 2003 13:25:06 +0000 Subject: [PATCH] fix temp pkgs, optionally keep temp pkgs, support for su command, skip sub-index by platform, no longer uses defaults for platform name --- openpkg-tool/openpkg-build.pl | 102 +++++++++++++++++++++------------ openpkg-tool/openpkg-index.pl | 9 ++- openpkg-tool/openpkg-tool.spec | 4 +- openpkg-tool/openpkg.pod | 25 +++++--- 4 files changed, 89 insertions(+), 51 deletions(-) diff --git a/openpkg-tool/openpkg-build.pl b/openpkg-tool/openpkg-build.pl index 662c715000..72e5a6f1b3 100644 --- a/openpkg-tool/openpkg-build.pl +++ b/openpkg-tool/openpkg-build.pl @@ -33,8 +33,8 @@ use vars qw/ $opt_R $opt_r $opt_f $opt_u $opt_U $opt_a $opt_A $opt_z $opt_Z $opt_P $opt_N $opt_E $opt_i $opt_D $opt_p $opt_q $opt_s $opt_S $opt_X $opt_M $opt_L - $opt_W/; -my $getopts = 'R:r:f:uUaAzZP:N:E:iD:p:qsSXMLW'; + $opt_W $opt_K/; +my $getopts = 'R:r:f:uUaAzZP:N:E:iD:p:qsSXMLWK'; getopts($getopts); ########################################################################## @@ -150,7 +150,7 @@ sub conditional ($$) { ########################################################################## -my($RPM,$RPM_PRIV,$RPM_NPRIV,$CURL,$PROG); +my($RPM,$CURL,$PROG); $RPM = $opt_R || $env{''}->{'R'} || '@l_prefix@/bin/rpm'; $RPM = (`which $RPM` =~ m{^(/.*)})[0]; @@ -163,14 +163,26 @@ foreach my $env (sort { $a cmp $b } grep { $RPM =~ /^\Q$_\E/ } keys %env) { } } -$RPM_PRIV = ($opt_P ? $opt_P." ".$RPM : $RPM); -$RPM_NPRIV = ($opt_N ? $opt_N." ".$RPM : $RPM); $CURL = $RPM; $CURL =~ s/\/bin\/rpm$/\/lib\/openpkg\/curl/ or die "FATAL: cannot deduce curl path from $RPM\n"; ($PROG) = $0 =~ /(?:.*\/)?(.*)/; +sub cmd ($$) { + my($w,$s) = @_; + if (!defined $w) { + return $s; + } elsif ($w =~ /^-(.*)/) { + return "$1 '$s'"; + } else { + return "$w $s"; + } +} +sub priv ($) { cmd($opt_P,$_[0]); } +sub npriv ($) { cmd($opt_N,$_[0]); } +sub run ($) { my($c) = cmd($opt_N,$_[0]); `$c` } + sub version_cmp ($$) { my($a,$b) = @_; my(@a,@b,$c); @@ -243,7 +255,7 @@ sub get_config () { my($c,@q,@g); - $c = `$RPM_NPRIV --eval '%{_rpmdir} %{_rpmfilename} %{_target_os} %{_target_cpu} %{_target_platform} %{_prefix}'`; + $c = run("$RPM --eval '%{_rpmdir} %{_rpmfilename} %{_target_os} %{_target_cpu} %{_prefix}'"); chomp($c); (@q) = split(/\s+/,$c); @@ -251,14 +263,14 @@ sub get_config () $q[1] =~ s/%{ARCH}/$q[3]/; - $c = `$RPM_NPRIV --showrc`; + $c = run("$RPM --showrc"); @g = $c =~ /\%\{l_tool_locate\s+([^\s\}]+)/g; return { rpmdir => $q[0], template => $q[1], - platform => $q[4], - prefix => $q[5], + platform => '', + prefix => $q[4], optreg => '(?:'.join('|', map { "\Qwith_$_\E" } @g).')' }; } @@ -266,16 +278,13 @@ sub get_config () sub get_release () { my($rel,$url); - ($rel) =`$RPM_NPRIV -qi openpkg` =~ /Version:\s*(\S+)/m; - + ($rel) = run("$RPM -qi openpkg") =~ /Version:\s*(\S+)/m; if ($rel =~ /^\d+$/) { print "# $PROG current($rel)\n"; - print "# using '$RPM_NPRIV' (build) and '$RPM_PRIV' (install)\n"; $url = "ftp://ftp.openpkg.org/current/"; } elsif ($rel =~ /^(\d+\.\d+)/) { $rel = $1; print "# $PROG release($rel)\n"; - print "# using '$RPM_NPRIV' (build) and '$RPM_PRIV' (install)\n"; $url = "ftp://ftp.openpkg.org/release/$rel/"; } else { die "FATAL: don't know how to handle this release\n"; @@ -416,7 +425,7 @@ sub depends2pkglist ($) { # sub get_installed () { my(%map); - my(@l) = `$RPM_NPRIV --provides -qa`; + my(@l) = run("$RPM --provides -qa"); my($p); my($nam,$val,%options); @@ -548,9 +557,9 @@ sub get_with ($$;$) { $opt = $t->{OPTIONS}; } else { if (defined $fn) { - @l = `$RPM_NPRIV -qi -p $fn`; + @l = run("$RPM -qi -p $fn"); } else { - @l = `$RPM_NPRIV -qi $t->{name}`; + @l = run("$RPM -qi $t->{name}"); } $opt = parse_options(\@l); $t->{OPTIONS} = $opt if $env; @@ -633,8 +642,14 @@ sub with_list ($$) { return \@out; } -sub simple_text_parser ($$$$) { - my($fh,$url,$with,$map) = @_; +sub goodpf ($$) { + my($l,$p) = @_; + return 1 if $l eq ''; + return $l =~ /(?:^|\s)\Q$p\E(?:\s|$)/; +} + +sub simple_text_parser ($$$$$) { + my($fh,$url,$with,$map,$pfmatch) = @_; my(@include); my($section); @@ -671,8 +686,12 @@ sub simple_text_parser ($$$$) { @nosource = (); } - if (!(defined $href) && /{href} } @$sub; + @include = map { + goodpf($_->{platform},$pfmatch) + ? ( $_->{href} ) + : ( ) + } @$sub; } return \@include; @@ -929,8 +952,8 @@ sub open_index ($$) { # fetch index from file or URL # recursively fetch sub-indexes # -sub get_index ($$$$) { - my($url,$fn,$with,$noxml) = @_; +sub get_index ($$$$$) { + my($url,$fn,$with,$noxml,$pfmatch) = @_; my(%map,$include); open_index($url,$fn); @@ -943,9 +966,9 @@ sub get_index ($$$$) { } if ($noxml) { - $include = simple_text_parser(\*RFH, $url, $with, \%map); + $include = simple_text_parser(\*RFH, $url, $with, \%map, $pfmatch); } else { - $include = xml_parser(\*RFH, $url, $with, \%map); + $include = xml_parser(\*RFH, $url, $with, \%map, $pfmatch); } close(RFH) @@ -958,7 +981,7 @@ sub get_index ($$$$) { foreach (@$include) { my($submap); my($suburl,$subfn) = relurl($url,$fn,$_); - $submap = get_index($suburl,$subfn,$with,$noxml); + $submap = get_index($suburl,$subfn,$with,$noxml,$pfmatch); while (my($name,$vmap) = each %$submap) { while (my($vs,$recs) = each %$vmap) { push @{$map{$name}->{$vs}}, @$recs; @@ -1522,7 +1545,7 @@ sub build_list ($$) { } %keep = map { $_ => 1 } @keeps; - @bonly = grep { + @bonly = reverse grep { !$keep{$_} && !$env->{installed}->{$_->{name}}->{vs($_)}; } @targets; @@ -1628,7 +1651,7 @@ sub binary_target ($$) { # sub find_proxy ($$) { my($t,$bpkg) = @_; - my(@l) = `$RPM_NPRIV -ql $t->{name}`; + my(@l) = run("$RPM -ql $t->{name}"); my($link) = (grep { $_ =~ /\/\.prefix-$t->{name}$/ } @l)[0]; return unless defined $link; chomp $link; @@ -1727,13 +1750,15 @@ sub print_list1 ($$$@$) { # # rpm doesn't support additional parameters to the # mkproxy script - # $cmd1 = "$RPM_NPRIV$opt --makeproxy $ppkg -- -o $bpkg"; + # $cmd1 = npriv("$RPM$opt --makeproxy $ppkg -- -o $bpkg"); # - $cmd1 = "( cd $c->{rpmdir} && $RPM_NPRIV$opt --makeproxy $ppkg )"; + $cmd1 = "( cd $c->{rpmdir} && ". + npriv("$RPM$opt --makeproxy $ppkg"). + " )"; } elsif (defined $_->{prefix}) { - $cmd1 = "$CURL -q -s -o $bpkg $spkg"; + $cmd1 = npriv("$CURL -q -s -o $bpkg $spkg"); } else { - $cmd1 = "$RPM_NPRIV$opt --rebuild $spkg"; + $cmd1 = npriv("$RPM$opt --rebuild $spkg"); } } @@ -1743,7 +1768,7 @@ sub print_list1 ($$$@$) { # files # $opt = $_->{REBUILD} ? ' --force' : ''; - $cmd2 = "$RPM_PRIV$opt -Uvh $bpkg"; + $cmd2 = priv("$RPM$opt -Uvh $bpkg"); if ($ignore) { $cmd2 = "$cmd1 && \\\n$cmd2" if defined $cmd1; @@ -1770,7 +1795,7 @@ sub print_list2 ($$) { foreach (@$list) { $pkg = "$_->{name}-$_->{version}-$_->{release}"; - print "$RPM_PRIV -e $pkg\n"; + print priv("$RPM -e $pkg\n"); } } @@ -1910,7 +1935,8 @@ $repository = get_index( $url.'00INDEX.rdf', $opt_f, ($opt_W ? undef : \%with), - $opt_X); + $opt_X, + $config->{platform}); $env = { config => $config, @@ -1953,7 +1979,7 @@ if ($opt_L) { } print_list1($list,$config,$opt_a || $opt_u || $opt_U,\%with,$opt_i); - print_list2($bonly,$config); + print_list2($bonly,$config) unless $opt_K; } } diff --git a/openpkg-tool/openpkg-index.pl b/openpkg-tool/openpkg-index.pl index f52ad491be..935ca667ea 100644 --- a/openpkg-tool/openpkg-index.pl +++ b/openpkg-tool/openpkg-index.pl @@ -683,6 +683,10 @@ sub rpm2data ($$) { my($q,$pipe,%a); my($t,$v); + unless (defined $platform) { + die "FATAL: indexing binary package '$fn' requires -p option\n"; + } + $q = < [B<-L>] [B<-W>] [B<-X>] +[B<-K>] [B<-P> I] [B<-N> I] [B<-p> I] @@ -97,12 +98,9 @@ The name of the resource stored in the index. The default is =item B<-p> I -B adds a platform attribute for binary RPMs. The -attribute is built as I<%{arch}>C<->IC<->I<%{os}> where -I<%{arch}> and I<%{os}> are taken from the RPM header and I is -the value of the B<-p> option. The default value is "C". This -must be used to distinguish between platforms that support the same -Architecture and OS name like various Linux distributions. +B adds a platform attribute for binary RPMs. This +must be unique to correctly identify a specific architecture, OS +and build environment. =item B<-C> I @@ -275,20 +273,29 @@ results!> Ignore an installed XML parser module but use the internal simple text parser instead. +=item B<-K> + +Keep packages that were installed temporarily during the build process. + =item B<-P> I Command prefix to use for install commands that require elevated -privileges. The most common tool for this is sudo(8). +privileges. The most common tool for this is sudo(8). If I +starts with a dash it will be run without the dash and the command +line it should execute is passed as a single quoted string. =item B<-N> I Command prefix to use for install commands that do not require elevated -privileges. The most common tool for this is sudo(8). +privileges. The most common tool for this is sudo(8). If I +starts with a dash it will be run without the dash and the command +line it should execute is passed as a single quoted string. =item B<-p> I The platform string that is matched against the index for binary -packages. Default is to use the I<%{_target_platform}> variable. +packages. Default is an empty string so that no binary packages +are matched. =item B<-D>I=I