chiark / gitweb /
changelog: Start 9.11
[dgit.git] / tests / tstunt / gpg-withagent
1 #!/bin/sh
2 set -ex
3
4 d () {
5         date --iso-8601=ns >&2
6         ps -ef | grep gpg-agent >&2 ||:
7 }
8
9 d
10
11 retry_until_ok () {
12         sleeptime=0
13         d
14         while ! "$@"; do
15                 d
16                 case $sleeptime in
17                 ??.*)
18                         echo >&2 "$0: GPG AGENT STARTP $@ TIMED OUT"
19                         exit 127
20                         ;;
21                 esac
22                 sleep $sleeptime
23                 sleeptime=$(echo "($sleeptime + 0.001) * 2" | bc -l)
24         done
25 }
26
27 kill_agent_not_running () {
28         LC_MESSAGES=C gpg-connect-agent --no-autostart </dev/null \
29                 KILLAGENT /bye 2>&1 \
30         | tee -a /dev/stderr \
31         | grep 'no gpg-agent running' >&2
32 }
33
34 echo >&2 'GPG-WITHAGENT... PRE-STOPPING'
35
36 retry_until_ok kill_agent_not_running
37
38 agent_is_running () {
39         gpg-connect-agent --no-autostart </dev/null \
40                 '/echo dgit-gpg-agent-ok' /bye 2>&1 \
41         | grep dgit-gpg-agent-ok >&2
42 }
43
44
45 $DGIT_STUNT_AGENT --daemon </dev/null >&2
46 retry_until_ok agent_is_running
47
48 echo >&2 'GPG-WITHAGENT... RUNNING'
49
50 d
51
52 set +e
53 $DGIT_TEST_REAL_GPG                                     \
54         --agent-program=$DGIT_STUNT_AGENT "$@" 2>&9
55 rc=$?
56 set -e
57
58 d
59
60 echo >&2 'GPG-WITHAGENT... STOPPING'
61
62 retry_until_ok kill_agent_not_running
63
64 echo >&2 'GPG-WITHAGENT... DONE'
65
66 d
67
68 exit $rc