Jens Wiklander | c0bc808 | 2018-02-27 20:25:25 +0100 | [diff] [blame] | 1 | #!/bin/sh |
Jens Wiklander | c0bc808 | 2018-02-27 20:25:25 +0100 | [diff] [blame] | 2 | |
Etienne Carriere | 43791be | 2019-02-06 14:51:01 +0100 | [diff] [blame^] | 3 | DAEMON="tee-supplicant" |
| 4 | DAEMON_PATH="/usr/sbin" |
| 5 | DAEMON_ARGS="-d /dev/teepriv0" |
| 6 | PIDFILE="/var/run/$DAEMON.pid" |
| 7 | |
| 8 | start() { |
| 9 | # tee-supplicant and the client applications need not run as |
| 10 | # root provided that the TEE devices and the data store have |
| 11 | # proper permissions |
| 12 | printf 'Set permissions on %s: ' "/dev/tee*" |
| 13 | chown root:tee /dev/teepriv0 && chmod 0660 /dev/teepriv0 && \ |
| 14 | chown root:teeclnt /dev/tee0 && chmod 0660 /dev/tee0 |
| 15 | status=$? |
| 16 | if [ "$status" -eq 0 ]; then |
| 17 | echo "OK" |
| 18 | else |
| 19 | echo "FAIL" |
| 20 | return "$status" |
| 21 | fi |
| 22 | if [ -e /dev/ion ]; then |
| 23 | printf 'Set permissions on %s: ' "/dev/ion" |
| 24 | chown root:ion /dev/ion && chmod 0660 /dev/ion |
| 25 | status=$? |
| 26 | if [ "$status" -eq 0 ]; then |
| 27 | echo "OK" |
| 28 | else |
| 29 | echo "FAIL" |
| 30 | return "$status" |
| 31 | fi |
| 32 | fi |
| 33 | printf 'Create/set permissions on %s: ' "/data/tee" |
| 34 | mkdir -p /data/tee && chown -R tee:tee /data/tee && chmod 0770 /data/tee |
| 35 | status=$? |
| 36 | if [ "$status" -eq 0 ]; then |
| 37 | echo "OK" |
| 38 | else |
| 39 | echo "FAIL" |
| 40 | return "$status" |
| 41 | fi |
| 42 | printf 'Starting %s: ' "$DAEMON" |
| 43 | start-stop-daemon -S -q -p "$PIDFILE" -c tee -x "$DAEMON_PATH/$DAEMON" \ |
| 44 | -- $DAEMON_ARGS |
| 45 | status=$? |
| 46 | if [ "$status" -eq 0 ]; then |
| 47 | echo "OK" |
| 48 | else |
| 49 | echo "FAIL" |
| 50 | fi |
| 51 | return "$status" |
| 52 | } |
| 53 | |
| 54 | stop() { |
| 55 | printf 'Stopping %s: ' "$DAEMON" |
| 56 | start-stop-daemon -K -q -p "$PIDFILE" |
| 57 | status=$? |
| 58 | if [ "$status" -eq 0 ]; then |
| 59 | echo "OK" |
| 60 | else |
| 61 | echo "FAIL" |
| 62 | fi |
| 63 | return "$status" |
| 64 | } |
| 65 | |
| 66 | restart() { |
| 67 | stop |
| 68 | sleep 1 |
| 69 | start |
| 70 | } |
| 71 | |
| 72 | case "$1" in |
| 73 | start|stop|restart) |
| 74 | "$1";; |
| 75 | reload) |
| 76 | # Restart, since there is no true "reload" feature (does not |
| 77 | # reconfigure/restart on SIGHUP, just closes all open files). |
| 78 | restart;; |
| 79 | *) |
| 80 | echo "Usage: $0 {start|stop|restart|reload}" |
| 81 | exit 1 |
Jens Wiklander | c0bc808 | 2018-02-27 20:25:25 +0100 | [diff] [blame] | 82 | esac |