aboutsummaryrefslogtreecommitdiff
path: root/system/usbguard/config/rc.usbguard
blob: 71f7975d24a694089a30b1102678e72f3f13bfc3 (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
#!/bin/sh
#
# Start/Stop/Restart the USBGuard daemon.
#

PIDFILE=/var/run/usbguard.pid
USBGUARD_OPTS="-f -s"

# Start
usbguard_start() {
  if [ -x /usr/sbin/usbguard-daemon ]; then
    if [ -e "$PIDFILE" ]; then
      echo "USBGuard daemon already started!"
    else
      echo "Starting USBGuard daemon..."
      /usr/sbin/usbguard-daemon $USBGUARD_OPTS
    fi
  fi
}

# Stop
usbguard_stop() {
  echo "Stopping USBGuard daemon..."
  if [ -e "$PIDFILE" ]; then
      kill $(cat $PIDFILE)
      rm -f $PIDFILE 2>&1 >/dev/null
  fi
  # Just in case:
  killall usbguard-daemon 2>&1 >/dev/null
}

# Restart
usbguard_restart() {
  usbguard_stop
  sleep 3
  usbguard_start
}

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

case "$1" in
'start')
  usbguard_start
  ;;
'stop')
  usbguard_stop
  ;;
'restart')
  usbguard_restart
  ;;
'status')
  usbguard_status
  ;;
*)
  echo "usage: $0 start|stop|restart|status"
esac