Merge branch 'master' of git://git.pcp.io/kenj/pcp into kenj-merge
[pcp.git] / scripts / unspin-rawhide
blob34132dad082bcac4164d3679b37f1b7822906f09
1 #!/usr/bin/perl -w
3 use strict;
4 use Getopt::Long;
6 my $specfile = 'pcp.spec';
7 if (@ARGV) {
8 GetOptions (
9 'spec=s' => \$specfile,
13 open(my $fh, '<:encoding(UTF-8)', $specfile)
14 or die "Could not open '$specfile' $!";
16 # state variables
17 my $state = 'before-changelog';
18 my $entry = '';
19 my $discard = 0;
21 # process the specfile
22 while (my $row = <$fh>) {
23 if ($state eq 'before-changelog') {
24 # handful of special cases toward the start of the spec
25 $row =~ s#ftp://oss.sgi.com#ftp://ftp.pcp.io#;
26 $row =~ s#^Release: .*%\{\?dist\}#Release: \%\{buildversion}%{?dist}#;
27 $row =~ s#%{name}-%{version}-.*\.tar\.gz#ftp://ftp.pcp.io/projects/pcp/download/%{name}-%{version}.src.tar.gz#;
29 print $row;
32 if ($row =~ '^%changelog') {
33 $state = 'within-changelog';
34 next; # report the heading (above) & continue
35 } elsif ($state eq 'before-changelog') {
36 next; # not yet reached the changelog section
39 # separate out the changelog entries, discard the weekly ones
40 if ($row =~ '^\* ') {
41 # first deal with any previous entry
42 print $entry if ($entry ne '' and $discard == 0);
43 # now begin capturing this new entry
44 $state = 'capturing-entry';
45 $entry = $row;
46 $discard = 0;
47 } elsif ($row =~ 'Automated weekly rawhide release') {
48 $discard = 1;
49 } else {
50 $entry .= $row;
53 print $entry if ($entry ne '' and $discard == 0);
54 close $fh;