diff options
author | Michael Scherer <misc@mandriva.com> | 2004-09-05 00:04:06 +0000 |
---|---|---|
committer | Michael Scherer <misc@mandriva.com> | 2004-09-05 00:04:06 +0000 |
commit | 13ad421df5e7716427bbfbe46224a35b016a31e9 (patch) | |
tree | 06eb0b80b3bc18f3b08c1b958d28f0204c6c02a4 /rpmbuildupdate | |
parent | 89e1cf9782236a7d933504694a73fb00b7dd4b40 (diff) | |
download | bootsplash-13ad421df5e7716427bbfbe46224a35b016a31e9.tar bootsplash-13ad421df5e7716427bbfbe46224a35b016a31e9.tar.gz bootsplash-13ad421df5e7716427bbfbe46224a35b016a31e9.tar.bz2 bootsplash-13ad421df5e7716427bbfbe46224a35b016a31e9.tar.xz bootsplash-13ad421df5e7716427bbfbe46224a35b016a31e9.zip |
- perl_checker fix, remove obsolete construct ( &func )
- rebuild the package if no new version is given
- add two config file ( /etc/rpmbuildupdate.conf and ~/.rpmbuildupdate.conf )
- add a new mirror to sourceforge ( ovh, france )
- keep prefix (ie plfawarness )
- add a changelog option to use another changelog message
- check if options are valid and show help if not
- do not use %packager if not defined
Diffstat (limited to 'rpmbuildupdate')
-rwxr-xr-x | rpmbuildupdate | 285 |
1 files changed, 149 insertions, 136 deletions
diff --git a/rpmbuildupdate b/rpmbuildupdate index 2fa5c15..8c2fe0f 100755 --- a/rpmbuildupdate +++ b/rpmbuildupdate @@ -15,7 +15,6 @@ # TODO # do not hardcode sudo urpmi command ( to use --deps on cluster ) # rework configuration option -# remove TODO and &sub call use strict; use AppConfig; @@ -26,111 +25,100 @@ use Cwd; my %config; -sub system_die -{ - my ($command,$message) = @_; - $message = "$command failed" if not $message; +sub system_die { + my ($command, $message) = @_; + $message = "$command failed" if ! $message; # do not forget , return value of 1 means failure in unix - system("$command") and die "$message"; + system($command) and die $message; } -sub build_from_src -{ +sub build_from_src { $_ = shift; my $nv = shift; - my $b; - $b = basename($_) ; - if($b =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) - { &build($1, $nv, $_); } + my $b = basename($_); + if ($b =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) + { build($1, $nv, $_) } } -sub file_not_found -{ +sub file_not_found { my ($basename) = @_; - ( ! -f $basename ) && return 1; + ! -f $basename && return 1; # sometimes, the webserver return a webpage when the file is not found, instead of letting wget fails # see wget http://www.wesnoth.org/files/wesnoth-0.7.1.tar.bz2 # So if the file is a html page, then it is a error and it should be removed. - is_html($basename) && do { rm_rf("$basename") ; return 1 ; }; + is_html($basename) && do { rm_rf($basename); return 1 }; return 0; } -sub is_html -{ +sub is_html { my ($basename) = @_; - `file $basename` =~ /HTML/i && return 1 ; + `file $basename` =~ /HTML/i && return 1; return 0; } -sub download -{ +sub download { my $wget = "wget -N -q"; my ($url)=@_; my $temp = basename($url); print "Trying to fetch $url...\n"; system("$wget $url;"); - -f "$temp" && ( ! is_html($temp) ) && ( $temp !~ /.bz2$/ ) && system_die("bzme $temp","Cannot convert $temp"); + -f $temp && ! is_html($temp) && $temp !~ /.bz2$/ && system_die("bzme $temp", "Cannot convert $temp"); } -sub fetch -{ +sub fetch { my ($url) = @_; # if you add a handler here, do not forget to add it to the body of build() - return fetch_http($url) if ($url =~ m!^(ftp|https?)://! ); - return fetch_svn($url) if ($url =~ m!^svns?://! ); + return fetch_http($url) if $url =~ m!^(ftp|https?)://!; + return fetch_svn($url) if $url =~ m!^svns?://!; } -sub fetch_svn -{ +sub fetch_svn { my ($url) = @_; - my ($basename,$repos); + my ($basename, $repos); $basename = basename($url); - ( $repos = $url ) =~ s|/$basename$||; + ($repos = $url) =~ s|/$basename$||; $repos =~ s/^svn/http/; $basename =~ /^(.*)-([^-]*rev)(\d\d*).tar.bz2$/; - my ( $name,$prefix,$release ) = ($1,$2,$3); + my ($name, $prefix, $release) = ($1, $2, $3); my $dir="$ENV{TMP}/rpmbuildupdate-$$"; my $current_dir = cwd(); mkdir $dir or die "Cannot create dir $dir"; chdir $dir or die "Cannot change dir to $dir"; - system_die("svn co -r $release $repos","svn checkout failed on $repos"); + system_die("svn co -r $release $repos", "svn checkout failed on $repos"); my $basedir = basename($repos); # FIXME quite inelegant, should use a dedicated cpan module. my $complete_name = "$name-$prefix$release"; - move($basedir,$complete_name); + move($basedir, $complete_name); system_die("find $complete_name -name '.svn' | xargs rm -Rf"); system_die("tar -cjf $complete_name.tar.bz2 $complete_name", "tar failed"); system_die("mv -f $complete_name.tar.bz2 $current_dir"); chdir $current_dir; } -sub fetch_http -{ +sub fetch_http { my ($url) = @_; my $basename = basename($url); my $turl; - rm_rf("$basename") if ($config{nobuild}); + rm_rf($basename) if $config{nobuild}; download($url); - foreach ('.tar.gz' , '.tgz' , '.zip' ) + foreach ('.tar.gz', '.tgz', '.zip') { ($turl = $url) =~ s/\.tar\.bz2/$_/; - download($turl) if (file_not_found($basename)); + download($turl) if file_not_found($basename); } - return ! file_not_found($basename); } -sub build -{ +sub build { my $pkg = shift; my $newversion = shift; my $pkgrpm = shift; my ($rpm, $log); - + my ($release_prefix, $newrelease, $message); my $found = 0; my ($version, $release); my ($spec, @url, @rpms, %specvars); @@ -141,35 +129,53 @@ sub build $rpm = qq(rpm --define "_topdir $top"); - print "===> Building $pkg $newversion\n"; + if ($newversion) { + print "===> Building $pkg $newversion\n"; + } else { + print "===> Rebuilding $pkg\n"; + } + + my $pkge = $pkg; $pkge =~ s/\+/\\\+/; # Search for file if we do not use --src - if(!$config{src}) + if (!$config{src}) { opendir(MP, $config{srpms}) or die "$config{srpms} is not a directory"; @rpms = readdir(MP); foreach (@rpms) { - if(m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) - { $config{src} = $pkgrpm = "$config{srpms}/$_"; $version = $2; $release = $3; $found = 1; last;} + if (m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) + { $config{src} = $pkgrpm = "$config{srpms}/$_"; $version = $2; $release = $3; $found = 1; last } } closedir(MP); - if($found == 0) { print "Package $pkg has no source, skipping.\n\n"; return; } - } - else - { + if ($found == 0) { print "Package $pkg has no source, skipping.\n\n"; return } + } else { my $pkgrpm_basename = basename($pkgrpm); - if($pkgrpm_basename =~ m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) - { $version = $2; $release = $3; $found = 1;} + if ($pkgrpm_basename =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) + { $pkg=$1; $version = $2; $release = $3; $found = 1 } } - if($config{log}) + ($newrelease,$release_prefix) = ($1,$2) if $release =~ /^(.*\d+)(\D*)$/g; + + if (! defined($newversion)) { + $newversion = $version; + my @tmp = split(/\./,$newrelease); + $tmp[-1]++; + $release = join('.',@tmp) . $release_prefix; + $message = $config{message} || '- Rebuild'; + } else { + $message = $config{message} || '- New release %%VERSION'; + $release = "1$release_prefix"; + } + $release = $config{release} if $config{release}; + + if ($config{log}) { my $basename = basename($pkgrpm); mkdir_p("$top/log"); @@ -178,74 +184,73 @@ sub build $log = ""; } - if($config{deps}) + if ($config{deps}) { system_die("sudo /usr/sbin/urpmi --auto --force $pkgrpm $log"); } - if($config{src}) + if ($config{src}) { system_die("$rpm -ivh $pkgrpm $log"); $config{src} = 0; - } - elsif(!$config{nosource}) - { + } elsif (!$config{nosource}) { system_die("/usr/sbin/urpmi --install-src --force $config{srpms} $log"); } $found = 0; - - if(!open(SPECFILE, "../SPECS/".$pkg.".spec")) + + my $SPECFILE; + if (!open($SPECFILE, "../SPECS/$pkg.spec")) { print STDERR "Unable to open spec file !\n"; return; } my $tar_ball; - - while(<SPECFILE>) + while (<$SPECFILE>) { # 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 $config{release}/; - $spec =~ s/Release\s*:(\s+)(\S*mdk)/Release:$1$config{release}/; - push(@url, $2) if(/(Source[0-9]*)\s*:\s+((?:ftp|svns?|https?):\S+)/i); - $tar_ball=$2 if(/(Source[0-9]*)\s*:\s+([^:\s]+)/i) and not $tar_ball; + $spec =~ s/\%define(\s+)release(\s+)(.*)/\%define release $release/; + $spec =~ s/Release\s*:(\s*)(\S*)/Release: $release/; + push(@url, $2) if /(Source[0-9]*)\s*:\s+((?:ftp|svns?|https?):\S+)/i; + $tar_ball=$2 if /(Source[0-9]*)\s*:\s+([^:\s]+)/i and ! $tar_ball; # For %vars ! - $specvars{$1} = $2 if(/\%define\s+(\S+?)\s+(\S+)/g); - for my $i ( 'url','name','version' ) + $specvars{$1} = $2 if /\%define\s+(\S+?)\s+(\S+)/g; + foreach my $i ('url', 'name', 'version', 'release') { - $specvars{$i} = $1 if(!$specvars{$i} && /$i\s*:\s+(\S+)/gi); + $specvars{$i} = $1 if !$specvars{$i} && /$i\s*:\s+(\S+)/gi; } - - if(/\%changelog/) + + if (/\%changelog/) { - my $email; + $message =~ s/\%\%VERSION/$newversion/; my @l = getpwuid($<); my $packager = `rpm --eval '\%packager'`; chomp($packager); - $email = $packager ? $packager : ( $ENV{EMAIL} ? $l[6]." <$ENV{EMAIL}>" : $l[6]." <$l[0]\@mandrakesoft.com>"); - $spec .= "* ".`LC_TIME=C date '+%a %b %e %Y'|tr -d '\n'`." ".$email. - " ".$newversion."-".$config{release}."\n"; - $spec .= "- New release $newversion\n\n"; + # if macro is undefined + $packager =~ s/\%packager//g; + my $email = $packager ? $packager : $l[6] . ( $ENV{EMAIL} ? " <$ENV{EMAIL}>" : " <$l[0]\@mandrakesoft.com>"); + $spec .= "* " . `LC_TIME=C date '+%a %b %e %Y'|tr -d '\n'` . " $email $newversion-$release\n"; + $spec .= "$message\n\n"; } } - close(SPECFILE); + close($SPECFILE); - if(!$url[0]) + if (!$url[0]) { print "URL of sources was not found ! Trying to guess it with url tag ...\n"; - my $url=$specvars{'url'}; + my $url=$specvars{url}; if ($url =~ m!http://(.*)\.((?:sourceforge|sf)\.net)/(.*)!) { $url="http://prdownloads.$2/$1/$3" unless $1 eq 'prdownloads'; } - push(@url, $url.'/'.$tar_ball) + push(@url, "$url/$tar_ball") } $found = 0; @@ -253,7 +258,7 @@ sub build foreach (@url) { # Replace variable from spec (%blabla) - while(/\%/) + while (/\%/) { s/\%\{(.*?)\}/$specvars{$1}/g; s/\%(\w+)/$specvars{$1}/g; @@ -263,7 +268,7 @@ sub build my $basename = basename($_); - rm_rf("${top}/SOURCES/$basename") if ($config{nobuild}); + rm_rf("${top}/SOURCES/$basename") if $config{nobuild}; # GNOME: add the major version to the URL automatically # for example: ftp://ftp://ftp.gnome.org/pub/GNOME/sources/ORbit2/ORbit2-2.10.0.tar.bz2 @@ -275,7 +280,7 @@ sub build } # download from Fedora rpms - if(/ftp\.redhat\.com/) + if (/ftp\.redhat\.com/) { opendir(MP, $config{fedora}) or die "$config{fedora} is not a directory"; my @rpmsrh = readdir(MP); @@ -283,26 +288,27 @@ sub build my $pkgrpmrh; foreach (@rpmsrh) { - if(m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) - { $pkgrpmrh = $_; last;} + if (m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) + { $pkgrpmrh = $_; last } } closedir(MP); print "Trying from fedora($basename): $config{fedora}/$pkgrpmrh\n"; - system_die("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $basename","Rpm extraction failed"); + system_die("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $basename", "Rpm extraction failed"); if (! -f "${top}/SOURCES/$basename") { (my $bname = $basename) =~ s/bz2/gz/; print "Trying from fedora($bname): $config{fedora}/$pkgrpmrh\n"; - system("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $bname; bzme $bname","rpm recompression failed"); + system("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $bname; bzme $bname", "rpm recompression failed"); } } # download from sourceforge mirrors if (m!http://prdownloads.sourceforge.net!) { - foreach my $site ("http://heanet.dl.sourceforge.net/sourceforge/", + foreach my $site ("http://ovh.dl.sourceforge.net/sourceforge/", + "http://heanet.dl.sourceforge.net/sourceforge/", "http://aleron.dl.sourceforge.net/sourceforge/", "http://keihanna.dl.sourceforge.net/sourceforge/", "http://belnet.dl.sourceforge.net/sourceforge/", @@ -311,7 +317,7 @@ sub build ) { (my $dest = $_) =~ s!http://prdownloads.sourceforge.net/!$site!; - last if (fetch_http($dest)); + last if fetch_http($dest); } } # download specified url @@ -320,17 +326,17 @@ sub build fetch($_); } - $found++ if(-e $basename); - chmod(0644,"${top}/SOURCES/$basename"); + $found++ if -e $basename; + chmod(0644, "${top}/SOURCES/$basename"); } # TODO use output ? - open(SPECFILE, ">../SPECS/".$pkg.".spec") or die "Unable to open $pkg.spec"; - print SPECFILE $spec; - close(SPECFILE); + open($SPECFILE, ">../SPECS/$pkg.spec") or die "Unable to open $pkg.spec"; + print $SPECFILE $spec; + close($SPECFILE); - if(!$found) + if (!$found) { print "Unable to download file: URL is not valid ! :-(\n\n"; return; @@ -338,23 +344,21 @@ sub build print "All files downloaded\n"; return; } - - if(system("$rpm -ba ../SPECS/".$pkg.".spec $log")) + + if (system("$rpm -ba ../SPECS/$pkg.spec $log")) { print "Binary build fails: building source only\n"; system("$rpm -bs --nodeps ../SPECS/$pkg.spec $log"); } } -sub wget_check -{ +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 }); +sub parse_argv { + my $conf = AppConfig->new({ CASE => 1,ERROR =>\&usage }); $conf->define("rpmmon", { ARGS => "=s", @@ -364,7 +368,7 @@ sub parse_argv $conf->define("release", { ARGS => "=s", - DEFAULT => "1mdk", + DEFAULT => "", ARGCOUNT => AppConfig::ARGCOUNT_ONE } ); @@ -417,7 +421,20 @@ sub parse_argv DEFAULT => 0, ARGCOUNT => AppConfig::ARGCOUNT_NONE } ); - $conf->args(); + $conf->define("changelog", + { + ARGS => "=s", + # default is defined at the beggining of build + # as it depend if this is a new version or a simple rebuild + DEFAULT => "", + ARGCOUNT => AppConfig::ARGCOUNT_ONE } + ); + + foreach my $f ('/etc/rpmbuildupdate.conf',"$ENV{HOME}/.rpmbuildupdate.conf") + { + -f $f && $conf->file($f) ; + } + $conf->args; $config{rpmmon} = $conf->get("rpmmon"); $config{deps} = $conf->get("deps"); $config{srpms} = $conf->get("srpms"); @@ -427,12 +444,12 @@ sub parse_argv $config{fedora} = $conf->get("fedora"); $config{top} = $conf->get("top"); $config{nobuild} = $conf->get("nobuild"); + $config{message} = $conf->get("changelog"); $config{log} = $conf->get("log"); } -sub usage -{ +sub usage { 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"; @@ -443,6 +460,7 @@ sub usage 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"; + print " --changelog <changelog message>: use a alternate message. \%\%VERSION is replace by version\n"; print " --deps: install builds dependencies\n"; print " --log: log builds\n"; print " --nosource: do not install source from (urpmi x.src.rpm)\n"; @@ -451,48 +469,43 @@ sub usage exit 0; } -sub parse_rpmmon -{ - my $f; - ($f = shift()); +sub parse_rpmmon { + my $f = shift; -f $f or die "Error: $f is not a file.\n"; - open(RPMMON, $f); - while(<RPMMON>) + open(my $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); + close($RPMMON); } -sub check_dir -{ +sub check_dir { $_ = shift; - -d $_ or die $_." is not a directory.\n"; + -d $_ or die $_ . " is not a directory.\n"; } -sub main -{ - &parse_argv; - &wget_check; +sub main { + parse_argv; + + wget_check; - if($config{rpmmon}) - { + if ($config{rpmmon}) { print($config{srpms}); - &parse_rpmmon($config{rpmmon}); - } - elsif($config{src} && $ARGV[0]) - { &build_from_src($config{src}, $ARGV[0]); } - elsif($ARGV[0] && $ARGV[1]) - { - &check_dir($config{srpms}); - &build($ARGV[0], $ARGV[1]); + parse_rpmmon($config{rpmmon}) + } elsif ($config{src} && $ARGV[0]) { + build_from_src($config{src}, $ARGV[0]) + } elsif ($ARGV[0] && $ARGV[1]) { + check_dir($config{srpms}); + build($ARGV[0], $ARGV[1]) + } elsif ($config{src}) { + build_from_src($config{src}) + } else { + usage } - else - { &usage; } - } -&main; +main; |