chiark / gitweb /
Import gnupg2_2.1.17.orig.tar.bz2
[gnupg2.git] / doc / examples / scd-event
1 #!/bin/sh
2 # Sample script for scdaemon event mechanism.
3
4 #exec >>/tmp/scd-event.log
5
6 PGM=scd-event
7
8 reader_port=
9 old_code=0x0000
10 new_code=0x0000
11 status=
12
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]*=//')
19             ;;
20          *) optarg=
21             ;;
22   esac
23   if [ -n "$prev" ]; then
24     eval "$prev=\$arg"
25     prev=
26     shift
27     continue
28   fi
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
34
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
41
42 Environment:
43
44 GNUPGHOME=DIR            Set to the active homedir
45
46 EOF
47           exit 0
48           ;;
49     
50       --reader-port)  
51           prev=reader_port
52           ;;
53       --reader-port=*)
54           reader_port="$optarg"
55           ;;
56       --old-code)  
57           prev=old_code
58           ;;
59       --old-code=*)
60           old_code="$optarg"
61           ;;
62       --new-code)  
63           prev=new_code
64           ;;
65       --new-code=*)
66           new_code="$optarg"
67           ;;
68       --status)  
69           prev=status
70           ;;
71       --new-code=*)
72           status="$optarg"
73           ;;
74
75       -*)
76           echo "$PGM: invalid option $tick$arg'" >&2
77           exit 1
78           ;;
79
80       *)
81           break
82           ;;
83   esac
84   shift
85 done
86 if [ -n "$prev" ]; then
87   echo "$PGM: argument missing for option $tick$prev'" >&2
88   exit 1
89 fi
90
91 cat <<EOF
92 ========================
93 port:     $reader_port
94 old-code: $old_code
95 new-code: $new_code
96 status:   $status
97 EOF
98
99 if [ x$status = xUSABLE ]; then
100     gpg --batch --card-status 2>&1
101 fi
102