#!/usr/bin/env perl
my
$copyright
=
<<'COPYRIGHT';
# Copyright 2021 by Christian Jaeger <ch@christianjaeger.ch>
# Published under the same terms as perl itself
COPYRIGHT
my
(
$email_full
) =
$copyright
=~ / by ([^\n]*)/s;
my
(
$mydir
,
$myname
);
BEGIN {
$0 =~ /(.*?)([^\/]+)\z/s or
die
"?"
;
(
$mydir
,
$myname
) = ($1, $2);
}
use
lib
"$mydir/../../lib"
;
my
$orig_gpg
=
"/usr/bin/gpg"
;
my
$siginput_path
=
"$mydir/../../SIGNATURE-input"
;
my
$sigoutput_path
= getcwd .
"/SIGNATURE.tmp"
;
if
( equal(\
@ARGV
, [
"--version"
])
or equal(\
@ARGV
, [
'--batch'
,
'--verify'
,
'SIGNATURE'
]))
{
xexec
$orig_gpg
,
@ARGV
;
}
elsif
(
@ARGV
and
$ARGV
[0] eq
"--clearsign"
) {
my
$in
=
do
{
local
$/;
<STDIN>
};
close
STDIN or
die
"stdin: $!"
;
xputfile_bytes
$siginput_path
,
$in
;
open
STDOUT,
">"
,
"/dev/tty"
or
die
$!;
xprintln
"our call was:"
. singlequote_many(
@ARGV
);
xprintln
"please run:"
;
xprintln
" gpg @ARGV < $siginput_path > $sigoutput_path"
;
xprintln
"then ctl-d here."
;
repl;
unlink
$siginput_path
;
}
else
{
open
STDERR,
">"
,
"/dev/tty"
or
die
$!;
open
STDOUT,
">"
,
"/dev/tty"
or
die
$!;
open
STDIN,
"<"
,
"/dev/tty"
or
die
$!;
xprintln
"unknown call to $0, please examine..."
;
repl;
}