1#!/bin/sh
2
3### BEGIN INIT INFO
4# Provides:		tpm2-abrmd
5# Required-Start:	$local_fs $remote_fs $network
6# Required-Stop:	$local_fs $remote_fs $network
7# Should-Start:
8# Should-Stop:
9# Default-Start:	2 3 4 5
10# Default-Stop:		0 1 6
11# Short-Description:	starts tpm2-abrmd
12# Description:		tpm2-abrmd implements the TCG resource manager
13### END INIT INFO
14
15PATH=/sbin:/bin:/usr/sbin:/usr/bin
16DAEMON=/usr/sbin/tpm2-abrmd
17NAME=tpm2-abrmd
18DESC="TCG TSS2 Access Broker and Resource Management daemon"
19USER="tss"
20
21test -x "${DAEMON}" || exit 0
22
23# Read configuration variable file if it is present
24[ -r /etc/default/$NAME ] && . /etc/default/$NAME
25
26case "${1}" in
27	start)
28		echo -n "Starting $DESC: "
29
30		if [ ! -e /dev/tpm? ]
31		then
32			echo "device driver not loaded, skipping."
33			exit 0
34		fi
35
36		start-stop-daemon --start --quiet --oknodo --background --pidfile /var/run/${NAME}.pid --user ${USER} --chuid ${USER} --exec ${DAEMON} -- ${DAEMON_OPTS}
37		RETVAL="$?"
38		echo "$NAME."
39		[ "$RETVAL" = 0 ] && pidof $DAEMON > /var/run/${NAME}.pid
40		exit $RETVAL
41		;;
42
43	stop)
44		echo -n "Stopping $DESC: "
45
46		start-stop-daemon --stop --quiet --oknodo --pidfile /var/run/${NAME}.pid --user ${USER} --exec ${DAEMON}
47		RETVAL="$?"
48                echo  "$NAME."
49		rm -f /var/run/${NAME}.pid
50		exit $RETVAL
51		;;
52
53	restart|force-reload)
54		"${0}" stop
55		sleep 1
56		"${0}" start
57		exit $?
58		;;
59	*)
60		echo "Usage: ${NAME} {start|stop|restart|force-reload|status}" >&2
61		exit 3
62		;;
63esac
64
65exit 0
66