-system "git commit -a -m 'Preparing for release of $version'" and exit 1;
-print "\nSign the tag:";
-system "git tag -s -m 'Version $version.' v$version" and exit 1;
+# We want to use our passphrase-providing "gpg" script, so modify the PATH.
+$ENV{PATH} = "$curdir/packaging/bin:$path";
+
+my $passphrase;
+while (1) {
+ ReadMode('noecho');
+ print "\nEnter your GPG pass-phrase: ";
+ chomp($passphrase = <STDIN>);
+ ReadMode(0);
+ print "\n";
+
+ # Briefly create a temp file with the passphrase for git's tagging use.
+ my $oldmask = umask 077;
+ unlink($passfile);
+ open(OUT, '>', $passfile) or die $!;
+ print OUT $passphrase, "\n";
+ close OUT;
+ umask $oldmask;
+ $ENV{'GPG_PASSFILE'} = $passfile;
+
+ $_ = `git tag -s -m 'Version $version.' v$version 2>&1`;
+ print $_;
+ next if /bad passphrase/;
+ exit 1 if /failed/;
+
+ if (-d 'patches/.git') {
+ $_ = `cd patches && git tag -s -m 'Version $version.' v$version 2>&1`;
+ print $_;
+ exit 1 if /bad passphrase|failed/;
+ }
+
+ unlink($passfile);
+ last;
+}
+
+$ENV{PATH} = $path;