#!/bin/sh
daemon=discovery
PATH=$PATH:/sbin
ifeth=wlan0
ready=0
die() {
echo $@
exit 1
}
showUsage() {
die "$0 {start|stop|restart|status} [prefix]"
}
dumpSystemKeys() {
echo -n "\
OEM_ms
OEMUrl_ms
ProdName_ms
Model_ss
ProdNumber_ss
ProdNameW_ms
ModelW_ss
ProdNumberW_ss
"
}
dumpUPnPKeys() {
echo -n "\
Enable_byte
PortForward_byte
"
}
probeLink() {
ethtool $1 2> /dev/null | grep -q "Link detected: yes"
}
start() {
while [ $ready -eq 0 ];
do
curl 127.0.0.1 > /tmp/onvif_result 2>&1
if [ "$(grep 't connect to host' /tmp/onvif_result)" != "" ]; then
sleep 1;
else
ready=1;
fi
done
! pids=$(pidof $daemon) || die "$daemon($pids) is already running."
echo -n "Startting $daemon... "
[ -x $binary ] || die "$binary is not a valid application"
export LD_LIBRARY_PATH=$prefix/lib
WLANEnable_byte=`tdb get Wireless Enable_byte`
CameraName=`tdb get Host CameraName_ms`
DiscoveryMode=`tdb get Discovery Enable_byte`
median=$ifeth
eval $(dumpSystemKeys | tdb get System)
if [ "$DiscoveryMode" -eq 1 ]; then
route add -host 239.255.255.250 dev $median 2> /dev/null
$binary -i $median "$debug" > /dev/null 2> /dev/null &
echo "ok."
else
echo " DiscoveryMode is disabled."
fi
}
status() {
echo -n "$daemon"
pids=$(pidof $daemon) && echo "($pids) is running." || echo " is stop."
}
stop() {
WLANEnable_byte=`tdb get Wireless Enable_byte`
CameraName=`tdb get Host CameraName_ms`
median=$ifeth
echo -n "send Bye"
pids=$(pidof $daemon) || { echo "$daemon is not running." && return 1; }
kill $(echo $pids)
sleep 1
$binary -o "bye" -i $median
echo -n "Stopping $daemon... "
sleep 1
}
action=$1
prefix=$2
end=$3
debug=$4
[ "$end" = "" ] && [ "$action" != "" ] || showUsage
[ "$prefix" = "" ] || [ -d "$prefix" ] || die "$prefix is not a valid directory"
binary=$prefix/sbin/$daemon
#
# Disable discovery daemon if device didn't register itself.
#
#mydlink_reg=`tdb get DLink15 Register_byte`
#if [ $mydlink_reg -eq 0 ]; then
# echo "MyDlink is not bound yet, exit......"
# exit 0
#fi
case $action in
start)
start
;
stop)
# stop may call return, instead of exit
stop || exit 1
;
restart)
stop
sleep 1
start
;
reload)
stop
sleep 1
start
sleep 1
;
status)
status
;
*)
showUsage
;
esac
exit 0