#117 installer v0.9a added support for different targets

This commit is contained in:
Mikayla Fischler 2023-02-19 20:17:03 -05:00
parent e6632c3bd9
commit 279a40e335

View File

@ -22,11 +22,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
local function println(message) print(tostring(message)) end local function println(message) print(tostring(message)) end
local function print(message) term.write(tostring(message)) end local function print(message) term.write(tostring(message)) end
local VERSION = "v0.8b" local VERSION = "v0.9a"
local install_dir = "/.install-cache" local install_dir = "/.install-cache"
local repo_path = "http://raw.githubusercontent.com/MikaylaFischler/cc-mek-scada/devel/" local repo_path = "http://raw.githubusercontent.com/MikaylaFischler/cc-mek-scada/"
local install_manifest = repo_path .. "install_manifest.json"
local opts = { ... } local opts = { ... }
local mode = nil local mode = nil
@ -65,20 +64,31 @@ end
println("-- CC Mekanism SCADA Installer " .. VERSION .. " --") println("-- CC Mekanism SCADA Installer " .. VERSION .. " --")
if #opts == 0 or opts[1] == "help" then if #opts == 0 or opts[1] == "help" then
println("note: only modifies files that are part of the device application") println("usage: ccmsi <mode> <app> <tag/branch>")
println("usage: ccmsi <mode> <app>")
println("<mode>") println("<mode>")
term.setTextColor(colors.lightGray)
println(" check - check latest versions avilable") println(" check - check latest versions avilable")
term.setTextColor(colors.yellow)
println(" ccmsi check <tag/branch> for target")
term.setTextColor(colors.lightGray)
println(" install - fresh install, overwrites config") println(" install - fresh install, overwrites config")
println(" update - update files EXCEPT for config/logs") println(" update - update files EXCEPT for config/logs")
println(" remove - delete files EXCEPT for config/logs") println(" remove - delete files EXCEPT for config/logs")
println(" purge - delete files INCLUDING config/logs") println(" purge - delete files INCLUDING config/logs")
term.setTextColor(colors.white)
println("<app>") println("<app>")
term.setTextColor(colors.lightGray)
println(" reactor-plc - reactor PLC firmware") println(" reactor-plc - reactor PLC firmware")
println(" rtu - RTU firmware") println(" rtu - RTU firmware")
println(" supervisor - supervisor server application") println(" supervisor - supervisor server application")
println(" coordinator - coordinator application") println(" coordinator - coordinator application")
println(" pocket - pocket application") println(" pocket - pocket application")
term.setTextColor(colors.white)
println("<tag/branch>")
term.setTextColor(colors.yellow)
println(" second parameter instead of app when used with check")
term.setTextColor(colors.lightGray)
println(" target GitHub tag or branch name instead of main")
return return
else else
for _, v in pairs({ "check", "install", "update", "remove", "purge" }) do for _, v in pairs({ "check", "install", "update", "remove", "purge" }) do
@ -115,6 +125,9 @@ if mode == "check" then
-- GET REMOTE MANIFEST -- -- GET REMOTE MANIFEST --
------------------------- -------------------------
if opts[2] then repo_path = repo_path .. opts[2] .. "/" else repo_path = repo_path .. "main/" end
local install_manifest = repo_path .. "install_manifest.json"
local response, error = http.get(install_manifest) local response, error = http.get(install_manifest)
if response == nil then if response == nil then
@ -175,6 +188,9 @@ elseif mode == "install" or mode == "update" then
-- GET REMOTE MANIFEST -- -- GET REMOTE MANIFEST --
------------------------- -------------------------
if opts[3] then repo_path = repo_path .. opts[3] .. "/" else repo_path = repo_path .. "main/" end
local install_manifest = repo_path .. "install_manifest.json"
local response, error = http.get(install_manifest) local response, error = http.get(install_manifest)
if response == nil then if response == nil then
@ -508,7 +524,7 @@ elseif mode == "remove" or mode == "purge" then
if mode == "remove" then if mode == "remove" then
println("removing all " .. app .. " files except for config.lua and log.txt...") println("removing all " .. app .. " files except for config.lua and log.txt...")
elseif mode == "purge" then elseif mode == "purge" then
println("purging all " .. app .. " files including config.lua and log.txt...") println("purging all " .. app .. " files...")
end end
---@diagnostic disable-next-line: undefined-field ---@diagnostic disable-next-line: undefined-field
@ -523,11 +539,21 @@ elseif mode == "remove" or mode == "purge" then
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
-- delete log file if purging -- delete log file if purging
if mode == "purge" then if mode == "purge" and fs.exists(config_file) then
local config = require(app .. ".config") local log_deleted = pcall(function ()
if fs.exists(config.LOG_PATH) then local config = require(app .. ".config")
fs.delete(config.LOG_PATH) if fs.exists(config.LOG_PATH) then
println("deleted log file " .. config.LOG_PATH) fs.delete(config.LOG_PATH)
println("deleted log file " .. config.LOG_PATH)
end
end)
if not log_deleted then
term.setTextColor(colors.red)
println("failed to delete log file")
term.setTextColor(colors.white)
---@diagnostic disable-next-line: undefined-field
os.sleep(1)
end end
end end
@ -554,8 +580,10 @@ elseif mode == "remove" or mode == "purge" then
end end
end end
fs.delete(folder) if fs.isDir(folder) then
println("deleted directory " .. folder) fs.delete(folder)
println("deleted directory " .. folder)
end
elseif dependency == app then elseif dependency == app then
for _, folder in pairs(files) do for _, folder in pairs(files) do
while true do while true do
@ -567,7 +595,7 @@ elseif mode == "remove" or mode == "purge" then
end end
end end
if folder ~= app and fs.exists(folder) then if folder ~= app and fs.isDir(folder) then
fs.delete(folder) fs.delete(folder)
println("deleted app subdirectory " .. folder) println("deleted app subdirectory " .. folder)
end end