Fixed EOF detection for encrypted packets.
[gnupg.git] / doc / examples / scd-event
blob938465ffb2dba6b0f9d6f399cc34f8b602278a17
1 #!/bin/sh
2 # Sample script for scdaemon event mechanism.
4 #exec >>/tmp/scd-event.log
6 PGM=scd-event
8 reader_port=
9 old_code=0x0000
10 new_code=0x0000
11 status=
13 tick='`'
14 prev=
15 while [ $# -gt 0 ]; do
16 arg="$1"
17 case $arg in
18 -*=*) optarg=$(echo "X$arg" | sed -e '1s/^X//' -e 's/[-_a-zA-Z0-9]*=//')
20 *) optarg=
22 esac
23 if [ -n "$prev" ]; then
24 eval "$prev=\$arg"
25 prev=
26 shift
27 continue
29 case $arg in
30 --help|-h)
31 cat <<EOF
32 Usage: $PGM [options]
33 $PGM is called by scdaemon on card reader status changes
35 Options:
36 --reader-port N Reports change for port N
37 --old-code 0xNNNN Previous status code
38 --old-code 0xNNNN Current status code
39 --status USABLE|ACTIVE|PRESENT|NOCARD
40 Human readable status code
42 Environment:
44 GNUPGHOME=DIR Set to the active homedir
46 EOF
47 exit 0
50 --reader-port)
51 prev=reader_port
53 --reader-port=*)
54 reader_port="$optarg"
56 --old-code)
57 prev=old_code
59 --old-code=*)
60 old_code="$optarg"
62 --new-code)
63 prev=new_code
65 --new-code=*)
66 new_code="$optarg"
68 --status)
69 prev=status
71 --new-code=*)
72 status="$optarg"
75 -*)
76 echo "$PGM: invalid option $tick$arg'" >&2
77 exit 1
81 break
83 esac
84 shift
85 done
86 if [ -n "$prev" ]; then
87 echo "$PGM: argument missing for option $tick$prev'" >&2
88 exit 1
91 cat <<EOF
92 ========================
93 port: $reader_port
94 old-code: $old_code
95 new-code: $new_code
96 status: $status
97 EOF
99 if [ x$status = xUSABLE ]; then
100 gpg --batch --card-status 2>&1