This commit is contained in:
Gvidas Juknevičius 2024-08-26 00:16:13 +03:00
parent 79c5654247
commit 9e633867da
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
4 changed files with 7 additions and 123 deletions

View File

@ -9,60 +9,11 @@ local require = function(path)
return __DEFAULT_IMPORT(path)
end
end
local __UPDATE_HASH = "b325b5c21f4f619ca9454e08f1f8d17a634f245e"
local __UPDATE_HASH = "5e1c10aba96c3f9ded6aecb030f2774577c005af"
rawset(__BUNDLER_FILES, "updater.lua", function ()
local utils = require("utils.lua")
local config = require("config.lua")
local LAST_USED = os.time()
local mod = {}
if not __UPDATE_HASH then
__UPDATE_HASH = "WHATTHEFUCK";
end
local function checkForUpdate()
local current_time = os.time()
local difference = math.abs(current_time - LAST_USED)
if difference > .5 then
print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
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
if fs.exists("backup.lua") then
fs.delete("backup.lua")
end
fs.copy("startup.lua", "backup.lua")
if not string.find(update_code_text, __UPDATE_HASH) then
http.post(config.ntfy_url, "Computer #" .. tostring( os.getComputerID() ) .. " updating")
local file = fs.open("startup.lua", "w")
file.write(update_code_text)
file.close()
os.reboot()
else
print("Nothing changed, not updating.")
LAST_USED = os.time()
return
end
else
print("Bad file download (core)")
end
else
print("Bad mem read (core)")
end
else
print("Bad download (core)")
end
end
end
function mod.UpdateChecker()
while true do
local status, err = pcall(checkForUpdate)
if not status and err ~= "Terminated" then
http.post(config.ntfy_url, err, {Priority = "urgent"})
end
sleep(1)
end
end
function mod.GetBasalt()
if fs.exists("basalt.lua") then
utils.MonPrint("Basalt found!")
@ -128,7 +79,6 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
drive:ejectDisk()
end
end
basalt.debug("test")
if ui.pin == config.correctPin then
blibs.notifier.notify("5", "Unlocked door :3 love u");
ui.enterButton:setBackground(colors.green)
@ -200,8 +150,8 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
parallel.waitForAll(basalt.autoUpdate)
end)
if not status and err ~= "Terminated" then
print("Error detected: " .. err)
http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
log.error("Error detected: " .. err)
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
fs.delete("basalt.lua")
@ -236,11 +186,7 @@ rawset(__BUNDLER_FILES, "main.lua", function ()
local mod = {}
KEYPADOS_VERSION = "4.0"
function mod.main(blibs)
print("blibs:" .. tostring(blibs));
print("blibs:" .. tostring(blibs.updater));
print("blibs:" .. tostring(blibs.log));
print("blibs:" .. tostring(blibs.json));
print("blibs:" .. tostring(blibs.notifier));
_G.log = blibs.log;
_G.blibs = blibs;
utils.MonReset(0.5)
updater.GetBasalt()

View File

@ -30,11 +30,7 @@ KEYPADOS_VERSION = "4.0"
---@param blibs BootloaderLibs
function mod.main(blibs)
print("blibs:" .. tostring(blibs));
print("blibs:" .. tostring(blibs.updater));
print("blibs:" .. tostring(blibs.log));
print("blibs:" .. tostring(blibs.json));
print("blibs:" .. tostring(blibs.notifier));
_G.log = blibs.log;
_G.blibs = blibs;
utils.MonReset(0.5)
updater.GetBasalt()

View File

@ -37,7 +37,6 @@ local function unlockDoor(ui)
end
end
basalt.debug("test")
if ui.pin == config.correctPin then
blibs.notifier.notify("5", "Unlocked door :3 love u");
ui.enterButton:setBackground(colors.green)
@ -123,8 +122,8 @@ function mod.InitUi()
end)
if not status and err ~= "Terminated" then
print("Error detected: " .. err)
http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
log.error("Error detected: " .. err)
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
fs.delete("basalt.lua")

View File

@ -1,65 +1,8 @@
local utils = require("utils.lua")
local config = require("config.lua")
local LAST_USED = os.time()
local mod = {}
-- For lsp, shouldnt ever be check for true
if not __UPDATE_HASH then
__UPDATE_HASH = "WHATTHEFUCK";
end
local function checkForUpdate()
local current_time = os.time()
local difference = math.abs(current_time - LAST_USED)
-- print("INFO: 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
print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
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
-- Make backup
if fs.exists("backup.lua") then
fs.delete("backup.lua")
end
fs.copy("startup.lua", "backup.lua")
if not string.find(update_code_text, __UPDATE_HASH) then
http.post(config.ntfy_url, "Computer #" .. tostring( os.getComputerID() ) .. " updating")
local file = fs.open("startup.lua", "w")
file.write(update_code_text)
file.close()
os.reboot()
else
print("Nothing changed, not updating.")
LAST_USED = os.time()
return
end
else
print("Bad file download (core)")
end
else
print("Bad mem read (core)")
end
else
print("Bad download (core)")
end
end
end
function mod.UpdateChecker()
while true do
local status, err = pcall(checkForUpdate)
if not status and err ~= "Terminated" then
http.post(config.ntfy_url, err, {Priority = "urgent"})
end
sleep(1)
end
end
function mod.GetBasalt()
if fs.exists("basalt.lua") then