#117 installer v0.8 fixed purge, added check

This commit is contained in:
Mikayla Fischler 2023-02-19 19:30:03 -05:00
parent 960c016f4c
commit bc38a9ea27

View File

@ -22,7 +22,7 @@ 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.7" local VERSION = "v0.8"
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/devel/"
@ -63,8 +63,9 @@ println("-- CC Mekanism SCADA Installer " .. VERSION .. " --")
if #opts == 0 or opts[1] == "help" or #opts ~= 2 then if #opts == 0 or opts[1] == "help" or #opts ~= 2 then
println("note: only modifies files that are part of the device application") println("note: only modifies files that are part of the device application")
println("usage: installer <mode> <app>") println("usage: ccmsi <mode> <app>")
println("<mode>") println("<mode>")
println(" check - check latest versions avilable")
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")
@ -106,7 +107,7 @@ end
-- run selected mode -- run selected mode
-- --
if mode == "install" or mode == "update" then if mode == "check" then
------------------------- -------------------------
-- GET REMOTE MANIFEST -- -- GET REMOTE MANIFEST --
------------------------- -------------------------
@ -122,7 +123,9 @@ if mode == "install" or mode == "update" then
local ok, manifest = pcall(function () return textutils.unserializeJSON(response.readAll()) end) local ok, manifest = pcall(function () return textutils.unserializeJSON(response.readAll()) end)
if not ok then if not ok then
term.setTextColor(colors.red)
println("error parsing remote installation manifest") println("error parsing remote installation manifest")
term.setTextColor(colors.white)
return return
end end
@ -139,6 +142,64 @@ if mode == "install" or mode == "update" then
imfile.close() imfile.close()
end end
if not local_ok then
term.setTextColor(colors.yellow)
println("warning: failed to load local installation information")
term.setTextColor(colors.white)
end
for key, value in pairs(manifest.versions) do
term.setTextColor(colors.white)
print("[" .. key .. "]" )
term.setTextColor(colors.blue)
print(value)
term.setTextColor(colors.lightGray)
if local_manifest.versions[key] ~= nil then
print(" (current ")
term.setTextColor(colors.blue)
print(value)
term.setTextColor(colors.white)
println(")")
else
println(" (not installed)")
end
end
elseif mode == "install" or mode == "update" then
-------------------------
-- GET REMOTE MANIFEST --
-------------------------
local response, error = http.get(install_manifest)
if response == nil then
term.setTextColor(colors.red)
println("failed to get installation manifest from GitHub, cannot update or install")
println("http error " .. error)
term.setTextColor(colors.white)
return
end
local ok, manifest = pcall(function () return textutils.unserializeJSON(response.readAll()) end)
if not ok then
term.setTextColor(colors.red)
println("error parsing remote installation manifest")
term.setTextColor(colors.white)
end
------------------------
-- GET LOCAL MANIFEST --
------------------------
local imfile = fs.open("install_manifest.json", "r")
local local_ok = false
local local_manifest = {}
if imfile ~= nil then
local_ok, local_manifest = pcall(function () return textutils.unserializeJSON(imfile.readAll()) end)
imfile.close()
end
local local_app_version = nil local local_app_version = nil
local local_comms_version = nil local local_comms_version = nil
local local_boot_version = nil local local_boot_version = nil
@ -457,7 +518,7 @@ elseif mode == "remove" or mode == "purge" then
-- delete log file if purging -- delete log file if purging
if mode == "purge" then if mode == "purge" then
local config = require(config_file) local config = require(app .. ".config")
if fs.exists(config.LOG_PATH) then if fs.exists(config.LOG_PATH) then
fs.delete(config.LOG_PATH) fs.delete(config.LOG_PATH)
println("deleted log file " .. config.LOG_PATH) println("deleted log file " .. config.LOG_PATH)