diff options
Diffstat (limited to 'rpmbuildupdate')
-rwxr-xr-x | rpmbuildupdate | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/rpmbuildupdate b/rpmbuildupdate index d78e1be..ec5cf45 100755 --- a/rpmbuildupdate +++ b/rpmbuildupdate @@ -18,6 +18,9 @@ use strict; use AppConfig; +use File::Copy; +use MDK::Common::File qw(:all); +use Cwd; my %config; @@ -25,7 +28,7 @@ sub system_die { my ($command,$message) = @_; $message = "$command failed" if not $message; - # do not forget , return value of 1 means failue in unix + # do not forget , return value of 1 means failure in unix system("$command") and die "$message"; } @@ -34,7 +37,7 @@ sub build_from_src $_ = shift; my $nv = shift; my $b; - ( $b = $_ ) =~ s!.*/!!; + $b = basename($_) ; if($b =~ m|^(.*)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) { &build($1, $nv, $_); } } @@ -43,10 +46,10 @@ sub file_not_found { my ($basename) = @_; ( ! -f $basename ) && return 1; - # sometimes, webserver give a webpage when the file is not found, instead of letting wget fails + # 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. - `file $basename` =~ /HTML/i && do { system("rm -f $basename") ; return 1 ; }; + `file $basename` =~ /HTML/i && do { rm_rf("$basename") ; return 1 ; }; return 0; } @@ -54,8 +57,7 @@ sub download { my $wget = "wget -N -q"; my ($url)=@_; - my $temp; - ( $temp = $url ) =~ s!.*/!!; + my $temp = basename($url); print "Trying to fetch $url...\n"; system("$wget $url;"); -f "$temp" && ( $temp !~ /.bz2$/ ) && system_die("bzme $temp","Cannot convert $temp"); @@ -74,23 +76,21 @@ sub fetch_svn my ($url) = @_; my ($basename,$repos); - ( $basename = $url ) =~ s!.*/!!; - print $basename , "\n"; + $basename = basename($url); ( $repos = $url ) =~ s|/$basename$||; $repos =~ s/^svn/http/; $basename =~ /^(.*)-([^-]*rev)(\d\d*).tar.bz2$/; my ( $name,$prefix,$release ) = ($1,$2,$3); my $dir="$ENV{TMP}/rpmbuildupdate-$$"; - my $current_dir=`pwd`; chomp $current_dir; + 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"); - my $basedir ; - ( $basedir = $repos ) =~ s!.*/!!; + my $basedir = basename($repos); # FIXME quite inelegant, should use a dedicated cpan module. my $complete_name = "$name-$prefix$release"; - system_die("mv $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"); @@ -100,11 +100,10 @@ sub fetch_svn sub fetch_http { my ($url) = @_; - my $basename; - ( $basename = $url ) =~ s!.*/!!; + my $basename = basename($url); my $turl; - system("rm -f $basename") if ($config{nobuild}); + rm_rf("$basename") if ($config{nobuild}); download($url); foreach ('.tar.gz' , '.tgz' , '.zip' ) @@ -156,17 +155,15 @@ sub build } else { - my $pkgrpm_basename; - ( $pkgrpm_basename = $pkgrpm ) =~ s!.*/!!; + my $pkgrpm_basename = basename($pkgrpm); if($pkgrpm_basename =~ m|^($pkge)-([^-]+)-([^-]+)\.[^\.]+\.rpm|) { $version = $2; $release = $3; $found = 1;} } if($config{log}) { - my $basename; - ( $basename = $pkgrpm ) =~ s!.*/!!; - system("mkdir -p $top/log"); + my $basename = basename($pkgrpm); + mkdir_p("$top/log"); $log = " >> $top/log/${basename}.log 2>&1"; } else { $log = ""; @@ -175,19 +172,16 @@ sub build if($config{deps}) { system_die("sudo /usr/sbin/urpmi --auto --force $pkgrpm $log"); - wait; } if($config{src}) { system_die("$rpm -ivh $pkgrpm $log"); - wait; $config{src} = 0; } elsif(!$config{nosource}) { system_die("/usr/sbin/urpmi --install-src --force $config{srpms} $log"); - wait; } $found = 0; @@ -214,7 +208,7 @@ sub build # For %vars ! $specvars{$1} = $2 if(/\%define\s+(\S+?)\s+(\S+)/g); - for my $i ( 'url','name','version' ) + for my $i ( 'url','name','version' ) { $specvars{$i} = $1 if(!$specvars{$i} && /$i\s*:\s+(\S+)/gi); } @@ -235,7 +229,7 @@ sub build if(!$url[0]) { print "URL of sources was not found ! Trying to guess it with url tag ...\n"; - push(@url, $specvars{'url'}.$tar_ball) + push(@url, $specvars{'url'}.'/'.$tar_ball) } $found = 0; @@ -251,10 +245,9 @@ sub build s/\%\{version\}/$newversion/gi; } - my $basename; - ($basename=$_)=~ s!.*/!!; + my $basename = basename($_); - system("rm -f ${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 @@ -282,14 +275,12 @@ sub build print "Trying from fedora($basename): $config{fedora}/$pkgrpmrh\n"; system_die("cd ${top}/SOURCES; rpm2cpio $config{fedora}/$pkgrpmrh | cpio -id $basename","Rpm extraction failed"); - wait; 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"); - wait; } } # download from sourceforge mirrors @@ -314,7 +305,7 @@ sub build } $found++ if(-e $basename); - system("chmod 0644 ${top}/SOURCES/$basename"); + chmod(0644,"${top}/SOURCES/$basename"); } open(SPECFILE, ">../SPECS/".$pkg.".spec") or die "Unable to open $pkg.spec"; @@ -333,11 +324,9 @@ sub build if(system("$rpm -ba ../SPECS/".$pkg.".spec $log")) { - wait; print "Binary build fails: building source only\n"; system("$rpm -bs --nodeps ../SPECS/$pkg.spec $log"); } - wait; } sub wget_check |