#!/bin/sh /etc/rc.common START=99 STOP=01 USE_PROCD=1 log() { echo "$*"|logger -t usp-js -p debug } get_oui_from_db() { db -q get device.deviceinfo.ManufacturerOUI } get_serial_from_db() { db -q get device.deviceinfo.SerialNumber } publish_endpoint() { local AgentEndpointID serial oui user pass if ! uci -q get obuspa.testmqtt; then return 0; fi # return if mosquitto_pub is not present if [ ! "$(command -v mosquitto_pub)" ]; then log "mosquitto_pub not present can't publish EndpointID" return 0; fi # Get endpoint id from obuspa config first config_load obuspa config_get AgentEndpointID localagent EndpointID "" if [ -z "${AgentEndpointID}" ]; then serial=$(get_serial_from_db) oui=$(get_oui_from_db) AgentEndpointID="os::${oui}-${serial//+/%2B}" fi config_get user testmqtt Username "" config_get pass testmqtt Password "" # publish Agent's EndpointID in mosquito broker for discovery by usp-js # This is a work around till obuspa adds supports for mDNS discovery if [ -n "${user}" ] && [ -n "${pass}" ]; then log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker with username, password" mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" -u "${user}" -P "${pass}" elif [ -n "${user}" ]; then log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker with username only" mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" -u "${user}" else log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker" mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" fi } start_service() { publish_endpoint } service_triggers() { procd_add_reload_trigger "obuspa" }