diff options
Diffstat (limited to 'rpmbuildupdate')
-rwxr-xr-x | rpmbuildupdate | 180 |
1 files changed, 113 insertions, 67 deletions
diff --git a/rpmbuildupdate b/rpmbuildupdate index 16b02c6..ccc8308 100755 --- a/rpmbuildupdate +++ b/rpmbuildupdate @@ -15,9 +15,8 @@ use strict; use AppConfig; -my $defaultrelease = "1mdk"; -my %config; +my %config; sub build_from_src { @@ -35,26 +34,24 @@ sub build my $pkgrpm = shift; my $found = 0; - my ($pkge, $version, $release, $email); - my ($spec, @url, $basename); - - my (@rpms, %specvars); + my ($version, $release); + my ($spec, @url, @rpms, %specvars); print "===> Building $pkg $newversion\n"; - $pkge = $pkg; + my $pkge = $pkg; $pkge =~ s/\+/\\\+/; - + # Search for file if we do not use --src if(!$config{src}) { - opendir(MP, $config{mountpoint}) or die "$config{mountpoint} is not a directory"; + opendir(MP, $config{srpms}) or die "$config{srpms} is not a directory"; @rpms = readdir(MP); foreach (@rpms) { if(m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) - { $pkgrpm = $_; $version = $2; $release = $3; $found = 1;} + { $pkgrpm = $_; $version = $2; $release = $3; $found = 1; last;} } closedir(MP); @@ -68,21 +65,18 @@ sub build { $version = $2; $release = $3; $found = 1;} } - if ($config{src}) { - system("rpm -ivh $pkgrpm"); - wait; - } else { - system("sudo /usr/sbin/urpmi --auto --force ".$config{mountpoint}."/".$pkgrpm); - #{ print "Error while urpmi $pkgrpm\n"; return; }; - wait; - - system("/usr/sbin/urpmi --install-src --force ".$config{mountpoint}."/".$pkgrpm); - #{ print "Error while urpmi --install-src $pkgrpm\n"; return; } + if ($config{src}) + { system("rpm -ivh $pkgrpm"); } + else + { + system("sudo /usr/sbin/urpmi --auto --force ".$config{srpms}."/".$pkgrpm); wait; - } + system("/usr/sbin/urpmi --install-src --force ".$config{srpms}."/".$pkgrpm); + } + wait; my $top = `rpm --eval '%_topdir'`; - chop($top); + chomp($top); chdir("$top/SOURCES") or die "Unable to chdir to $top/SOURCES"; $found = 0; @@ -95,12 +89,12 @@ sub build while(<SPECFILE>) { - # s/// version + # Doing a s/// version s/\%define\s+version\s+$version/\%define version $newversion/g; s/Version:\s+$version/Version: $newversion/g; $spec .= $_; - $spec =~ s/\%define(\s+)release(\s+)(.*)/\%define release $defaultrelease/; + $spec =~ s/\%define(\s+)release(\s+)(.*)/\%define release $config{release}/; push(@url, $2) if(/(Source|Url|Source0):\s+(\S+)/i); # For %vars ! @@ -110,10 +104,11 @@ sub build if(/\%changelog/) { + my $email; $email = $ENV{EMAIL} || qx[awk -F: '/$ENV{USER}/{print \$5}' /etc/passwd|tr -d '\n']." <$ENV{USER}\@mandrakesoft.com> "; $spec .= "* ".qx[LC_TIME=C date '+%a %b %d %Y'|tr -d '\n']." ".$email. - " ".$newversion."-".$defaultrelease."\n"; + " ".$newversion."-".$config{release}."\n"; $spec .= "- New release $newversion\n\n"; } } @@ -123,45 +118,66 @@ sub build 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/) + if(/ftp\.redhat\.com.*SRPMS/) { - s/gz/bz2/; - $basename = `basename $_`; chomp($basename); - print "Trying to fetch .bz2...\n"; - system("wget ".$_); + $found = 1; + opendir(MP, $config{rawhide}) or die "$config{rawhide} is not a directory"; + my @rpmsrh = readdir(MP); + + foreach (@rpmsrh) + { + if(m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) + { my $pkgrpmrh = $_; last;} + } + + closedir(MP); + + system("sudo /usr/sbin/urpmi --auto --force ".$config{rawhide}."/".$pkgrpmrh); + wait; + system("/usr/sbin/urpmi --install-src --force ".$config{rawhide}."/".$pkgrpmrh); + wait; + # Reinstall source to restore .spec file + #system("/usr/sbin/urpmi --install-src --force ".$config{srpms}."/".$pkgrpm); + #wait; } - elsif($basename =~ /bz2/) + else { - s/bz2/gz/; - print "Trying to fetch .gz...\n"; + # 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 gz was downloaded, recompressing it in bz2 - if(-f $basename) + my $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/) { - system("bzme ".$basename); - $basename =~ s/bz2/gz/; + 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) + { + system("bzme ".$basename); + $basename =~ s/bz2/gz/; + } } } @@ -169,14 +185,19 @@ sub build $basename =~ s/bz2/gz/; $found = 1 if(-e $basename); } + + open(SPECFILE, ">../SPECS/".$pkg.".spec") or die "Unable to open $pkg.spec"; + print SPECFILE $spec; + close(SPECFILE); + if(!$found) - { print "Unable to download file: URL is not valid ! :-/\n\n"; return; } + { print "Unable to download file: URL is not valid ! :-(\n\n"; return; } if(system("rpm -ba ../SPECS/".$pkg.".spec")) { wait; - print "Build fails: building source only\n"; + print "Binary build fails: building source only\n"; system("rpm -bs ../SPECS/".$pkg.".spec"); } wait; @@ -195,10 +216,17 @@ sub parse_argv $conf->define("rpmmon", { ARGS => "=s", ALIAS => "r", - ARGCOUNT => AppConfig::ARGCOUNT_NONE } + ARGCOUNT => AppConfig::ARGCOUNT_ONE } + ); + + $conf->define("release", + { ARGS => "=s", + ALIAS => "l", + DEFAULT => "1mdk", + ARGCOUNT => AppConfig::ARGCOUNT_ONE } ); - $conf->define("mountpoint", + $conf->define("srpms", { ARGS => "=s", ALIAS => "m", DEFAULT => "/mnt/BIG/distrib/cooker/SRPMS/", @@ -210,26 +238,35 @@ sub parse_argv ALIAS => "s", ARGCOUNT => AppConfig::ARGCOUNT_ONE } ); - + $conf->define("rawhide", + { ARGS => "=s", + ALIAS => "h", + DEFAULT => "/mnt/BIG/distrib/rawhide/SRPMS/SRPMS/", + ARGCOUNT => AppConfig::ARGCOUNT_ONE } + ); + $conf->args(); $config{rpmmon} = $conf->get("rpmmon"); - $config{mountpoint} = $conf->get("mountpoint"); + $config{srpms} = $conf->get("srpms"); $config{src} = $conf->get("src"); + $config{release} = $conf->get("release"); + $config{rawhide} = $conf->get("rawhide"); } sub usage { - print "rpmbuildupdate v0.2 helps you build up to date RPMs.\n\n"; + print "rpmbuildupdate v0.3 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"; - print " -m <mount point>: Specify mount point of \n"; + print " --srpms <path_to_srpms>: Specify SRPMS path\n"; print " --src <src.rpm file> <new version>: Build new version from this source RPM\n"; + print " --release <mdk_release>: Release version of package (default: 1mdk)\n"; exit 0; } @@ -238,13 +275,22 @@ sub parse_rpmmon my $f; ($f = shift()); -f $f or die "Error: $f is not a file.\n"; + open(RPMMON, $f); 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/); } + { + &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 check_dir +{ + $_ = shift; + -d $_ or die $_." is not a directory.\n"; +} + sub main { &parse_argv; @@ -253,13 +299,13 @@ sub main if($config{rpmmon}) { - -d $config{mountpoint} or die $config{mountpoint}." is not a directory.\n"; + print($config{srpms}); &parse_rpmmon($config{rpmmon}); } elsif($config{src} && $ARGV[0]) { &build_from_src($config{src}, $ARGV[0]); } elsif($ARGV[0] && $ARGV[1]) { - -d $config{mountpoint} or die $config{mountpoint}." is not a directory.\n"; + &check_dir($config{srpms}); &build($ARGV[0], $ARGV[1]); } else |