Debian Codegraph @

debian/scripts/decrypt_gnupg-sc

raw symbols SCIP
1 #!/bin/sh
2
3 if [ -d "/cryptroot/gnupghome" ]; then
4 export GNUPGHOME="/cryptroot/gnupghome"
5 fi
6
7 run_gpg() {
8 gpg --no-options --trust-model=always "$@"
9 }
10 decrypt_gpg () {
11 local console _
12 if ! GPG_TTY="$(tty)"; then
13 read console _ </proc/consoles
14 GPG_TTY="/dev/$console"
15 fi
16 export GPG_TTY
17
18 if ! run_gpg --decrypt -- "$1"; then
19 return 1
20 fi
21 return 0
22 }
23
24 # `gpg-connect-agent LEARN /bye` is another (lighter) way, but it's
25 # harder to retrieve the return code
26 if ! run_gpg --batch --quiet --no-tty --card-status >/dev/null; then
27 echo "Please insert OpenPGP SmartCard..." >&2
28 until run_gpg --batch --quiet --no-tty --card-status; do
29 sleep 1
30 done >/dev/null 2>&1
31 fi
32
33 if [ ! -x /usr/bin/gpg ]; then
34 echo "$0: /usr/bin/gpg is not available" >&2
35 exit 1
36 fi
37
38 if [ -z "$1" ] || [ ! -f "$1" ]; then
39 echo "$0: missing key as argument" >&2
40 exit 1
41 fi
42
43 decrypt_gpg "$1"
44 exit $?