icwmp/init/icwmpd.init
2015-11-23 13:40:20 +01:00

133 lines
3.1 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2015 Inteno Broadband Technology AB
# Author Ahmed Zribi <ahmed.zribi@pivasoftware.com>
# Author Mohamed Kallel <mohamed.kallel@pivasoftware.com>
# Author Anis Ellouze <anis.ellouze@pivasoftware.com>
include /lib/network
. /usr/share/libubox/jshn.sh
START=99
STOP=10
USE_PROCD=1
PROG="/usr/sbin/icwmpd"
EXTRA_HELP=" start [GetRPCMethods] Start icwmpd 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"
uci -P /var/state -q set cwmp.acs.url=$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"
uci -P /var/state -q set cwmp.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 l3_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 l3_device l3_device
if [ "$l3_device" != "" ];then
uci_set cwmp cpe interface "$l3_device"
uci_commit
fi
}
start_msg="Start icwmpd ..."
stop_msg="Stop icwmpd ..."
cwmp_wait_net() {
local tm=1
while [ "$(nvram get wlmngr)" != "done" ]; do
sleep $tm
[ $tm -ge 10 ] && break
tm=$((tm+1))
done
}
service_running() {
ubus -t 2 wait_for asterisk
}
start_service() {
if [ ! -f /tmp/.icwmpd_boot ]; then
touch /etc/icwmpd/.icwmpd_boot
touch /tmp/.icwmpd_boot
else
echo $start_msg;printf "\033[A" ;sleep 1
set_wan_interface
check_dhcp
check_acs_url
cwmp_wait_net
procd_open_instance
procd_set_param command "$PROG"
if [ "$1" = "GetRPCMethods" ];then
procd_append_param command -g
elif [ -f /etc/icwmpd/.icwmpd_boot ]; then
procd_append_param command -b
rm -f /etc/icwmpd/.icwmpd_boot 2>/dev/null
fi
procd_set_param respawn "3" "7" "0"
procd_close_instance
fi
}
service_triggers() {
procd_add_reload_trigger cwmp
}