chiark / gitweb /
changelog: Start 9.11
[dgit.git] / tests / tstunt / gpg-locked
1 #!/bin/sh
2 set -e
3
4 for attempt in '' ' ' exec; do
5
6 case "$*" in
7 *"
8 --batch
9 --import")
10         # ^ apt-key's invocation
11         if [ "x$stdin_tmp" = x ]; then
12                 stdin_tmp="$GNUPGHOME"/dgit-stdin-tmp
13                 cat >$stdin_tmp
14                 stdin_tmp_bytes=$(wc -c <$stdin_tmp)
15         fi
16         exec <$stdin_tmp
17         ;;
18 esac
19
20 set +e
21 $attempt                                                \
22 $DGIT_TEST_REAL_GPG                                     \
23         --agent-program=$DGIT_STUNT_AGENT               \
24         "$@"
25 rc=$?
26 set -e
27
28 if [ $rc != 2 ]; then exit $rc; fi
29
30 echo >&2 "WARNING - GNUPG FAILED $rc - STUNT GNUPG $attempt $stdin_tmp_bytes $*"
31
32 if [ "$stdin_tmp_bytes" = 0 ]; then
33         sleep 5
34 else
35         sh -ec '
36                 if [ "x$DGIT_GNUPG_STUNT_ERRLOG" != x ]; then
37                         exec >"$DGIT_GNUPG_STUNT_ERRLOG"
38                 else
39                         exec 2>/dev/null
40                 fi
41                 exec >/dev/tty
42                 printf "%s\n" "$*"
43         ' x "GNUPG WRAPPER - TROUBLE - $HOME $GNUPGHOME - FAILED $rc $attempt $stdin_tmp_bytes $*" ||:
44         sleep 10
45 fi
46
47 done
48
49 exit 127