rtmc/src/updater.lua

75 lines
2.4 KiB
Lua
Raw Normal View History

2024-08-18 00:34:13 +00:00
local utils = require("utils.lua")
local LAST_USED = os.time()
2024-08-18 01:34:08 +00:00
local mod = {}
2024-08-18 00:34:13 +00:00
local function checkForUpdate()
local current_time = os.time()
local difference = math.abs(current_time - LAST_USED)
print("Checking for update... difference: " .. tostring(difference))
--its been considerable time since the keypad was interacted with
--therefore it's time to force an update down the users throat (microsoft moment)
if difference > .5 then
2024-08-18 03:00:20 +00:00
local update_code_request = http.get("https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
2024-08-18 00:34:13 +00:00
if update_code_request then
local update_code_text = update_code_request.readAll()
if update_code_text then
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
2024-08-18 03:00:20 +00:00
-- Make backup
fs.copy("startup.lua", "backup.lua")
2024-08-18 00:34:13 +00:00
2024-08-18 03:29:34 +00:00
if not string.find(update_code_text, KEYPADOS_UPDATE_HASH) then
local file = fs.open("startup.lua", "w")
file.write(update_code_text)
file.close()
os.reboot()
else
print("Nothing changed, not updating.")
2024-08-18 02:57:44 +00:00
LAST_USED = os.time()
2024-08-18 02:55:24 +00:00
return
end
2024-08-18 03:00:20 +00:00
else
print("Bad file download (core)")
2024-08-18 00:34:13 +00:00
end
2024-08-18 03:00:20 +00:00
else
print("Bad mem read (core)")
2024-08-18 00:34:13 +00:00
end
2024-08-18 03:00:20 +00:00
else
print("Bad download (core)")
2024-08-18 00:34:13 +00:00
end
end
end
2024-08-18 01:34:08 +00:00
function mod.UpdateChecker()
2024-08-18 00:34:13 +00:00
while true do
checkForUpdate()
sleep(1)
end
end
2024-08-18 01:34:08 +00:00
function mod.GetBasalt()
2024-08-18 00:34:13 +00:00
if fs.exists("basalt.lua") then
utils.MonPrint("Basalt found!")
else
utils.MonPrint("Downloading basalt...")
local basalt_code = http.get("https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua").readAll()
utils.MonPrint("Installing basalt...")
local file = fs.open("basalt.lua", "w")
if not file then
utils.MonPrint("failed to get basalt")
sleep(60)
os.reboot()
end
2024-08-18 00:36:52 +00:00
file.write(utils.Cast(basalt_code))
2024-08-18 00:34:13 +00:00
file.close()
utils.MonPrint("Rebooting...")
os.reboot()
end
end
2024-08-18 01:34:08 +00:00
return mod