mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-03-11 11:38:34 +01:00
116 lines
2.5 KiB
Bash
116 lines
2.5 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
# Copyright (C) 2012 Inteno
|
|
|
|
START=99
|
|
STOP=40
|
|
|
|
EXTRA_HELP=" start [GetRPCMethods] Start cwmpd service and send GetRPCMethods"
|
|
|
|
wait_connection_acs() {
|
|
default_acs="http://192.168.1.1:8080/openacs/acs"
|
|
acs_dhcp_discovery=`uci -q get cwmp.acs.dhcp_discovery`
|
|
url=`uci -q get cwmp.acs.url`
|
|
dhcp_url_path=`uci -q get cwmp.acs.dhcp_url_path`
|
|
if [ \( "_$acs_dhcp_discovery" = "_enable" \) -o \( "_$url" = "_" \) ];then
|
|
url=`uci -P /var/state -q get $dhcp_url_path`
|
|
elif [ "_$url" != "_" ];then
|
|
url=`uci -q get cwmp.acs.url`
|
|
else
|
|
url=$default_acs
|
|
fi
|
|
|
|
dest=`echo $url|sed 's/http:\/\///g'|cut -f1 -d \/|cut -f1 -d:`
|
|
port=`echo $url|sed 's/http:\/\///g'|cut -f1 -d \/|cut -f2 -d:`
|
|
|
|
if [ "_$port" = "_" ];then
|
|
port=80
|
|
fi
|
|
|
|
i=0
|
|
result=1
|
|
echo "binding acs url"
|
|
until [ \( $result -eq 0 \) -o \( $i -eq 100 \) ];do
|
|
echo -e -n "" | nc $dest $port 2> /dev/null
|
|
result=$?
|
|
if [ $result -eq 1 ];then
|
|
i=`expr $i + 1`;echo -n $i;printf "\033[A" ;sleep 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
check_dhcp() {
|
|
i=0
|
|
dhcp_discovery=`uci -q get cwmp.acs.dhcp_discovery`
|
|
url=`uci -q get cwmp.acs.url`
|
|
dhcp_url_path=`uci -q get cwmp.acs.dhcp_url_path`
|
|
if [ \( "_$acs_dhcp_discovery" = "_enable" \) -o \( "_$url" = "_" \) ]
|
|
then
|
|
while [ $i -le 10 ]
|
|
do
|
|
acs_url=`uci -P /var/state -q get $dhcp_url_path`
|
|
if [ "$acs_url" != "" ]
|
|
then
|
|
echo "The acs url discovery from dhcp server is successfully done."
|
|
break
|
|
else
|
|
echo "Waiting for discovery of acs url from dhcp server ..."
|
|
sleep 10
|
|
fi
|
|
i=`expr $i + 1`
|
|
done
|
|
fi
|
|
}
|
|
|
|
start_msg="Start cwmpd ..."
|
|
stop_msg="Stop cwmpd ..."
|
|
|
|
run() {
|
|
echo $start_msg;printf "\033[A" ;sleep 1
|
|
check_dhcp
|
|
wait_connection_acs
|
|
if [ "_$1" = "_boot" ];then
|
|
opt=$opt"-b "
|
|
fi
|
|
if [ "_$1" = "_GetRPCMethods" ];then
|
|
opt=$opt"-g "
|
|
fi
|
|
[ -f /etc/config/cwmp ] && /usr/sbin/cwmpd $opt &
|
|
}
|
|
|
|
boot() {
|
|
run=$(ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common)
|
|
if [ "$run" = "" ];then
|
|
run "boot"
|
|
else
|
|
echo "cwmpd is currently running ..."
|
|
fi
|
|
}
|
|
|
|
start() {
|
|
run=$(ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common)
|
|
if [ "$run" = "" ]
|
|
then
|
|
if [ "$1" = "GetRPCMethods" ];then
|
|
run "GetRPCMethods"
|
|
else
|
|
run
|
|
fi
|
|
else
|
|
echo "cwmpd is currently running ..."
|
|
fi
|
|
}
|
|
|
|
stop() {
|
|
echo $stop_msg;printf "\033[A" ;sleep 1
|
|
for pid in `ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:`
|
|
do
|
|
if [ "_$pid" != "_" ];then
|
|
/bin/kill -9 $pid 2> /dev/null
|
|
fi
|
|
done
|
|
}
|
|
|
|
restart() {
|
|
stop
|
|
start
|
|
}
|