1 #!/usr/bin/perl -w 2 3 # Increment the tarball build number in Moz/Evo/APOC spec files. 4 # 5 # Created by Damien Carbery, 25 April 2005. 6 7 8 use strict; 9 use Getopt::Long; 10 use File::Basename; 11 use POSIX; # For strftime. 12 13 14 # Display usage information. 15 sub Usage 16 { 17 my $ScriptName = basename( $0 ); 18 19 print << "END_OF_USAGE_INFO"; 20 Increment the build source tarball number and add %changelog entry. 21 Usage: $ScriptName -buildnum num 22 23 -buildnum Specify build number to insert into spec files. (Required) 24 -email Specify email address to be listed in %changelog. 25 -help Display this usage information. 26 END_OF_USAGE_INFO 27 28 exit 1; # Indicate an error. 29 } 30 31 32 # #################################### 33 # Main program. 34 # #################################### 35 36 37 # Display usage if no arguments. 38 Usage if ( $#ARGV == -1 ); 39 40 my $DisplayHelp = 0; 41 my $BuildNum; 42 my $Email = 'dermot.mccluskey (at] sun.com'; 43 44 # ############################ 45 # Begin command line parsing. 46 # ############################ 47 #Getopt::Long::Configure( 'pass_through' ); # Ignore unknown options. 48 GetOptions( 'buildnum=i' => \$BuildNum, 49 'email=s' => \$Email, 50 'help' => \$DisplayHelp ); 51 52 Usage if ( $DisplayHelp ); 53 Usage if ( ! defined $BuildNum ); 54 55 56 # List of spec files to update. 57 my @specfiles = qw / apoc.spec evolution.spec gnome-spell.spec gtkhtml.spec hydrogen.spec libgal.spec libsoup.spec mozilla.spec oxygen2.spec /; 58 59 foreach my $file ( @specfiles ) 60 { 61 # Ensure all the specified files are present, quitting if any aren't. 62 my $MissingFiles = 0; 63 foreach my $file ( @ARGV ) 64 { 65 if ( ! -r $file ) 66 { 67 print "ERROR: $file is missing or not readable.\n"; 68 $MissingFiles++; 69 } 70 } 71 exit 1 if ( $MissingFiles ); 72 } 73 74 75 # Change t_suffix and Release data and add %changelog entry for each file. 76 foreach my $file ( @specfiles ) 77 { 78 if ( open( IN, '<' . $file ) ) 79 { 80 if ( open( OUT, '>' . $file . ".$$" ) ) 81 { 82 while ( <IN> ) 83 { 84 if ( /^(%define t_suffix \D+)(\d+)(\D+)$/ ) 85 { 86 print OUT $1,$BuildNum,$3; 87 } 88 elsif ( /^(Release:\s+)(\d+)(\D+)$/ ) 89 { 90 print OUT $1,(${2}+1),$3; 91 } 92 elsif ( /^%changelog$/ ) 93 { 94 print OUT; 95 print OUT '* ', strftime("%a %b %d %Y",localtime), " - $Email\n- Bump source tarball to build $BuildNum.\n\n"; 96 } 97 else 98 { 99 print OUT; 100 } 101 } 102 103 close( OUT ); 104 } 105 close( IN ); 106 rename( $file . ".$$", $file ); 107 print "$file - done\n"; 108 } 109 else 110 { 111 print "WARNING: Unable to open $file ($!). Skipping.\n"; 112 } 113 } 114 115 # Update ChangeLog too, putting info at the top of the file. 116 if ( open( IN, '<' . 'ChangeLog' ) ) 117 { 118 if ( open( OUT, '>' . 'ChangeLog' . ".$$" ) ) 119 { 120 print OUT strftime("%Y-%m-%d",localtime), " <$Email>\n\n"; 121 print OUT "\t* ", join( ' ', @specfiles[0..4] ), "\n\t", join( ' ', @specfiles[5..$#specfiles] ), ":\n\t* Bump source tarballs to build $BuildNum.\n\n"; 122 # Just pass-through the rest of the lines. 123 print OUT while ( <IN> ); 124 close( OUT ); 125 } 126 close( IN ); 127 rename( 'ChangeLog'. ".$$", 'ChangeLog' ); 128 print "ChangeLog - done\n"; 129 } 130 131 print "\nUse 'cvs diff' to verify changes.\nTo commit changes:\n cvs commit -m \"Bump source tarballs for Mozilla/Evolution/APOC\"\n"; 132