5372N/A#!/usr/bin/perl -w
5372N/A
5372N/A# Increment the tarball build number in Moz/Evo/APOC spec files.
5372N/A#
5372N/A# Created by Damien Carbery, 25 April 2005.
5372N/A
5372N/A
5372N/Ause strict;
5372N/Ause Getopt::Long;
5372N/Ause File::Basename;
5372N/Ause POSIX; # For strftime.
5372N/A
5372N/A
5372N/A# Display usage information.
5372N/Asub Usage
5372N/A{
5372N/A my $ScriptName = basename( $0 );
5372N/A
5372N/A print << "END_OF_USAGE_INFO";
5372N/AIncrement the build source tarball number and add %changelog entry.
5372N/AUsage: $ScriptName -buildnum num
5372N/A
5372N/A-buildnum Specify build number to insert into spec files. (Required)
5372N/A-email Specify email address to be listed in %changelog.
5372N/A-help Display this usage information.
5372N/AEND_OF_USAGE_INFO
5372N/A
5372N/A exit 1; # Indicate an error.
5372N/A}
5372N/A
5372N/A
5372N/A# ####################################
5372N/A# Main program.
5372N/A# ####################################
5372N/A
5372N/A
5372N/A# Display usage if no arguments.
5372N/AUsage if ( $#ARGV == -1 );
5372N/A
5372N/Amy $DisplayHelp = 0;
5372N/Amy $BuildNum;
5372N/Amy $Email = 'dermot.mccluskey@sun.com';
5372N/A
5372N/A# ############################
5372N/A# Begin command line parsing.
5372N/A# ############################
5372N/A#Getopt::Long::Configure( 'pass_through' ); # Ignore unknown options.
5372N/AGetOptions( 'buildnum=i' => \$BuildNum,
5372N/A 'email=s' => \$Email,
5372N/A 'help' => \$DisplayHelp );
5372N/A
5372N/AUsage if ( $DisplayHelp );
5372N/AUsage if ( ! defined $BuildNum );
5372N/A
5372N/A
5372N/A# List of spec files to update.
5386N/Amy @specfiles = qw / apoc.spec evolution.spec gnome-spell.spec gtkhtml.spec hydrogen.spec libgal.spec libsoup.spec mozilla.spec oxygen2.spec /;
5372N/A
5372N/Aforeach my $file ( @specfiles )
5372N/A{
5372N/A # Ensure all the specified files are present, quitting if any aren't.
5372N/A my $MissingFiles = 0;
5372N/A foreach my $file ( @ARGV )
5372N/A {
5372N/A if ( ! -r $file )
5372N/A {
5372N/A print "ERROR: $file is missing or not readable.\n";
5372N/A $MissingFiles++;
5372N/A }
5372N/A }
5372N/A exit 1 if ( $MissingFiles );
5372N/A}
5372N/A
5372N/A
5385N/A# Change t_suffix and Release data and add %changelog entry for each file.
5372N/Aforeach my $file ( @specfiles )
5372N/A{
5372N/A if ( open( IN, '<' . $file ) )
5372N/A {
5372N/A if ( open( OUT, '>' . $file . ".$$" ) )
5372N/A {
5372N/A while ( <IN> )
5372N/A {
5372N/A if ( /^(%define t_suffix \D+)(\d+)(\D+)$/ )
5372N/A {
5372N/A print OUT $1,$BuildNum,$3;
5372N/A }
5385N/A elsif ( /^(Release:\s+)(\d+)(\D+)$/ )
5385N/A {
5385N/A print OUT $1,(${2}+1),$3;
5385N/A }
5372N/A elsif ( /^%changelog$/ )
5372N/A {
5372N/A print OUT;
5401N/A print OUT '* ', strftime("%a %b %d %Y",localtime), " - $Email\n- Bump source tarball to build $BuildNum.\n\n";
5372N/A }
5372N/A else
5372N/A {
5372N/A print OUT;
5372N/A }
5372N/A }
5372N/A
5372N/A close( OUT );
5372N/A }
5372N/A close( IN );
5372N/A rename( $file . ".$$", $file );
5372N/A print "$file - done\n";
5372N/A }
5372N/A else
5372N/A {
5372N/A print "WARNING: Unable to open $file ($!). Skipping.\n";
5372N/A }
5372N/A}
5372N/A
5372N/A# Update ChangeLog too, putting info at the top of the file.
5372N/Aif ( open( IN, '<' . 'ChangeLog' ) )
5372N/A{
5372N/A if ( open( OUT, '>' . 'ChangeLog' . ".$$" ) )
5372N/A {
5401N/A print OUT strftime("%Y-%m-%d",localtime), " <$Email>\n\n";
5372N/A print OUT "\t* ", join( ' ', @specfiles[0..4] ), "\n\t", join( ' ', @specfiles[5..$#specfiles] ), ":\n\t* Bump source tarballs to build $BuildNum.\n\n";
5372N/A # Just pass-through the rest of the lines.
5372N/A print OUT while ( <IN> );
5372N/A close( OUT );
5372N/A }
5372N/A close( IN );
5372N/A rename( 'ChangeLog'. ".$$", 'ChangeLog' );
5372N/A print "ChangeLog - done\n";
5372N/A}
5372N/A
5372N/Aprint "\nUse 'cvs diff' to verify changes.\nTo commit changes:\n cvs commit -m \"Bump source tarballs for Mozilla/Evolution/APOC\"\n";