mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-02-18 18:21:25 +01:00
162 lines
4 KiB
Bash
162 lines
4 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
# Copyright (C) 2012 Inteno
|
|
include /lib/network
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
START=60
|
|
STOP=40
|
|
|
|
EXTRA_HELP=" start [GetRPCMethods] Start cwmpd service and send GetRPCMethods"
|
|
|
|
check_url_format() {
|
|
# SCHEMA_LIST: contain list of possible schemas that could be present in the acs url
|
|
# Example: SCHEMA_LIST="http https"
|
|
SCHEMA_LIST="http"
|
|
|
|
for schema in $SCHEMA_LIST; do
|
|
dest=`echo $1|sed 's/$schema:\/\///g'|cut -f1 -d \/|cut -f1 -d:`
|
|
if [ "_$dest" != "_" ]; then
|
|
return 0
|
|
fi
|
|
done
|
|
return 1
|
|
}
|
|
|
|
check_acs_url() {
|
|
default_acs="http://10.10.1.6:8000/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`
|
|
echo "ACS URL from dhcp: $url"
|
|
elif [ "_$url" != "_" ];then
|
|
url=`uci -q get cwmp.acs.url`
|
|
echo "ACS URL from configuration: $url"
|
|
else
|
|
url=$default_acs
|
|
echo "Using default ACS URL: $url"
|
|
fi
|
|
|
|
check_url_format $url
|
|
if [ "$?" != "0" ];then
|
|
echo "Invalid ACS URL: $url"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
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
|
|
break
|
|
else
|
|
echo "Waiting for discovery of acs url from dhcp server ..."
|
|
sleep 10
|
|
fi
|
|
i=`expr $i + 1`
|
|
done
|
|
fi
|
|
}
|
|
set_wan_interface()
|
|
{
|
|
|
|
local device=""
|
|
local default_wan_interface=""
|
|
config_load cwmp
|
|
config_get default_wan_interface cpe default_wan_interface
|
|
json_load "$(ifstatus $default_wan_interface)"
|
|
json_get_var device device
|
|
uci_set cwmp cpe interface "$device"
|
|
uci_commit
|
|
}
|
|
|
|
start_msg="Start cwmpd ..."
|
|
stop_msg="Stop cwmpd ..."
|
|
|
|
run() {
|
|
echo $start_msg;printf "\033[A" ;sleep 1
|
|
set_wan_interface
|
|
check_dhcp
|
|
check_acs_url
|
|
if [ "_$1" = "_boot" ];then
|
|
opt=$opt"-b "
|
|
fi
|
|
if [ "_$1" = "_GetRPCMethods" ];then
|
|
opt=$opt"-g "
|
|
fi
|
|
[ -f /etc/config/cwmp ] && /usr/sbin/cwmpd $opt &
|
|
while [ "`ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common`" = "" ];do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
boot() {
|
|
touch /etc/cwmpd/.cwmpd_boot
|
|
}
|
|
|
|
start() {
|
|
local default_wan_interface
|
|
config_load cwmp
|
|
config_get default_wan_interface cpe default_wan_interface
|
|
json_load "$(ifstatus $default_wan_interface)"
|
|
json_get_var device device
|
|
if [ "$device" != "" ];then
|
|
uci -q set cwmp.cpe.interface="$device"
|
|
uci commit -q
|
|
fi
|
|
run=$(ps aux|grep /usr/sbin/cwmpd|grep -v grep|grep -v rc.common)
|
|
if [ "$run" = "" ]
|
|
then
|
|
if [ "$1" = "GetRPCMethods" ];then
|
|
run "GetRPCMethods"
|
|
else
|
|
if [ ! -f /etc/cwmpd/.cwmpd_boot ]; then
|
|
run
|
|
else
|
|
run "boot"
|
|
rm -f /etc/cwmpd/.cwmpd_boot 2>/dev/null
|
|
fi
|
|
fi
|
|
else
|
|
echo "cwmpd is currently running ..."
|
|
fi
|
|
}
|
|
|
|
stop() {
|
|
echo $stop_msg;printf "\033[A" ;sleep 1
|
|
ubus call tr069 command '{"command": "exit"}' -t 3 &> /dev/null
|
|
|
|
pids="`ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v \" Z \"|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
|
|
while [ "_$pids" != "_" ];do
|
|
kill -9 $pids 2> /dev/null
|
|
pids="`ps aux|grep /usr/sbin/cwmpd|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v \" Z \"|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
|
|
done
|
|
|
|
pids="`ps aux|grep /tmp/freecwmp_action.sh|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
|
|
while [ "_$pids" != "_" ];do
|
|
kill -9 $pids 2> /dev/null
|
|
pids="`ps aux|grep /tmp/freecwmp_action.sh|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
|
|
done
|
|
|
|
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
|
|
while [ "_$pids" != "_" ];do
|
|
kill -9 $pids 2> /dev/null
|
|
pids="`ps aux|grep /usr/sbin/freecwmp|sed 's/^ \+//g'|sed 's/ \+/:/g'|grep -v grep|cut -f1 -d:|tr '\n' ' '`"
|
|
done
|
|
|
|
rm -f /tmp/freecwmp_action.sh
|
|
}
|
|
|
|
restart() {
|
|
stop
|
|
start
|
|
}
|