#313 installer self-update fix, added update command for it

This commit is contained in:
Mikayla Fischler 2023-08-21 22:47:00 -04:00
parent 97f0191875
commit 0fe9b391d8

View File

@ -18,7 +18,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 CCMSI_VERSION = "v1.8a" local CCMSI_VERSION = "v1.9"
local install_dir = "/.install-cache" local install_dir = "/.install-cache"
local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/" local manifest_path = "https://mikaylafischler.github.io/cc-mek-scada/manifests/"
@ -213,8 +213,8 @@ if #opts == 0 or opts[1] == "help" then
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")
white();println("<branch>");yellow() println(" installer - ccmsi installer (update only)")
println(" second parameter when used with check") white();println("<branch>")
lgray();println(" main (default) | latest | devel");white() lgray();println(" main (default) | latest | devel");white()
return return
else else
@ -224,10 +224,13 @@ else
return return
end end
app = get_opt(opts[2], { "reactor-plc", "rtu", "supervisor", "coordinator", "pocket" }) app = get_opt(opts[2], { "reactor-plc", "rtu", "supervisor", "coordinator", "pocket", "installer" })
if app == nil and mode ~= "check" then if app == nil and mode ~= "check" then
red();println("Unrecognized application.");white() red();println("Unrecognized application.");white()
return return
elseif app == "installer" and mode ~= "update" then
red();println("Installer app only supports 'update' option.");white()
return
end end
-- determine target -- determine target
@ -273,7 +276,12 @@ if mode == "check" then
print(value);white();println(")") print(value);white();println(")")
end end
end end
if manifest.versions.installer ~= local_manifest.versions.installer then
yellow();println("\nA newer version of the installer is available, it is recommended to update (use 'ccmsi update installer').");white()
end
elseif mode == "install" or mode == "update" then elseif mode == "install" or mode == "update" then
local update_installer = app == "installer"
local ok, manifest = get_remote_manifest() local ok, manifest = get_remote_manifest()
if not ok then return end if not ok then return end
@ -293,7 +301,7 @@ elseif mode == "install" or mode == "update" then
red();println("Failed to load local installation information, cannot update.");white() red();println("Failed to load local installation information, cannot update.");white()
return return
end end
else elseif not update_installer then
ver.boot.v_local = lmnf.versions.bootloader ver.boot.v_local = lmnf.versions.bootloader
ver.app.v_local = lmnf.versions[app] ver.app.v_local = lmnf.versions[app]
ver.comms.v_local = lmnf.versions.comms ver.comms.v_local = lmnf.versions.comms
@ -309,8 +317,8 @@ elseif mode == "install" or mode == "update" then
lmnf.versions.installer = CCMSI_VERSION lmnf.versions.installer = CCMSI_VERSION
if manifest.versions.installer ~= CCMSI_VERSION then if manifest.versions.installer ~= CCMSI_VERSION then
yellow();println("A newer version of the installer is available, it is recommended to update to it.");white() if not update_installer then yellow();println("A newer version of the installer is available, it is recommended to update to it.");white() end
if ask_y_n("Would you like to update now") then if update_installer or ask_y_n("Would you like to update now") then
lgray();println("GET ccmsi.lua") lgray();println("GET ccmsi.lua")
local dl, err = http.get(repo_path .. "ccmsi.lua") local dl, err = http.get(repo_path .. "ccmsi.lua")
@ -318,7 +326,7 @@ elseif mode == "install" or mode == "update" then
red();println("HTTP Error " .. err) red();println("HTTP Error " .. err)
println("Installer download failed.");white() println("Installer download failed.");white()
else else
local handle = fs.open(debug.getinfo(2, "S").source:sub(2), "w") -- this file, regardless of name or location local handle = fs.open(debug.getinfo(1, "S").source:sub(2), "w") -- this file, regardless of name or location
handle.write(dl.readAll()) handle.write(dl.readAll())
handle.close() handle.close()
green();println("Installer updated successfully.");white() green();println("Installer updated successfully.");white()
@ -326,6 +334,9 @@ elseif mode == "install" or mode == "update" then
return return
end end
elseif update_installer then
green();println("Installer already up-to-date.");white()
return
end end
ver.boot.v_remote = manifest.versions.bootloader ver.boot.v_remote = manifest.versions.bootloader