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.
159 lines
5.1 KiB
Bash
159 lines
5.1 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
START=99
|
|
STOP=
|
|
|
|
USE_PROCD=1
|
|
|
|
MY_SERVICE_NAME=dlanApp2Backend
|
|
PLCNETAPI_MDNS_PATH=/etc/avahi/services/dvl-plcnetapi.service
|
|
PLCNETAPI_MDNS_PATH_TMP=/tmp/$(basename $PLCNETAPI_MDNS_PATH)
|
|
DEVICEAPI_MDNS_PATH=/etc/avahi/services/dvl-deviceapi.service
|
|
DEVICEAPI_MDNS_PATH_TMP=/tmp/$(basename $DEVICEAPI_MDNS_PATH)
|
|
|
|
PRODUCT_NAME="$(uci_get customization info product_name)"
|
|
|
|
# Determine, if PLC or G.hn is installed
|
|
if [ -f /etc/init.d/plc ]; then
|
|
PLC_CFG_FILE=plc
|
|
PLC_DISABLED=$(uci_get plc plc disabled 0)
|
|
TECHNOLOGY=hpav
|
|
elif [ -f /etc/init.d/ghn ]; then
|
|
PLC_CFG_FILE=ghn
|
|
PLC_DISABLED=$(uci_get ghn ghn disabled 0)
|
|
TECHNOLOGY=ghn
|
|
fi
|
|
|
|
logger() {
|
|
command logger -t ${MY_SERVICE_NAME} "$@"
|
|
}
|
|
|
|
get_interface() {
|
|
local board=$(cat /tmp/sysinfo/board_name)
|
|
local interface=
|
|
case "$board" in
|
|
dlan-550-wifi|\
|
|
dlan-1000-ac)
|
|
interface=eth0
|
|
;;
|
|
dlan2-2400-ac)
|
|
interface=eth0
|
|
;;
|
|
dlan-pro-1200-ac|\
|
|
dlan-pro-1200-n)
|
|
interface=eth0
|
|
;;
|
|
*)
|
|
interface=eth0
|
|
;;
|
|
esac
|
|
echo $interface
|
|
}
|
|
|
|
create_plcnetapi_mDNS_service() {
|
|
DLANMAC="$(uci_get_state delos baptization DlanMacAddress | tr -d ':' | awk '{print toupper($0)}')"
|
|
cat > $PLCNETAPI_MDNS_PATH_TMP <<EOF
|
|
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
|
|
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
|
|
<service-group>
|
|
<name>$PRODUCT_NAME</name>
|
|
<service protocol="ipv4">
|
|
<type>_dvl-plcnetapi._tcp.</type>
|
|
<port>47219</port>
|
|
<txt-record>Path=plcnetapi</txt-record>
|
|
<txt-record>Version=v0</txt-record>
|
|
<txt-record>PlcMacAddress=$DLANMAC</txt-record>
|
|
<txt-record>PlcTechnology=$TECHNOLOGY</txt-record>
|
|
</service>
|
|
</service-group>
|
|
EOF
|
|
|
|
cmp -s $PLCNETAPI_MDNS_PATH_TMP $PLCNETAPI_MDNS_PATH &&
|
|
rm -f $PLCNETAPI_MDNS_PATH_TMP ||
|
|
mv $PLCNETAPI_MDNS_PATH_TMP $PLCNETAPI_MDNS_PATH
|
|
}
|
|
|
|
create_deviceapi_mDNS_service() {
|
|
MT="$(uci_get_state delos baptization MT)"
|
|
SN="$(uci_get_state delos baptization SerialNumber)"
|
|
PS="$(uci_get_state delos baptization PS)"
|
|
. /etc/delos-version
|
|
cat > $DEVICEAPI_MDNS_PATH_TMP <<EOF
|
|
<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
|
|
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
|
|
<service-group>
|
|
<name>$PRODUCT_NAME</name>
|
|
<service protocol="ipv4">
|
|
<type>_dvl-deviceapi._tcp.</type>
|
|
<port>14791</port>
|
|
<txt-record>Path=deviceapi</txt-record>
|
|
<txt-record>Version=v0</txt-record>
|
|
<txt-record>MT=$MT</txt-record>
|
|
<txt-record>SN=$SN</txt-record>
|
|
<txt-record>FirmwareVersion=$FIRMWARE_VERSION</txt-record>
|
|
<txt-record>PS=$PS</txt-record>
|
|
</service>
|
|
</service-group>
|
|
EOF
|
|
|
|
cmp -s $DEVICEAPI_MDNS_PATH_TMP $DEVICEAPI_MDNS_PATH &&
|
|
rm -rf $DEVICEAPI_MDNS_PATH_TMP ||
|
|
mv $DEVICEAPI_MDNS_PATH_TMP $DEVICEAPI_MDNS_PATH
|
|
}
|
|
|
|
start_service() {
|
|
SERVICE_ENABLED=$(uci_get ${MY_SERVICE_NAME} global enabled 1)
|
|
HTTP_REALM=$(uci_get ${MY_SERVICE_NAME} global http_realm "")
|
|
HTTP_USERNAME=$(uci_get ${MY_SERVICE_NAME} global http_username "")
|
|
HTTP_PASSWORD=$(uci_get ${MY_SERVICE_NAME} global http_password "")
|
|
HTTP_HA1=$(uci_get ${MY_SERVICE_NAME} global http_ha1 "")
|
|
LOG_LEVEL=$(uci_get ${MY_SERVICE_NAME} global LOG_LEVEL INFO)
|
|
DLAN_MAC_ADDRESS=$(uci_get_state delos baptization DlanMacAddress)
|
|
INTERFACE=$(get_interface)
|
|
|
|
if [ ${SERVICE_ENABLED} -eq 1 ] && [ $PLC_DISABLED -eq 0 ] ; then
|
|
if [ -f /usr/bin/dlanApp2Backend-plcnet ]; then
|
|
|
|
create_plcnetapi_mDNS_service
|
|
|
|
procd_open_instance
|
|
procd_set_param command /usr/bin/dlanApp2Backend-plcnet -l "$LOG_LEVEL" -p 47219 -i $INTERFACE -n $TECHNOLOGY -m "$DLAN_MAC_ADDRESS" -r /usr/sbin/dlanApp2Backend_get_router_mac.sh
|
|
# Respawn: Threshold in seconds, timeout, retries
|
|
procd_set_param respawn 3600 5 5
|
|
procd_set_param stdout 1 # forward stdout to logd
|
|
procd_set_param stderr 1 # same for stderr
|
|
procd_close_instance
|
|
fi
|
|
else
|
|
# Remove mDNS service announcement for deviceapi if PLC is not active or app backend is not running
|
|
rm -f $PLCNETAPI_MDNS_PATH
|
|
fi
|
|
|
|
if [ ${SERVICE_ENABLED} -eq 1 ]; then
|
|
if [ -f /usr/bin/dlanApp2Backend-device ]; then
|
|
|
|
create_deviceapi_mDNS_service
|
|
|
|
procd_open_instance
|
|
procd_set_param command /usr/bin/dlanApp2Backend-device -l "$LOG_LEVEL" -R "$HTTP_REALM" -U "$HTTP_USERNAME" -P "$HTTP_PASSWORD" -H "$HTTP_HA1"
|
|
# Respawn: Threshold in seconds, timeout, retries
|
|
procd_set_param respawn 3600 5 5
|
|
procd_set_param stdout 1 # forward stdout to logd
|
|
procd_set_param stderr 1 # same for stderr
|
|
procd_close_instance
|
|
fi
|
|
else
|
|
# Remove mDNS service announcement for deviceapi if backend is disabled
|
|
rm -f $DEVICEAPI_MDNS_PATH
|
|
fi
|
|
}
|
|
|
|
stop_service() {
|
|
rm -f $PLCNETAPI_MDNS_PATH
|
|
rm -f $DEVICEAPI_MDNS_PATH
|
|
}
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger $MY_SERVICE_NAME $PLC_CFG_FILE
|
|
}
|