-- -- install.lua -- -- Fetches the facility-control files a given role needs, from a base URL you -- host them at (same idea as the mimic installer). Every role also gets -- facility.lua (shared) and config.example.lua (reference). -- -- install [base_url] -- roles: coordinator | chamber | me | datacenter | all -- base_url defaults to the sandbox file host below -- -- e.g. install chamber -- wget run http://test.tomttfb.com/install.lua chamber -- -- No hosting? See INSTALL.md for the pastebin and copy-into-save alternatives. -- local DEFAULT_BASE = "http://test.tomttfb.com" local role, base = ... base = base or DEFAULT_BASE local ROLES = { coordinator = { "coordinator.lua" }, chamber = { "chamber.lua", "chamber_rtu.lua" }, me = { "me.lua", "me_rtu.lua" }, datacenter = { "dc.lua", "dc_rtu.lua" }, } if not role or not (ROLES[role] or role == "all") then print("usage: install [base_url]") print("roles: coordinator | chamber | me | datacenter | all") print("base_url defaults to " .. DEFAULT_BASE) return end base = base:gsub("/$", "") -- build the file list local files = { "facility.lua", "configure.lua", "config.example.lua" } local function add(list) for _, f in ipairs(list) do files[#files + 1] = f end end if role == "all" then for _, set in pairs(ROLES) do add(set) end else add(ROLES[role]) end local failed = 0 for _, f in ipairs(files) do write(" " .. f .. " ... ") local h = http.get(base .. "/" .. f) if h then local data = h.readAll(); h.close() local out = fs.open(f, "w"); out.write(data); out.close() print("ok") else print("FAILED (" .. base .. "/" .. f .. ")") failed = failed + 1 end end print("") if failed == 0 then print("Done. Make sure mimic is installed too, then:") print(" cp config.example.lua config.lua & edit config.lua") else print(failed .. " file(s) failed - check the base URL and http access.") end