|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eval 'exec perl -wSx "$0" "$@"' |
|
if 0; |
|
|
|
my $VERSION = '2022-07-10 01:47'; |
|
|
|
|
|
|
|
|
|
|
|
my $copyright_year = '2022'; |
|
|
|
use strict; |
|
use Getopt::Long; |
|
use POSIX qw(strftime); |
|
|
|
(my $ME = $0) =~ s|.*/||; |
|
|
|
my %valid_release_types = map {$_ => 1} qw (alpha beta stable); |
|
my @archive_suffixes = qw (tar.gz tar.bz2 tar.lz tar.lzma tar.xz); |
|
my $srcdir = '.'; |
|
|
|
sub usage ($) |
|
{ |
|
my ($exit_code) = @_; |
|
my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR); |
|
if ($exit_code != 0) |
|
{ |
|
print $STREAM "Try '$ME --help' for more information.\n"; |
|
} |
|
else |
|
{ |
|
my @types = sort keys %valid_release_types; |
|
print $STREAM <<EOF; |
|
Usage: $ME [OPTIONS] |
|
Generate an announcement message. Run this from builddir. |
|
|
|
OPTIONS: |
|
|
|
These options must be specified: |
|
|
|
--release-type=TYPE TYPE must be one of @types |
|
--package-name=PACKAGE_NAME |
|
--previous-version=VER |
|
--current-version=VER |
|
--gpg-key-id=ID The GnuPG ID of the key used to sign the tarballs |
|
--url-directory=URL_DIR |
|
|
|
The following are optional: |
|
|
|
--news=NEWS_FILE include the NEWS section about this release |
|
from this NEWS_FILE; accumulates. |
|
--srcdir=DIR where to find the NEWS_FILEs (default: $srcdir) |
|
--bootstrap-tools=TOOL_LIST a comma-separated list of tools, e.g., |
|
autoconf,automake,bison,gnulib |
|
--gnulib-version=VERSION report VERSION as the gnulib version, where |
|
VERSION is the result of running git describe |
|
in the gnulib source directory. |
|
required if gnulib is in TOOL_LIST. |
|
--gpg-key-email=EMAIL The email address of the key used to |
|
sign the tarballs |
|
--gpg-keyring-url=URL URL pointing to keyring containing the key used |
|
to sign the tarballs |
|
--no-print-checksums do not emit SHA1 or SHA256 checksums |
|
--archive-suffix=SUF add SUF to the list of archive suffixes |
|
--mail-headers=HEADERS a space-separated list of mail headers, e.g., |
|
To: x\@example.com Cc: y-announce\@example.com,... |
|
|
|
--help display this help and exit |
|
--version output version information and exit |
|
|
|
EOF |
|
} |
|
exit $exit_code; |
|
} |
|
|
|
|
|
=item C<%size> = C<sizes (@file)> |
|
|
|
Compute the sizes of the C<@file> and return them as a hash. Return |
|
C<undef> if one of the computation failed. |
|
|
|
=cut |
|
|
|
sub sizes (@) |
|
{ |
|
my (@file) = @_; |
|
|
|
my $fail = 0; |
|
my %res; |
|
foreach my $f (@file) |
|
{ |
|
my $cmd = "du -h $f"; |
|
my $t = `$cmd`; |
|
|
|
$@ |
|
and (warn "command failed: '$cmd'\n"), $fail = 1; |
|
chomp $t; |
|
$t =~ s/^\s*([\d.]+[MkK]).*/${1}B/; |
|
$res{$f} = $t; |
|
} |
|
return $fail ? undef : %res; |
|
} |
|
|
|
=item C<print_locations ($title, \@url, \%size, @file) |
|
|
|
Print a section C<$title> dedicated to the list of <@file>, which |
|
sizes are stored in C<%size>, and which are available from the C<@url>. |
|
|
|
=cut |
|
|
|
sub print_locations ($\@\%@) |
|
{ |
|
my ($title, $url, $size, @file) = @_; |
|
print "Here are the $title:\n"; |
|
foreach my $url (@{$url}) |
|
{ |
|
for my $file (@file) |
|
{ |
|
print " $url/$file"; |
|
print " (", $$size{$file}, ")" |
|
if exists $$size{$file}; |
|
print "\n"; |
|
} |
|
} |
|
print "\n"; |
|
} |
|
|
|
=item C<print_checksums (@file) |
|
|
|
Print the SHA1 and SHA256 signature section for each C<@file>. |
|
|
|
=cut |
|
|
|
sub print_checksums (@) |
|
{ |
|
my (@file) = @_; |
|
|
|
print "Here are the SHA1 and SHA256 checksums:\n"; |
|
print "\n"; |
|
|
|
use Digest::file qw(digest_file_hex digest_file_base64); |
|
|
|
foreach my $f (@file) |
|
{ |
|
print digest_file_hex($f, "SHA-1"), " $f\n"; |
|
print digest_file_base64($f, "SHA-256"), " $f\n"; |
|
} |
|
print "\nThe SHA256 checksum is base64 encoded, instead of the\n"; |
|
print "hexadecimal encoding that most checksum tools default to.\n\n"; |
|
} |
|
|
|
=item C<print_news_deltas ($news_file, $prev_version, $curr_version) |
|
|
|
Print the section of the NEWS file C<$news_file> addressing changes |
|
between versions C<$prev_version> and C<$curr_version>. |
|
|
|
=cut |
|
|
|
sub print_news_deltas ($$$) |
|
{ |
|
my ($news_file, $prev_version, $curr_version) = @_; |
|
|
|
my $news_name = $news_file; |
|
$news_name =~ s|^\Q$srcdir\E/||; |
|
|
|
print "\n$news_name\n\n"; |
|
|
|
|
|
|
|
|
|
my $in_items; |
|
|
|
my $re_prefix = qr/(?:\* )?(?:Noteworthy c|Major c|C)(?i:hanges)/; |
|
|
|
my $found_news; |
|
open NEWS, '<', $news_file |
|
or die "$ME: $news_file: cannot open for reading: $!\n"; |
|
while (defined (my $line = <NEWS>)) |
|
{ |
|
if ( ! $in_items) |
|
{ |
|
|
|
|
|
|
|
$line =~ /^$re_prefix.*(?:[^\d.]|$)\Q$curr_version\E(?:[^\d.]|$)/o |
|
or next; |
|
$in_items = 1; |
|
print $line; |
|
} |
|
else |
|
{ |
|
|
|
|
|
|
|
$line =~ /^$re_prefix.*(?:[^\d.]|$)\Q$prev_version\E(?:[^\d.]|$)/o |
|
and last; |
|
print $line; |
|
$line =~ /\S/ |
|
and $found_news = 1; |
|
} |
|
} |
|
close NEWS; |
|
|
|
$in_items |
|
or die "$ME: $news_file: no matching lines for '$curr_version'\n"; |
|
$found_news |
|
or die "$ME: $news_file: no news item found for '$curr_version'\n"; |
|
} |
|
|
|
sub print_changelog_deltas ($$) |
|
{ |
|
my ($package_name, $prev_version) = @_; |
|
|
|
|
|
|
|
|
|
use File::Find; |
|
my @changelog; |
|
find ({wanted => sub {$_ eq 'ChangeLog' && -d 'CVS' |
|
and push @changelog, $File::Find::name}}, |
|
'.'); |
|
|
|
|
|
@changelog |
|
or return; |
|
my %changelog = map {$_ => 1} @changelog; |
|
|
|
|
|
|
|
|
|
my @dir = qw ( . src lib m4 config doc ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my @reordered; |
|
foreach my $d (@dir) |
|
{ |
|
my $dot_slash = $d eq '.' ? $d : "./$d"; |
|
my $target = "$dot_slash/ChangeLog"; |
|
delete $changelog{$target} |
|
and push @reordered, $target; |
|
} |
|
|
|
|
|
push @reordered, sort keys %changelog; |
|
|
|
|
|
@reordered = map { s!^\./!!; $_ } @reordered; |
|
|
|
print "\nChangeLog entries:\n\n"; |
|
|
|
|
|
$prev_version =~ s/\./_/g; |
|
my $prev_cvs_tag = "\U$package_name\E-$prev_version"; |
|
|
|
my $cmd = "cvs -n diff -u -r$prev_cvs_tag -rHEAD @reordered"; |
|
open DIFF, '-|', $cmd |
|
or die "$ME: cannot run '$cmd': $!\n"; |
|
|
|
|
|
|
|
|
|
|
|
my $prev_printed_line_empty = 1; |
|
while (defined (my $line = <DIFF>)) |
|
{ |
|
if ($line =~ /^\+\+\+ /) |
|
{ |
|
my $separator = "*"x70 ."\n"; |
|
$line =~ s///; |
|
$line =~ s/\s.*//; |
|
$prev_printed_line_empty |
|
or print "\n"; |
|
print $separator, $line, $separator; |
|
} |
|
elsif ($line =~ /^\+/) |
|
{ |
|
$line =~ s///; |
|
print $line; |
|
$prev_printed_line_empty = ($line =~ /^$/); |
|
} |
|
} |
|
close DIFF; |
|
|
|
|
|
|
|
$? == 256 || $? == 128 |
|
or warn "warning: '$cmd' had unexpected exit code or signal ($?)\n"; |
|
} |
|
|
|
sub get_tool_versions ($$) |
|
{ |
|
my ($tool_list, $gnulib_version) = @_; |
|
@$tool_list |
|
or return (); |
|
|
|
my $fail; |
|
my @tool_version_pair; |
|
foreach my $t (@$tool_list) |
|
{ |
|
if ($t eq 'gnulib') |
|
{ |
|
push @tool_version_pair, ucfirst $t . ' ' . $gnulib_version; |
|
next; |
|
} |
|
|
|
|
|
my ($first_line, undef) = split ("\n", `$t --version`); |
|
if ($first_line =~ /.* (\d[\w.-]+)$/) |
|
{ |
|
$t = ucfirst $t; |
|
push @tool_version_pair, "$t $1"; |
|
} |
|
else |
|
{ |
|
defined $first_line |
|
and $first_line = ''; |
|
warn "$t: unexpected --version output\n:$first_line"; |
|
$fail = 1; |
|
} |
|
} |
|
|
|
$fail |
|
and exit 1; |
|
|
|
return @tool_version_pair; |
|
} |
|
|
|
{ |
|
|
|
|
|
$ENV{LC_ALL} = "C"; |
|
|
|
my $mail_headers; |
|
my $release_type; |
|
my $package_name; |
|
my $prev_version; |
|
my $curr_version; |
|
my $gpg_key_id; |
|
my @url_dir_list; |
|
my @news_file; |
|
my $bootstrap_tools; |
|
my $gnulib_version; |
|
my $print_checksums_p = 1; |
|
my $gpg_key_email; |
|
my $gpg_keyring_url; |
|
|
|
|
|
local $SIG{__WARN__} = sub |
|
{ |
|
my ($msg) = @_; |
|
|
|
$msg =~ s/Option (\w)/option --$1/; |
|
warn "$ME: $msg"; |
|
}; |
|
|
|
GetOptions |
|
( |
|
'mail-headers=s' => \$mail_headers, |
|
'release-type=s' => \$release_type, |
|
'package-name=s' => \$package_name, |
|
'previous-version=s' => \$prev_version, |
|
'current-version=s' => \$curr_version, |
|
'gpg-key-id=s' => \$gpg_key_id, |
|
'gpg-key-email=s' => \$gpg_key_email, |
|
'gpg-keyring-url=s' => \$gpg_keyring_url, |
|
'url-directory=s' => \@url_dir_list, |
|
'news=s' => \@news_file, |
|
'srcdir=s' => \$srcdir, |
|
'bootstrap-tools=s' => \$bootstrap_tools, |
|
'gnulib-version=s' => \$gnulib_version, |
|
'print-checksums!' => \$print_checksums_p, |
|
'archive-suffix=s' => \@archive_suffixes, |
|
|
|
help => sub { usage 0 }, |
|
version => |
|
sub |
|
{ |
|
print "$ME version $VERSION\n"; |
|
print "Copyright (C) $copyright_year Free Software Foundation, Inc.\n"; |
|
print "License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n" |
|
. "This is free software: you are free to change and redistribute it.\n" |
|
. "There is NO WARRANTY, to the extent permitted by law.\n"; |
|
print "\n"; |
|
my $author = "Jim Meyering"; |
|
print "Written by $author.\n"; |
|
exit |
|
}, |
|
) or usage 1; |
|
|
|
my $fail = 0; |
|
|
|
$release_type |
|
or (warn "release type not specified\n"), $fail = 1; |
|
$package_name |
|
or (warn "package name not specified\n"), $fail = 1; |
|
$prev_version |
|
or (warn "previous version string not specified\n"), $fail = 1; |
|
$curr_version |
|
or (warn "current version string not specified\n"), $fail = 1; |
|
$gpg_key_id |
|
or (warn "GnuPG key ID not specified\n"), $fail = 1; |
|
@url_dir_list |
|
or (warn "URL directory name(s) not specified\n"), $fail = 1; |
|
|
|
my @tool_list = split ',', $bootstrap_tools |
|
if $bootstrap_tools; |
|
|
|
grep (/^gnulib$/, @tool_list) && ! defined $gnulib_version |
|
and (warn "when specifying gnulib as a tool, you must also specify\n" |
|
. "--gnulib-version=V, where V is the result of running git describe\n" |
|
. "in the gnulib source directory.\n"), $fail = 1; |
|
|
|
! grep (/^gnulib$/, @tool_list) && defined $gnulib_version |
|
and (warn "with --gnulib-version=V you must use --bootstrap-tools=...\n" |
|
. "including gnulib in that list"), $fail = 1; |
|
|
|
!$release_type || exists $valid_release_types{$release_type} |
|
or (warn "'$release_type': invalid release type\n"), $fail = 1; |
|
|
|
@ARGV |
|
and (warn "too many arguments:\n", join ("\n", @ARGV), "\n"), |
|
$fail = 1; |
|
$fail |
|
and usage 1; |
|
|
|
my $my_distdir = "$package_name-$curr_version"; |
|
|
|
my $xd = "$package_name-$prev_version-$curr_version.xdelta"; |
|
|
|
my @candidates = map { "$my_distdir.$_" } @archive_suffixes; |
|
my @tarballs = grep {-f $_} @candidates; |
|
|
|
@tarballs |
|
or die "$ME: none of " . join(', ', @candidates) . " were found\n"; |
|
my @sizable = @tarballs; |
|
-f $xd |
|
and push @sizable, $xd; |
|
my %size = sizes (@sizable); |
|
%size |
|
or exit 1; |
|
|
|
my $headers = ''; |
|
if (defined $mail_headers) |
|
{ |
|
($headers = $mail_headers) =~ s/\s+(\S+:)/\n$1/g; |
|
$headers .= "\n"; |
|
} |
|
|
|
|
|
|
|
print <<EOF; |
|
|
|
${headers}Subject: $my_distdir released [$release_type] |
|
|
|
<\#secure method=pgpmime mode=sign> |
|
|
|
FIXME: put comments here |
|
|
|
EOF |
|
|
|
if (@url_dir_list == 1 && @tarballs == 1) |
|
{ |
|
|
|
my $m = "$url_dir_list[0]/$tarballs[0]"; |
|
print "Here are the compressed sources and a GPG detached signature:\n" |
|
. " $m\n" |
|
. " $m.sig\n\n"; |
|
} |
|
else |
|
{ |
|
print_locations ("compressed sources", @url_dir_list, %size, @tarballs); |
|
-f $xd |
|
and print_locations ("xdelta diffs (useful? if so, " |
|
. "please tell bug-gnulib\@gnu.org)", |
|
@url_dir_list, %size, $xd); |
|
my @sig_files = map { "$_.sig" } @tarballs; |
|
print_locations ("GPG detached signatures", @url_dir_list, %size, |
|
@sig_files); |
|
} |
|
|
|
if ($url_dir_list[0] =~ "gnu\.org") |
|
{ |
|
print "Use a mirror for higher download bandwidth:\n"; |
|
if (@tarballs == 1 && $url_dir_list[0] =~ m!https://ftp\.gnu\.org/gnu/!) |
|
{ |
|
(my $m = "$url_dir_list[0]/$tarballs[0]") |
|
=~ s!https://ftp\.gnu\.org/gnu/!https://ftpmirror\.gnu\.org/!; |
|
print " $m\n" |
|
. " $m.sig\n\n"; |
|
|
|
} |
|
else |
|
{ |
|
print " https://www.gnu.org/order/ftp.html\n\n"; |
|
} |
|
} |
|
|
|
$print_checksums_p |
|
and print_checksums (@sizable); |
|
|
|
print <<EOF; |
|
Use a .sig file to verify that the corresponding file (without the |
|
.sig suffix) is intact. First, be sure to download both the .sig file |
|
and the corresponding tarball. Then, run a command like this: |
|
|
|
gpg --verify $tarballs[0].sig |
|
|
|
EOF |
|
my $gpg_fingerprint = `LC_ALL=C gpg --fingerprint $gpg_key_id | grep -v ^sub`; |
|
if ($gpg_fingerprint =~ /^pub/) |
|
{ |
|
chop $gpg_fingerprint; |
|
$gpg_fingerprint =~ s/ \[expires:.*//mg; |
|
$gpg_fingerprint =~ s/^uid \[ultimate\]/uid /mg; |
|
$gpg_fingerprint =~ s/^/ /mg; |
|
print<<EOF |
|
The signature should match the fingerprint of the following key: |
|
|
|
$gpg_fingerprint |
|
EOF |
|
} |
|
print <<EOF; |
|
If that command fails because you don't have the required public key, |
|
or that public key has expired, try the following commands to retrieve |
|
or refresh it, and then rerun the 'gpg --verify' command. |
|
EOF |
|
if ($gpg_key_email) { |
|
print <<EOF; |
|
|
|
gpg --locate-external-key $gpg_key_email |
|
EOF |
|
} |
|
print <<EOF; |
|
|
|
gpg --recv-keys $gpg_key_id |
|
EOF |
|
if ($gpg_keyring_url) { |
|
print <<EOF; |
|
|
|
wget -q -O- '$gpg_keyring_url' | gpg --import - |
|
EOF |
|
} |
|
print <<EOF; |
|
|
|
As a last resort to find the key, you can try the official GNU |
|
keyring: |
|
|
|
wget -q https://ftp.gnu.org/gnu/gnu-keyring.gpg |
|
gpg --keyring gnu-keyring.gpg --verify $tarballs[0].sig |
|
|
|
EOF |
|
|
|
my @tool_versions = get_tool_versions (\@tool_list, $gnulib_version); |
|
@tool_versions |
|
and print "\nThis release was bootstrapped with the following tools:", |
|
join ('', map {"\n $_"} @tool_versions), "\n"; |
|
|
|
print_news_deltas ($_, $prev_version, $curr_version) |
|
foreach @news_file; |
|
|
|
$release_type eq 'stable' |
|
or print_changelog_deltas ($package_name, $prev_version); |
|
|
|
exit 0; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|