#!/bin/sh . /lib/functions.sh . /usr/lib/configsync_lib.sh my_logger() { logger -t configsync_handler "${@}" } create_local_configuration_file() { #if it it not feasable that the uuid changes every time the service is started make the uuid persistent UUID=$(cat /proc/sys/kernel/random/uuid) if [ "$(uci_get ${MY_SERVICE_NAME} global configured)" = 1 ]; then CONFIGURED="yes" else CONFIGURED="no" fi cat > ${CONFIGSYNC_CONFIGURATION_FILE}<$CS_IMPORTSERVICELIST fi return $RETVAL } start_p1905() { my_logger ">>> start_p1905()" # wait on first start after device boot STARTDELAY=$(uci_get ${MY_SERVICE_NAME} global startdelay 0) EXTENSIONDELAY=$(uci_get ${MY_SERVICE_NAME} global extensiondelay 20) wait_stable_config ${STARTDELAY} ${EXTENSIONDELAY} for SERVICE in ${CS_SERVICES_TO_SYNC}; do update_md5sum ${SERVICE} done rm -f /tmp/cs_omit_wireless killall p1905 # call init() for all files (not directories!) in PATH_TO_CONFIGSYNC_EXECUTOR find ${PATH_TO_CONFIGSYNC_EXECUTOR} -type f -maxdepth 1 -exec sh -c "echo \"Call initialization of {} ...\"; {} init" \; create_local_configuration_file /usr/sbin/p1905 -f ${CONFIGSYNC_CONFIGURATION_FILE} | while read MESSAGE_TYPE MESSAGE do case ${MESSAGE_TYPE} in AUTOCONFIG-FAILED) my_logger "Message ${MESSAGE_TYPE} ${MESSAGE} ignored" ;; NEW-AP-SETTINGS) my_logger "Message ${MESSAGE_TYPE} ${MESSAGE} ignored" ;; CONFIGSYNC-SET-CONFIGURED) my_logger "Message ${MESSAGE_TYPE} ${MESSAGE} setting configsync state to configured" uci_set configsync global configured '1' uci_commit configsync create_local_configuration_file ;; NEW-CONFIGSYNC-SETTINGS) # kill pending events from own website killall configsync_event_delay.sh >$CS_SERVICELIST handle_event ${MESSAGE_TYPE} "${MESSAGE}" configsync_to_system reload_config ;; CONFIGSYNC-DYNAMIC-UPDATE) handle_event ${MESSAGE_TYPE} "${MESSAGE}" dynamic_update ;; CONFIGSYNC-RESET) my_logger "Message ${MESSAGE_TYPE} ${MESSAGE} received" rm $CS_CONFIGURATION_PATH/* find ${PATH_TO_CONFIGSYNC_EXECUTOR} -type f -maxdepth 1 -exec sh -c "echo \"Call initialization of {} ...\"; {} init" \; ;; VENDOR-MESSAGE) my_logger "Vendor message received" # cut off the VENDOR-MESSAGE prefix, decode base64 data and call service handler /usr/bin/configsync_vs_handler.sh $(echo "$MESSAGE" | cut -d' ' -f2 | openssl enc -base64 -d) ;; *) my_logger "Unknown message ${MESSAGE_TYPE} ${MESSAGE}" ;; esac done } case ${1} in SYSTEM-TO-CONFIGSYNC) handle_event NEW-SYSTEM-CONFIG-SETTINGS "${2}" system_to_configsync ;; APPLY) my_logger "APPLY) Apply configsync changes" killall -USR1 p1905 ;; STOP) my_logger "STOP) Stop p1905" killall p1905 2>/dev/null ;; START) ETH_MAC_ADDR=${2} my_logger "START) Start p1905 with ${ETH_MAC_ADDR}" start_p1905 ;; esac