#!/bin/sh
#
# qseecomd        init.d script to start the securemsm qseecomd daemon
#
#

set -e

soc_id=`cat /sys/devices/soc0/soc_id`

if [[ "$soc_id" -ne "290" && "$soc_id" -ne "296" && "$soc_id" -ne "297" && "$soc_id" -ne "298" ]]; then
    case "$1" in
      start)
            echo -n "Starting securemsm qseecomd daemon....: "
            chmod o+rw /dev/qseecom /dev/ion
            if [ -e /dev/sde20 ]; then
                chmod 0664 /dev/sde20
            fi
            if [ -e /dev/sg1 ]; then
                chmod o+rw  /dev/sg1
            fi
            if [ -e /dev/sg2 ]; then
                chmod o+rw  /dev/sg2
            fi
            if [ -e /dev/bsg/0:0:0:49476 ]; then
                chown root:system /dev/bsg/0:0:0:49476
                chmod g+rw  /dev/bsg/0:0:0:49476
            fi
            start-stop-daemon -S -b -n qseecom_daemon -a /usr/bin/qseecomd
            echo "done"
            ;;
      stop)
            echo -n "Stoping securemsm qseecomd daemon......: "
            start-stop-daemon -K -n qseecom_daemon
            echo "done"
            ;;
      restart)
            $0 stop
            $0 start
            ;;
      *)
            echo "Usage qseecomd { start | stop | restart}" >&2
            exit 1
            ;;
    esac
fi

exit 0
