#117 installer v0.3 with colors and fixes

This commit is contained in:
Mikayla Fischler 2023-02-19 17:15:26 -05:00
parent 1dea5b1b7a
commit 0493f572a2

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.2" local VERSION = "v0.3"
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/"
@ -107,16 +107,24 @@ if mode == "install" or mode == "update" then
-- GET LOCAL MANIFEST -- -- GET LOCAL MANIFEST --
------------------------ ------------------------
local imfile = fs.open("install_manifest.json") local imfile = fs.open("install_manifest.json", "r")
local local_ok, local_manifest = pcall(function () return textutils.unserializeJSON(imfile.readAll()) end) local local_ok = false
imfile.close() 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
if not local_ok and mode == "update" then if not local_ok and mode == "update" then
term.setTextColor(colors.yellow)
println("warning: failed to load local installation information") println("warning: failed to load local installation information")
term.setTextColor(colors.white)
local_app_version = local_manifest.versions[app] local_app_version = local_manifest.versions[app]
local_comms_version = local_manifest.versions.comms local_comms_version = local_manifest.versions.comms
local_boot_version = local_manifest.versions.bootloader local_boot_version = local_manifest.versions.bootloader
@ -126,27 +134,53 @@ if mode == "install" or mode == "update" then
local remote_comms_version = manifest.versions.comms local remote_comms_version = manifest.versions.comms
local remote_boot_version = manifest.versions.bootloader local remote_boot_version = manifest.versions.bootloader
term.setTextColor(colors.green)
if mode == "install" then if mode == "install" then
println("installing " .. app .. " files...") println("installing " .. app .. " files...")
elseif mode == "update" then elseif mode == "update" then
println("updating " .. app .. " files... (keeping old config.lua)") println("updating " .. app .. " files... (keeping old config.lua)")
end end
term.setTextColor(colors.white)
if local_boot_version ~= nil then if local_boot_version ~= nil then
if local_boot_version ~= remote_boot_version then if local_boot_version ~= remote_boot_version then
println("[bootldr] updating " .. local_boot_version .. " => " .. remote_boot_version) print("[bootldr] updating ")
term.setTextColor(colors.blue)
print(local_boot_version)
term.setTextColor(colors.white)
print(" => ")
term.setTextColor(colors.blue)
println(remote_boot_version)
term.setTextColor(colors.white)
end end
else else
println("[bootldr] fresh install of " .. remote_boot_version) println("[bootldr] new install of ")
term.setTextColor(colors.blue)
println(remote_boot_version)
term.setTextColor(colors.white)
end 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
println("[comms] updating " .. local_comms_version .. " => " .. remote_comms_version) print("[comms] updating ")
println("[comms] other devices on the network will require an update") term.setTextColor(colors.blue)
print(local_comms_version)
term.setTextColor(colors.white)
print(" => ")
term.setTextColor(colors.blue)
println(remote_comms_version)
term.setTextColor(colors.white)
print("[comms] ")
term.setTextColor(colors.yellow)
println("other devices on the network will require an update")
term.setTextColor(colors.white)
end end
else else
println("[comms] fresh install of " .. remote_comms_version) println("[comms] new install of ")
term.setTextColor(colors.blue)
println(remote_comms_version)
term.setTextColor(colors.white)
end end
if local_app_version ~= nil then if local_app_version ~= nil then
@ -170,6 +204,8 @@ if mode == "install" or mode == "update" then
local dependencies = manifest.depends[app] local dependencies = manifest.depends[app]
local config_file = app .. "/config.lua" local config_file = app .. "/config.lua"
table.insert(dependencies, app)
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
local size = size_list[dependency] local size = size_list[dependency]
space_required = space_required + size space_required = space_required + size
@ -177,7 +213,9 @@ if mode == "install" or mode == "update" then
if space_available < space_required then if space_available < space_required then
single_file_mode = true single_file_mode = true
term.setTextColor(colors.red)
println("WARNING: Insuffienct space available for a full download!") println("WARNING: Insuffienct space available for a full download!")
term.setTextColor(colors.white)
println("Files will be downloaded one by one, so if you are replacing a current install this will not be a problem unless installation fails.") println("Files will be downloaded one by one, so if you are replacing a current install this will not be a problem unless installation fails.")
println("Do you wish to continue? (y/N)") println("Do you wish to continue? (y/N)")
@ -199,13 +237,15 @@ 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
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)
local dl, err_c = http.get(repo_path .. file) local dl, err_c = http.get(repo_path .. file)
if dl == nil then if dl == nil then
term.setTextColor(colors.red)
println("get: error " .. err_c) println("get: error " .. err_c)
success = false success = false
break break
@ -231,6 +271,8 @@ if mode == "install" or mode == "update" then
fs.delete(install_dir) fs.delete(install_dir)
if success then if success then
term.setTextColor(colors.green)
-- 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
-- that means everything is OK -- that means everything is OK
if mode == "install" then if mode == "install" then
@ -240,8 +282,10 @@ if mode == "install" or mode == "update" then
end end
else else
if mode == "install" then if mode == "install" then
term.setTextColor(colors.red)
println("installation failed") println("installation failed")
else else
term.setTextColor(colors.orange)
println("update failed, existing files unmodified") println("update failed, existing files unmodified")
end end
end end
@ -249,7 +293,7 @@ if mode == "install" or mode == "update" then
for _, dependency in pairs(dependencies) do for _, dependency in pairs(dependencies) do
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)
local dl, err_c = http.get(repo_path .. file) local dl, err_c = http.get(repo_path .. file)
if dl == nil then if dl == nil then
@ -267,12 +311,14 @@ if mode == "install" or mode == "update" then
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
-- that means everything is OK -- that means everything is OK
term.setTextColor(colors.green)
if mode == "install" then if mode == "install" then
println("installation completed successfully") println("installation completed successfully")
else else
println("update completed successfully") println("update completed successfully")
end end
else else
term.setTextColor(colors.red)
if mode == "install" then if mode == "install" then
println("installation failed, files may have been skipped") println("installation failed, files may have been skipped")
else else
@ -286,9 +332,14 @@ elseif mode == "remove" or mode == "purge" then
imfile.close() imfile.close()
if not ok then if not ok then
term.setTextColor(colors.red)
println("error parsing local version manifest") println("error parsing local version manifest")
term.setTextColor(colors.white)
return return
elseif mode == "remove" then end
term.setTextColor(colors.orange)
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 including config.lua and log.txt...")
@ -301,6 +352,10 @@ elseif mode == "remove" or mode == "purge" then
local dependencies = manifest.depends[app] local dependencies = manifest.depends[app]
local config_file = app .. "/config.lua" local config_file = app .. "/config.lua"
table.insert(dependencies, app)
term.setTextColor(colors.lightGray)
-- 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]
@ -320,5 +375,8 @@ elseif mode == "remove" or mode == "purge" then
println("deleted " .. config.LOG_PATH) println("deleted " .. config.LOG_PATH)
end end
term.setTextColor(colors.green)
println("done!") println("done!")
end end
term.setTextColor(colors.white)