#!/bin/sh


set -e

case "$1" in
  start)
        echo -n "Starting modem dependent daemons: "
        subsyszero=`cat /sys/bus/msm_subsys/devices/subsys0/name`
        subsysone=`cat /sys/bus/msm_subsys/devices/subsys1/name`
        subsystwo=`cat /sys/bus/msm_subsys/devices/subsys2/name`
        if [ "$subsyszero" == "modem" ]
        then
            subsys=subsys0
        elif [ "$subsysone" == "modem" ]
        then
            subsys=subsys1
        else
            subsys=subsys2
        fi
        counter=0
        while [ ${counter} -le 10 ]
        do
           msstate=`cat /sys/bus/msm_subsys/devices/$subsys/state`
           if [ "$msstate" == "ONLINE" ]
           then
              break
           fi
           counter=$(( $counter + 1 ))
           sleep 1
        done
 #       if [ -f /etc/init.d/init_qcom_audio ]
 #       then
 #           /etc/init.d/init_qcom_audio start
 #       fi
        #/etc/init.d/wapfotadaemon start #disabled by zte, if enable, remove this comment
        /etc/init.d/diagrebootapp start
        /etc/init.d/atfwd_daemon start
        #/etc/init.d/lighttpd start #disabled by zte, if enable, remove this comment
        /etc/init.d/start_stop_qti_ppp_le start
        /etc/init.d/init_qcom_post mdm9635
        echo "done"
        ;;
  stop)
        echo -n "Stoping modem dependent daemon: "
        /etc/init.d/start_stop_qti_ppp_le stop
        #/etc/init.d/lighttpd stop #disabled by zte, if enable, remove this comment
        /etc/init.d/atfwd_daemon stop
        /etc/init.d/diagrebootapp stop
        #/etc/init.d/wapfotadaemon stop #disabled by zte, if enable, remove this comment
  #      /etc/init.d/init_qcom_audio stop
  #      if [ -f /etc/init.d/init_qcom_audio ]
  #      then
  #         /etc/init.d/init_qcom_audio stop
 #       fi
        echo "done"
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage misc-daemon { start | stop | restart}" >&2
        exit 1
        ;;
esac

exit 0
