From a0fce31840943dfcaf95182f8f598291898a5dad Mon Sep 17 00:00:00 2001 From: xomf Date: Sat, 31 May 2025 17:37:07 +0000 Subject: [PATCH] Add updater.lua --- updater.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 updater.lua diff --git a/updater.lua b/updater.lua new file mode 100644 index 0000000..bdf3854 --- /dev/null +++ b/updater.lua @@ -0,0 +1,36 @@ +local CURRENT_CLIENT_VERSION = "0.0.0.3" +local INSTALL_PATH = "/" + +function http_get(url) + + local req = http.get(url) + local resp = req.readAll() + req.close() + return resp + +end + +print("Device Version: " .. CURRENT_CLIENT_VERSION) + +print("Fetching latest version...") +local manifest = http_get("https://git.mcorangehq.xyz/xomf/slabOS/raw/branch/main/version.json") +local manifest_json = textutils.unserialiseJSON(manifest) +print("Latest: " .. manifest_json.version) +if manifest_json.version ~= CURRENT_CLIENT_VERSION then + + print("Installing update...") + + for path,url in pairs(manifest_json.sys_files) do + print("Writing " .. path) + local file = fs.open(INSTALL_PATH .. path, "w") + file.write( http_get(url) ) + file.close() + print("Written.") + + end + + print("Rebooting device in 5 seconds.") + sleep(5) + os.reboot() + +end \ No newline at end of file