#117 installer v0.4 with package version checking for skips, fixes to file overwriting

This commit is contained in:
Mikayla Fischler 2023-02-19 18:49:04 -05:00
parent 0493f572a2
commit df57e1859e

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.3" local VERSION = "v0.4"
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/"
@ -99,7 +99,7 @@ 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
println("error parsing remote version manifest") println("error parsing remote installation manifest")
return return
end end
@ -148,25 +148,40 @@ if mode == "install" or mode == "update" then
term.setTextColor(colors.blue) term.setTextColor(colors.blue)
print(local_boot_version) print(local_boot_version)
term.setTextColor(colors.white) term.setTextColor(colors.white)
print(" => ") print(" \xbb ")
term.setTextColor(colors.blue) term.setTextColor(colors.blue)
println(remote_boot_version) println(remote_boot_version)
term.setTextColor(colors.white) term.setTextColor(colors.white)
end end
else else
println("[bootldr] new install of ") print("[bootldr] new install of ")
term.setTextColor(colors.blue) term.setTextColor(colors.blue)
println(remote_boot_version) println(remote_boot_version)
term.setTextColor(colors.white) term.setTextColor(colors.white)
end end
if local_app_version ~= nil then
if local_app_version ~= remote_app_version then
print("[" .. app .. "] updating ")
term.setTextColor(colors.blue)
print(local_app_version)
term.setTextColor(colors.white)
print(" \xbb ")
term.setTextColor(colors.blue)
println(remote_app_version)
term.setTextColor(colors.white)
end
else
println("[" .. app .. "] fresh install of " .. remote_app_version)
end
if local_comms_version ~= nil then if local_comms_version ~= nil then
if local_comms_version ~= remote_comms_version then if local_comms_version ~= remote_comms_version then
print("[comms] updating ") print("[comms] updating ")
term.setTextColor(colors.blue) term.setTextColor(colors.blue)
print(local_comms_version) print(local_comms_version)
term.setTextColor(colors.white) term.setTextColor(colors.white)
print(" => ") print(" \xbb ")
term.setTextColor(colors.blue) term.setTextColor(colors.blue)
println(remote_comms_version) println(remote_comms_version)
term.setTextColor(colors.white) term.setTextColor(colors.white)
@ -177,20 +192,12 @@ if mode == "install" or mode == "update" then
term.setTextColor(colors.white) term.setTextColor(colors.white)
end end
else else
println("[comms] new install of ") print("[comms] new install of ")
term.setTextColor(colors.blue) term.setTextColor(colors.blue)
println(remote_comms_version) println(remote_comms_version)
term.setTextColor(colors.white) term.setTextColor(colors.white)
end end
if local_app_version ~= nil then
if local_app_version ~= remote_app_version then
println("[" .. app .. "] updating " .. local_app_version .. " => " .. remote_app_version)
end
else
println("[" .. app .. "] fresh install of " .. remote_app_version)
end
-------------------------- --------------------------
-- START INSTALL/UPDATE -- -- START INSTALL/UPDATE --
-------------------------- --------------------------
@ -237,8 +244,19 @@ if mode == "install" or mode == "update" then
fs.makeDir(install_dir) fs.makeDir(install_dir)
end end
term.setTextColor(colors.lightGray)
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
if (dependency == "system" and local_boot_version == remote_boot_version) or (local_app_version == remote_app_version) then
-- skip system package if unchanged, skip app package if not changed
-- skip packages that have no version if app version didn't change
print("skipping download of unchanged package ")
term.setTextColor(colors.blue)
println(dependency)
else
print("downloading package ")
term.setTextColor(colors.blue)
println(dependency)
term.setTextColor(colors.lightGray)
local files = file_list[dependency] local files = file_list[dependency]
for _, file in pairs(files) do for _, file in pairs(files) do
println("get: " .. file) println("get: " .. file)
@ -256,13 +274,29 @@ if mode == "install" or mode == "update" then
end end
end end
end end
end
if success then if success then
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
if (dependency == "system" and local_boot_version == remote_boot_version) or (local_app_version == remote_app_version) then
-- skip system package if unchanged, skip app package if not changed
-- skip packages that have no version if app version didn't change
print("skipping install of unchanged package ")
term.setTextColor(colors.blue)
println(dependency)
else
print("installing package ")
term.setTextColor(colors.blue)
println(dependency)
term.setTextColor(colors.lightGray)
local files = file_list[dependency] local files = file_list[dependency]
for _, file in pairs(files) do for _, file in pairs(files) do
if mode == "install" or file ~= config_file then if mode == "install" or file ~= config_file then
fs.move(install_dir .. "/" .. file, file) local temp_file = install_dir .. "/" .. file
if fs.exists(temp_file) then fs.delete(temp_file) end
fs.move(temp_file, file)
end
end end
end end
end end
@ -291,6 +325,18 @@ if mode == "install" or mode == "update" then
end end
else else
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
if (dependency == "system" and local_boot_version == remote_boot_version) or (local_app_version == remote_app_version) then
-- skip system package if unchanged, skip app package if not changed
-- skip packages that have no version if app version didn't change
print("skipping install of unchanged package ")
term.setTextColor(colors.blue)
println(dependency)
else
print("installing package ")
term.setTextColor(colors.blue)
println(dependency)
term.setTextColor(colors.lightGray)
local files = file_list[dependency] local files = file_list[dependency]
for _, file in pairs(files) do for _, file in pairs(files) do
println("get: " .. file) println("get: " .. file)
@ -307,6 +353,7 @@ if mode == "install" or mode == "update" then
end end
end end
end end
end
if success then if success then
-- if we made it here, then none of the file system functions threw exceptions -- if we made it here, then none of the file system functions threw exceptions
@ -333,7 +380,7 @@ elseif mode == "remove" or mode == "purge" then
if not ok then if not ok then
term.setTextColor(colors.red) term.setTextColor(colors.red)
println("error parsing local version manifest") println("error parsing local installation manifest")
term.setTextColor(colors.white) term.setTextColor(colors.white)
return return
end end
@ -356,6 +403,13 @@ elseif mode == "remove" or mode == "purge" then
term.setTextColor(colors.lightGray) term.setTextColor(colors.lightGray)
-- delete log file if purging
if mode == "purge" then
local config = require(config_file)
fs.delete(config.LOG_PATH)
println("deleted log file " .. config.LOG_PATH)
end
-- delete all files except config unless purging -- delete all files except config unless purging
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
local files = file_list[dependency] local files = file_list[dependency]
@ -367,14 +421,6 @@ elseif mode == "remove" or mode == "purge" then
end end
end end
-- delete log file if purging
if mode == "purge" then
println("deleting log file '" .. config_file .. "'...")
local config = require(config_file)
fs.delete(config.LOG_PATH)
println("deleted " .. config.LOG_PATH)
end
term.setTextColor(colors.green) term.setTextColor(colors.green)
println("done!") println("done!")
end end