From 9e396e66ada02815325496f5fe12a684b20bcf86 Mon Sep 17 00:00:00 2001 From: Bart Van Der Meerssche Date: Thu, 28 Apr 2011 13:53:23 +0200 Subject: [PATCH] [fsync] create a dependency towards enable_lan_branch --- .../openwrt/package/flukso/luasrc/fsync.lua | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/mote/v2/openwrt/package/flukso/luasrc/fsync.lua b/mote/v2/openwrt/package/flukso/luasrc/fsync.lua index edd8fe2..79410fa 100755 --- a/mote/v2/openwrt/package/flukso/luasrc/fsync.lua +++ b/mote/v2/openwrt/package/flukso/luasrc/fsync.lua @@ -50,7 +50,8 @@ local flukso = uci:get_all('flukso') local MAX_SENSORS = tonumber(flukso.main.max_sensors) local MAX_ANALOG_SENSORS = tonumber(flukso.main.max_analog_sensors) local RESET_COUNTERS = (flukso.main.reset_counters == '1') -local SYNC_TO_SERVER = (flukso.daemon.enable_wan_branch == '1') +local WAN_ENABLED = (flukso.daemon.enable_wan_branch == '1') +local LAN_ENABLED = (flukso.daemon.enable_lan_branch == '1') local METERCONST_FACTOR = 0.449 @@ -314,6 +315,13 @@ local function commit(ctrl) send(ctrl, COMMIT) end +--- Remove all /sensor/xyz endpoint mappings to the cgi script. +-- @return none +local function remove_symlinks() + for symlink in nixio.fs.dir(API_PATH) do + nixio.fs.unlink(API_PATH .. symlink) + end +end --- Map /sensor/xyz endpoints to the cgi script. -- @return none @@ -321,11 +329,6 @@ local function create_symlinks() -- make sure /www/sensor exists nixio.fs.mkdirr(API_PATH) - -- clean up old symlinks - for symlink in nixio.fs.dir(API_PATH) do - nixio.fs.unlink(API_PATH .. symlink) - end - -- generate new symlinks for i = 1, MAX_SENSORS do if flukso[tostring(i)] ~= nil @@ -344,6 +347,12 @@ local function create_symlinks() end end +--- Remove the avahi-daemon flukso.service xml file. +-- @return none +local function remove_avahi_config() + nixio.fs.unlink(AVAHI_PATH) +end + --- Generate a new flukso.service xml file for the avahi-daemon. -- @return none local function create_avahi_config() @@ -373,10 +382,7 @@ local function create_avahi_config() avahi.tail[3] = ' ' avahi.tail[4] = '' - -- remove the old flukso.service - nixio.fs.unlink(AVAHI_PATH) - - -- generate the new one + -- generate the new flukso service fd = nixio.open(AVAHI_PATH, O_RDWR_CREAT) print(string.format('generating a new %s', AVAHI_PATH)) @@ -501,12 +507,16 @@ ctrl_close(ctrl) -- sync config locally -create_symlinks() -create_avahi_config() +remove_symlinks() +remove_avahi_config() +if LAN_ENABLED then + create_symlinks() + create_avahi_config() +end -- sync config with the server -if SYNC_TO_SERVER then +if WAN_ENABLED then phone_home() end