From 04d43a777e3b4470b4192081e4063760c924d931 Mon Sep 17 00:00:00 2001 From: Frederic Lepied Date: Sun, 7 Mar 2004 20:47:50 +0000 Subject: allow to specify rpm top directory switch from rawhide to fedora --- rpmbuildupdate | 103 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/rpmbuildupdate b/rpmbuildupdate index 805504b..09475c7 100755 --- a/rpmbuildupdate +++ b/rpmbuildupdate @@ -2,7 +2,7 @@ # # rpmbuildupdate by Julien Danjou # -# Copyright (c) 2003 by MandrakeSoft +# Copyright (c) 2003-2004 by MandrakeSoft # # Permission to use, copy, modify, and distribute this software and its # documentation under the terms of the GNU General Public License is hereby @@ -32,11 +32,18 @@ sub build my $pkg = shift; my $newversion = shift; my $pkgrpm = shift; - + my $rpm; + my $found = 0; my ($version, $release); my ($spec, @url, @rpms, %specvars); + my $top = $config{top} || `rpm --eval '%_topdir'`; + chomp($top); + chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES"; + + $rpm = "rpm --define \"_topdir $top\""; + print "===> Building $pkg $newversion\n"; my $pkge = $pkg; @@ -73,7 +80,7 @@ sub build if($config{src}) { - system("rpm -ivh $pkgrpm"); + system("$rpm -ivh $pkgrpm"); wait; } elsif(!$config{nosource}) @@ -82,10 +89,6 @@ sub build wait; } - my $top = `rpm --eval '%_topdir'`; - chomp($top); - chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES"; - $found = 0; if(!open(SPECFILE, "../SPECS/".$pkg.".spec")) @@ -102,7 +105,7 @@ sub build $spec .= $_; $spec =~ s/\%define(\s+)release(\s+)(.*)/\%define release $config{release}/; - push(@url, $2) if(/(Source|Url|Source0):\s+(\S+)/i); + push(@url, $2) if(/(Source[0-9]*):\s+((?:ftp|http):\S+)/i); # For %vars ! $specvars{$1} = $2 if(/\%define\s+(.+?)\s+(.+)/g); @@ -129,11 +132,21 @@ sub build foreach (@url) { + # Replace variable from spec (%blabla) + while(/\%/) + { + s/\%\{(.*?)\}/$specvars{$1}/g; + s/\%(\w+)/$specvars{$1}/g; + s/\%\{name\}/$pkg/gi; + s/\%\{version\}/$newversion/gi; + } + my $basename = `basename $_`; chomp($basename); - if(/ftp\.redhat\.com.*SRPMS/) + + + if(/ftp\.redhat\.com/) { - $found = 1; - opendir(MP, $config{rawhide}) or die "$config{rawhide} is not a directory"; + opendir(MP, $config{fedora}) or die "$config{fedora} is not a directory"; my @rpmsrh = readdir(MP); my $pkgrpmrh; @@ -144,54 +157,36 @@ sub build } closedir(MP); - - if($config{deps}) - { - system("sudo /usr/sbin/urpmi --auto --force ".$config{rawhide}."/".$pkgrpmrh); - wait; - } - if($config{src}) - { - system("rpm -ivh $pkgrpmrh"); - wait; - } - elsif(!$config{nosource}) + print "Trying from fedora($basename): $config{fedora}/$pkgrpmrh\n"; + system("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $basename"); + wait; + + if (! -f "${top}/SOURCES/$basename") { - system("/usr/sbin/urpmi --install-src --force ".$config{rawhide}."/".$pkgrpmrh); - wait; + $basename =~ s/bz2/gz/; + print "Trying from fedora($basename): $config{fedora}/$pkgrpmrh\n"; + system("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $basename; bzme $basename"); + wait; } - - # Reinstall source to restore .spec file - #system("/usr/sbin/urpmi --install-src --force ".$config{srpms}."/".$pkgrpm); - #wait; } - else + if (! -f "${top}/SOURCES/$basename") { - # Replace variable from spec (%blabla) - while(/\%/) - { - s/\%\{(.*?)\}/$specvars{$1}/g; - s/\%(\w+)/$specvars{$1}/g; - s/\%\{name\}/$pkg/gi; - s/\%\{version\}/$newversion/gi; - } - print "Trying $_...\n"; - system("wget ".$_); + system("wget -N ".$_); if($basename =~ /gz/) { s/gz/bz2/; $basename = `basename $_`; chomp($basename); print "Trying to fetch .bz2...\n"; - system("wget ".$_); + system("wget -N ".$_); } elsif($basename =~ /bz2/) { s/bz2/gz/; print "Trying to fetch .gz...\n"; - system("wget ".$_); + system("wget -N ".$_); $basename = `basename $_`; chomp($basename); # If gz was downloaded, recompressing it in bz2 if(-f $basename) @@ -215,11 +210,11 @@ sub build if(!$found) { print "Unable to download file: URL is not valid ! :-(\n\n"; return; } - if(system("rpm -ba ../SPECS/".$pkg.".spec")) + if(system("$rpm -ba ../SPECS/".$pkg.".spec")) { wait; print "Binary build fails: building source only\n"; - system("rpm -bs ../SPECS/".$pkg.".spec"); + system("$rpm -bs ../SPECS/".$pkg.".spec"); } wait; } @@ -260,10 +255,10 @@ sub parse_argv ARGCOUNT => AppConfig::ARGCOUNT_ONE } ); - $conf->define("rawhide", + $conf->define("fedora", { ARGS => "=s", ALIAS => "h", - DEFAULT => "/mnt/BIG/distrib/rawhide/SRPMS/SRPMS/", + DEFAULT => "/mnt/BIG/distrib/fedora/development/SRPMS/", ARGCOUNT => AppConfig::ARGCOUNT_ONE } ); @@ -279,6 +274,13 @@ sub parse_argv ARGCOUNT => AppConfig::ARGCOUNT_NONE } ); + $conf->define("top", + { ARGS => "=t", + ALIAS => "h", + DEFAULT => 0, + ARGCOUNT => AppConfig::ARGCOUNT_ONE } + ); + $conf->args(); $config{rpmmon} = $conf->get("rpmmon"); $config{deps} = $conf->get("deps"); @@ -286,13 +288,14 @@ sub parse_argv $config{src} = $conf->get("src"); $config{release} = $conf->get("release"); $config{nosource} = $conf->get("nosource"); - $config{rawhide} = $conf->get("rawhide"); + $config{fedora} = $conf->get("fedora"); + $config{top} = $conf->get("top"); } sub usage { - print "rpmbuildupdate v0.3 helps you build up to date RPMs.\n\n"; + print "rpmbuildupdate v0.4 helps you build up to date RPMs.\n\n"; print "By Julien Danjou \n"; print "Copyright (c) 2003-2004 by MandrakeSoft.\n"; print "This is free software under the GPL License.\n"; @@ -302,9 +305,9 @@ sub usage print " --srpms : Specify SRPMS path\n"; print " --src : Build new version from this source RPM\n"; print " --release : Release version of package (default: 1mdk)\n"; - print " --deps: Install builds dependecies\n"; + print " --deps: Install builds dependencies\n"; print " --nosource: Do not install source from (urpmi x.src.rpm)\n"; - + print " --top : specify rpm top dir (default: `rpm --eval %_topdir`)\n"; exit 0; } -- cgit v1.2.1