From 837476e5a4c3d872ec0734537a56b3e95a31000e Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Mon, 26 Aug 2013 19:00:27 +0000 Subject: Update scripts to limit which Polycom files are moved / deleted --- config/delete_device.lua | 5 +++-- config/update_device_params.lua | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/config/delete_device.lua b/config/delete_device.lua index 542ed8b..4f5fee7 100644 --- a/config/delete_device.lua +++ b/config/delete_device.lua @@ -7,8 +7,9 @@ local root = "/var/www/provisioning/htdocs/" --APP.logevent("got to delete_device script") --- First, we delete the associated config files -if oldparams.value.device and string.match(oldparams.value.device.label, "Polycom") and oldparams.value.device.value.mac then +-- First, we delete the associated config files for Polycom with valid MAC (not blank or all 0's) +if oldparams.value.device and string.match(oldparams.value.device.label, "Polycom") and oldparams.value.device.value.mac and string.match(oldparams.value.device.value.mac.value, "[1-9A-F]") then + --APP.logevent("Deleting files for "..oldparams.value.device.value.mac.value) local path = root.."Polycom/" if posix.stat(path, "type") == "directory" then for d in posix.files(path) do diff --git a/config/update_device_params.lua b/config/update_device_params.lua index 487765a..6d7ae23 100644 --- a/config/update_device_params.lua +++ b/config/update_device_params.lua @@ -29,16 +29,28 @@ end oldparams = oldparams or {value={}} --- If the mac address changed, we need to move the associated config files +-- If the mac address changed for Polycom with valid MAC (not blank or all 0's), we need to move the associated config files if oldparams.value.device and oldparams.value.device.value.mac and oldparams.value.device.value.mac.value ~= "" and params.value.device and params.value.device.value.mac and params.value.device.value.mac.value ~= oldparams.value.device.value.mac.value then - if string.match(oldparams.value.device.label, "Polycom") then - local path = root.."Polycom/" + if string.match(oldparams.value.device.label, "Polycom") and string.match(oldparams.value.device.value.mac.value, "[1-9A-F]") then + local deletefiles = true + if string.match(params.value.device.value.mac.value, "[1-9A-F]") then + --APP.logevent("Moving files for "..oldparams.value.device.value.mac.value) + deletefiles = false + else + --APP.logevent("Deleting files for "..oldparams.value.device.value.mac.value) + end + local path = root.."Polycom/" if posix.stat(path, "type") == "directory" then for d in posix.files(path) do if string.match(d, string.lower(oldparams.value.device.value.mac.value)) and posix.stat(path..d, "type") == "regular" then local newfile = string.gsub(d, string.lower(oldparams.value.device.value.mac.value), string.lower(params.value.device.value.mac.value)) - --APP.logevent("moving "..path..d.." to "..path..newfile) - os.rename(path..d, path..newfile) + if deletefiles then + --APP.logevent("deleting "..path..d) + os.remove(path..d) + else + --APP.logevent("moving "..path..d.." to "..path..newfile) + os.rename(path..d, path..newfile) + end end end end -- cgit v1.2.3