aboutsummaryrefslogtreecommitdiffstats
path: root/rpmbuildupdate
diff options
context:
space:
mode:
Diffstat (limited to 'rpmbuildupdate')
-rwxr-xr-xrpmbuildupdate203
1 files changed, 203 insertions, 0 deletions
diff --git a/rpmbuildupdate b/rpmbuildupdate
new file mode 100755
index 0000000..14a595e
--- /dev/null
+++ b/rpmbuildupdate
@@ -0,0 +1,203 @@
+#!/usr/bin/perl -w
+#
+# rpmbuildupdate by Julien Danjou <jdanjou at mandrakesoft dot com>
+#
+# Copyright (c) 2003 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
+# granted. No representations are made about the suitability of this software
+# for any purpose. It is provided "as is" without express or implied warranty.
+# See the GNU General Public License for more details.
+#
+
+
+use strict;
+use AppConfig;
+
+my $mount_point = "/mnt/distrib/cooker/SRPMS/";
+my $defaultrelease = "1mdk";
+my %config;
+
+sub build
+{
+ my $pkg = shift;
+ my $newversion = shift;
+
+ my $found = 0;
+ my ($pkge, $pkgrpm, $version, $release);
+ my ($spec, @url, $basename);
+
+ my (@rpms, %specvars);
+
+ print "===> Building $pkg $newversion\n";
+
+ opendir(MP, $mount_point) or die "$mount_point is not a directory";
+ @rpms = readdir(MP);
+
+ $pkge = $pkg;
+ $pkge =~ s/\+/\\\+/;
+
+ foreach (@rpms)
+ {
+ if(m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|)
+ { $pkgrpm = $_; $version = $2; $release = $3; $found = 1;}
+ }
+
+ closedir(MP);
+
+ if($found == 0) { print "Package $pkg has no source, skipping.\n\n"; return; }
+
+ system("/usr/sbin/urpmi --auto --force ".$mount_point.$pkgrpm);
+ #{ print "Error while urpmi $pkgrpm\n"; return; };
+ wait;
+
+ system("/usr/sbin/urpmi --install-src --force ".$mount_point.$pkgrpm);
+ #{ print "Error while urpmi --install-src $pkgrpm\n"; return; }
+ wait;
+
+
+ chdir "/usr/src/RPM/SOURCES" or die "Unable to chdir to /usr/src/RPM/SOURCES";
+
+ $found = 0;
+
+ if(!open(SPECFILE, "../SPECS/".$pkg.".spec"))
+ {
+ print STDERR "Unable to open spec file !\n";
+ return;
+ }
+
+ while(<SPECFILE>)
+ {
+ s/$version/$newversion/g if($_ !~ /Patch/i);
+ $spec .= $_;
+ $spec =~ s/\%define release (.*)/\%define release $defaultrelease/;
+ push(@url, $2) if(/(Source|Url|Source0):\s+(\S+)/i);
+
+ # For %vars !
+ $specvars{$1} = $2 if(/\%define\s+(.+?)\s+(.+)/g);
+ $specvars{version} = $1 if(!$specvars{version} && /Version:\s+(.+)/gi);
+ $specvars{name} = $1 if(!$specvars{name} && /Name:\s+(.+)/gi);
+ }
+ close(SPECFILE);
+
+
+ if(!$url[0])
+ { print "URL was not found ! Skipping...\n"; return; }
+
+ open(SPECFILE, ">../SPECS/".$pkg.".spec");
+ print SPECFILE $spec;
+ close(SPECFILE);
+
+ $found = 0;
+
+ 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;
+ }
+
+ print "Trying $_...\n";
+
+ system("wget ".$_);
+ $basename = `basename $_`; chomp($basename);
+ if($basename =~ /gz/)
+ {
+ s/gz/bz2/;
+ $basename = `basename $_`; chomp($basename);
+ print "Trying to fetch .bz2...\n";
+ system("wget ".$_);
+ }
+ elsif($basename =~ /bz2/)
+ {
+ s/bz2/gz/;
+ print "Trying to fetch .gz...\n";
+ system("wget ".$_);
+ $basename = `basename $_`; chomp($basename);
+ # If gz was downloaded, recompressing it in bz2
+ if(-f $basename)
+ {
+ print "Gunzipping $basename... ";
+ system("gunzip ".$basename);
+ print "done\n";
+ $basename =~ s/\.gz$//;
+ print "Bzipping $basename... ";
+ system("bzip2 ".$basename);
+ print "done\n";
+ $basename .= ".bz2";
+ }
+ }
+
+ $found = 1 if(-e $basename);
+ $basename =~ s/bz2/gz/;
+ $found = 1 if(-e $basename);
+ }
+
+ if(!$found) { print "Unable to download file: URL is not valid ! :-/\n\n"; return; }
+
+ system("rpmbuild -ba ../SPECS/".$pkg.".spec");
+ wait;
+}
+
+sub wget_check
+{
+ my $wgetv = `wget --version`;
+ $wgetv =~ /Wget/ or die "You need `wget' binary for FTP/HTTP download\n";
+}
+
+sub parse_argv
+{
+ my $conf = AppConfig->new({ CASE => 1 });
+
+ $conf->define("rpmmon",
+ { ARGS => "!", DEFAULT => 0, ARGCOUNT => AppConfig::ARGCOUNT_NONE }
+ );
+
+ $conf->args();
+ $config{rpmmon} = $conf->get("rpmmon");
+}
+
+sub usage
+{
+ print "rpmbuildupdate v0.1 helps you build up to date RPMs.\n\n";
+ print "By Julien Danjou <jdanjou\@mandrakesoft.com>\n";
+ print "Copyright (c) 2003 by MandrakeSoft.\n";
+ print "This is free software under the GPL License.\n";
+ print "Usage: rpmbuildupdate [options] [pkg] [newversion]\n\n";
+
+ print " --rpmmon <file>: Parse output of rpmmon from file\n\n";
+ exit 0;
+}
+
+sub parse_rpmmon
+{
+ open(RPMMON, shift());
+ while(<RPMMON>)
+ { &build($1, $3) if(/^\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/);
+ &build($2, $4) if(/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ && ! /Package/); }
+ close(RPMMON);
+}
+
+sub main
+{
+ &parse_argv;
+
+
+ &wget_check;
+
+ if(!$config{rpmmon})
+ {
+ my $pkg = shift @ARGV or &usage;
+ my $version = shift @ARGV or &usage;
+ &build($pkg, $version);
+ }
+ else
+ { &parse_rpmmon($ARGV[0]); }
+}
+
+&main;