.
[coreutils.git] / announce-gen
blob7f1c41399aedf64e2a946d12b8bd07895bc590cd
1 #!/usr/bin/perl -w
2 # Generate an announcement message.
3 use strict;
5 use Getopt::Long;
6 use Digest::MD5;
7 use Digest::SHA1;
9 (my $VERSION = '$Revision: 1.4 $ ') =~ tr/[0-9].//cd;
10 (my $ME = $0) =~ s|.*/||;
12 END
14 # Nobody ever checks the status of print()s. That's okay, because
15 # if any do fail, we're guaranteed to get an indicator when we close()
16 # the filehandle.
18 # Close stdout now, and if there were no errors, return happy status.
19 # If stdout has already been closed by the script, though, do nothing.
20 defined fileno STDOUT
21 or return;
22 close STDOUT
23 and return;
25 # Errors closing stdout. Indicate that, and hope stderr is OK.
26 warn "$ME: closing standard output: $!\n";
28 # Don't be so arrogant as to assume that we're the first END handler
29 # defined, and thus the last one invoked. There may be others yet
30 # to come. $? will be passed on to them, and to the final _exit().
32 # If it isn't already an error, make it one (and if it _is_ an error,
33 # preserve the value: it might be important).
34 $? ||= 1;
37 sub usage ($)
39 my ($exit_code) = @_;
40 my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
41 if ($exit_code != 0)
43 print $STREAM "Try `$ME --help' for more information.\n";
45 else
47 print $STREAM <<EOF;
48 Usage: $ME [OPTIONS]
50 OPTIONS:
52 Generate an announcement message.
54 FIXME: describe the following
56 --package-name=PACKAGE_NAME
57 --previous-version=VER
58 --current-version=VER
59 --release-archive-directory=DIR
60 --url-directory=URL_DIR
62 --help display this help and exit
63 --version output version information and exit
65 EOF
67 exit $exit_code;
71 my $package_name;
72 my $prev_version;
73 my $curr_version;
74 my $release_archive_dir;
75 my @url_dir_list;
77 GetOptions
79 'package-name=s' => \$package_name,
80 'previous-version=s' => \$prev_version,
81 'current-version=s' => \$curr_version,
82 'release-archive-directory=s' => \$release_archive_dir,
83 'url-directory=s@' => \@url_dir_list,
85 help => sub { usage 0 },
86 version => sub { print "$ME version $VERSION\n"; exit },
87 ) or usage 1;
89 my $fail = 0;
90 # Ensure that sure each required option is specified.
91 $package_name
92 or (warn "$ME: missing package name\n"), $fail = 1;
93 $prev_version
94 or (warn "$ME: missing previous version string\n"), $fail = 1;
95 $curr_version
96 or (warn "$ME: missing current version string\n"), $fail = 1;
97 $release_archive_dir
98 or (warn "$ME: missing release directory name\n"), $fail = 1;
99 @url_dir_list
100 or (warn "$ME: missing URL directory name(s)\n"), $fail = 1;
102 @ARGV
103 and (warn "$ME: too many arguments\n"), $fail = 1;
104 $fail
105 and usage 1;
107 my $my_distdir = "$package_name-$curr_version";
108 my $tgz = "$my_distdir.tar.gz";
109 my $tbz = "$my_distdir.tar.bz2";
110 my $xd = "$package_name-$prev_version-$curr_version.xdelta";
112 my %size;
114 foreach my $f (($tgz, $tbz, $xd))
116 my $cmd = "du --human $f";
117 my $t = `$cmd`;
118 # FIXME-someday: give a better diagnostic, a la $PROCESS_STATUS
120 and (warn "$ME: command failed: `$cmd'\n"), $fail = 1;
121 chomp $t;
122 $t =~ s/^([\d.]+[MkK]).*/${1}B/;
123 $size{$f} = $t;
126 $fail
127 and exit 1;
129 print <<EOF;
131 Subject: $my_distdir released
133 <#secure method=pgpmime mode=sign>
135 FIXME: put comments here
139 foreach my $url (@url_dir_list)
141 print " $url/$tgz ($size{$tgz})\n";
142 print " $url/$tbz ($size{$tbz})\n";
145 print "\nAnd here are xdelta-style diffs:\n";
146 foreach my $url (@url_dir_list)
148 print " $url/$xd ($size{$xd})\n";
151 print "\nHere are GPG detached signatures:\n";
152 foreach my $url (@url_dir_list)
154 print " $url/$tgz.sig\n";
155 print " $url/$tbz.sig\n";
158 # FIXME: clean up upon interrupt or die
159 my $tmpdir = $ENV{TMPDIR} || '/tmp';
160 my $tmp = "$tmpdir/$ME-$$";
161 unlink $tmp; # ignore failure
163 print "\nHere are the MD5 and SHA1 signatures:\n";
164 print "\n";
165 print "<#part type=text/plain filename=\"$tmp\" disposition=inline>\n"
166 . "<#/part>\n";
168 open OUT, '>', $tmp
169 or die "$ME: $tmp: cannot open for writing: $!\n";
171 foreach my $meth (qw (md5 sha1))
173 foreach my $f (($tgz, $tbz, $xd))
175 open IN, '<', $f
176 or die "$ME: $f: cannot open for reading: $!\n";
177 binmode IN;
178 my $dig =
179 ($meth eq 'md5'
180 ? Digest::MD5->new->addfile(*IN)->hexdigest
181 : Digest::SHA1->new->addfile(*IN)->hexdigest);
182 close IN;
183 print OUT "$dig $f\n";
187 close OUT
188 or die "$ME: $tmp: while writing: $!\n";
189 chmod 0400, $tmp; # ignore failure
191 # FIXME: depend on whether it's a test release
192 # sed -n "$news-r1),$news-r2)p" NEWS
193 # | grep -v '^\[';
194 # echo;
195 # echo ChangeLog entries:;
196 # find . -name ChangeLog -maxdepth 2
197 # | xargs $(CVS) diff -up -r$(prev-cvs-tag) -rHEAD
198 # | sed -n 's/^+//p'
199 # | perl -ne 'm!^\+\+ (\./)?! or print,next;'
200 # -e 'print "\n"."*"x70 ."\n"; s///; print; print "*"x70 ."\n"';