#!/bin/sh


set -e

FindAndMountVolumeUBI () {
   volume_name=$1
   dir=$2
   mkdir -p $dir
   mount -t ubifs ubi0:$volume_name $dir -o bulk_read
}



case "$1" in
  start)
        echo -n "Starting modem dependent daemons: "
        search_dir="/sys/bus/msm_subsys/devices/"
        for entry in `ls $search_dir`
        do
            subsys_temp=`cat $search_dir/$entry/name`
            if [ "$subsys_temp" == "modem" ]
            then
                break
            fi
        done
        counter=0
        while [ ${counter} -le 10 ]
        do
           msstate=`cat $search_dir/$entry/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/diagrebootapp start
        /sbin/reboot-daemon &
        /etc/init.d/start_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
        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/start_atfwd_daemon stop
        /etc/init.d/diagrebootapp 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
