aboutsummaryrefslogtreecommitdiff
path: root/system/pcsc-lite/rc.pcscd
blob: 613c80ae440e88106ce826b324fbd6856cb593c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
#
# Start/Stop/Restart the PC/SC-lite smart card daemon.
#
# pcscd should be started after pcmcia and shut down
# before it for smooth experience with PCMCIA readers.
#

PIDFILE=/var/run/pcscd/pcscd.pid
PCSCD_OPTS=""

# Start
pcscd_start() {
  if [ -x /usr/sbin/pcscd ]; then
    if [ -e "$PIDFILE" ]; then
      echo "PC/SC-lite daemon already started!"
    else
      echo "Starting PC/SC-lite smart card daemon..."
      /usr/sbin/update-reader.conf
      /usr/sbin/pcscd $PCSCD_OPTS
    fi
  fi
}

# Stop
pcscd_stop() {
  echo "Stopping PC/SC-lite smart card daemon..."
  if [ -e "$PIDFILE" ]; then
      kill $(cat $PIDFILE)
      rm -f $PIDFILE 1>&2 >/dev/null
  fi
  # Just in case:
  killall pcscd 1>&2 >/dev/null
}

# Restart
pcscd_restart() {
  pcscd_stop
  sleep 3
  pcscd_start
}

# Status
pcscd_status() {
  if [ -e "$PIDFILE" ]; then
    echo "pcscd is running."
  else
    echo "pcscd is stopped."
  fi
}

case "$1" in
'start')
  pcscd_start
  ;;
'stop')
  pcscd_stop
  ;;
'restart')
  pcscd_restart
  ;;
'status')
  pcscd_status
  ;;
*)
  echo "usage $0 start|stop|restart|status"
esac