You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.3 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2012-2014 OpenWrt.org
START=90
USE_PROCD=1
PROG="/usr/sbin/easycwmpd"
. /lib/delos-functions.sh
UCI_SET="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set"
UCI_GET="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} get"
UCI_COMMIT="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit"
UCI_ADD="/sbin/uci -q ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} add"
init_device_info() {
local val oval
local change=0
uci get easycwmp.device -q || $UCI_ADD easycwmp device
val=`cat "/etc/device_info" | grep "DEVICE_MANUFACTURER" | cut -f 2 -d '=' | sed -e "s/['\"]//g" -e "s'[]:@/?#[!$&()*+,;=]'_'g"`
oval=`$UCI_GET easycwmp.@device[0].manufacturer`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].manufacturer="$val"; change=1; }
val=`cat "/etc/device_info" | grep "DEVICE_PRODUCT" | cut -f 2 -d '=' | sed -e "s/['\"]//g" -e "s'[]:@/?#[!$&()*+,;=]'_'g"`
oval=`$UCI_GET easycwmp.@device[0].product_class`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].product_class="$val"; change=1; }
oval=`$UCI_GET easycwmp.@device[0].model_name`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].model_name="$val"; change=1; }
val=`cat "/etc/device_info" | grep "DEVICE_REVISION" | cut -f 2 -d '=' | sed -e "s/['\"]//g" -e "s'[]:@/?#[!$&()*+,;=]'_'g"`
oval=`$UCI_GET easycwmp.@device[0].hardware_version`
[ -n "$val" -a "$val" != "$oval" ] && { $UCI_SET easycwmp.@device[0].hardware_version="$val"; change=1; }
eval $(cat "/etc/delos-version")
[ -n "$FIRMWARE_VERSION" ] && $UCI_SET easycwmp.@device[0].software_version="$FIRMWARE_VERSION ($FIRMWARE_DATE)"
val=`uci -P/var/state get delos.baptization.SerialNumber`
[ -n "$val" ] && $UCI_SET easycwmp.@device[0].serial_number="$val"
val=`uci -P/var/state get delos.baptization.MacAddress0 |tr 'a-z' 'A-Z' |tr -d ':-' |cut -c-6`
[ -n "$val" ] && $UCI_SET easycwmp.@device[0].oui="$val"
#The same thing here for OUI and SerialNumber
[ "$change" = "1" ] && $UCI_COMMIT easycwmp
}
start_service() {
[ "$(uci_get_state delos baptization Tr069)" != "1" ] && ! dvl_is_internal_firmware && exit 1
init_device_info
procd_open_instance
procd_set_param command "$PROG" -f
if [ "$1" = "--boot" ];then
procd_append_param command --boot
else
procd_append_param command --getrpcmethod
fi
procd_set_param respawn "3" "7" "0"
procd_close_instance
}
boot() {
# restore persistent service state after firmware update
local script=$(readlink -f $initscript)
disabled=$(uci_get easycwmp @local[0] disabled '0')
[ $disabled = '1' ] && $script enabled && { $script disable ; return 0 ; }
# perform normal boot action
start --boot
}
service_triggers()
{
procd_add_reload_trigger easycwmp
}
# redirect enable action
[ $action = "enable" ] && action=do_enable && EXTRA_COMMANDS="$EXTRA_COMMANDS $action"
do_enable() {
enable "$@"
# make service state persistent
disabled=$(uci_get easycwmp @local[0] disabled '0')
[ $disabled = '1' ] && {
uci_set easycwmp @local[0] disabled 0
uci_commit easycwmp
}
}
# redirect disable action
[ $action = "disable" ] && action=do_disable && EXTRA_COMMANDS="$EXTRA_COMMANDS $action"
do_disable() {
disable "$@"
# make service state persistent
disabled=$(uci_get easycwmp @local[0] disabled '0')
[ $disabled = '0' ] && {
uci_set easycwmp @local[0] disabled 1
uci_commit easycwmp
}
}