Compare commits
10 Commits
7c78db3620
...
9e633867da
Author | SHA1 | Date | |
---|---|---|---|
9e633867da | |||
79c5654247 | |||
6b864b43be | |||
5fa92ae0c4 | |||
4ccc4b07da | |||
b0c5b756b1 | |||
a3ca65a458 | |||
d07a35f360 | |||
b88ca058fa | |||
df5e544347 |
63
keypadOS.lua
63
keypadOS.lua
|
@ -3,64 +3,17 @@ local __DEFAULT_IMPORT = require
|
||||||
local require = function(path)
|
local require = function(path)
|
||||||
if __BUNDLER_FILES[path] then
|
if __BUNDLER_FILES[path] then
|
||||||
return __BUNDLER_FILES[path]()
|
return __BUNDLER_FILES[path]()
|
||||||
|
elseif __BUNDLER_FILES[path .. ".lua"] then
|
||||||
|
return __BUNDLER_FILES[path .. ".lua"]()
|
||||||
else
|
else
|
||||||
return __DEFAULT_IMPORT(path)
|
return __DEFAULT_IMPORT(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local __UPDATE_HASH = "fa901aeda9f7ac12a3f0d9bbf4bec9efc14d7797"
|
local __UPDATE_HASH = "5e1c10aba96c3f9ded6aecb030f2774577c005af"
|
||||||
rawset(__BUNDLER_FILES, "updater.lua", function ()
|
rawset(__BUNDLER_FILES, "updater.lua", function ()
|
||||||
local utils = require("utils.lua")
|
local utils = require("utils.lua")
|
||||||
local config = require("config.lua")
|
local config = require("config.lua")
|
||||||
local LAST_USED = os.time()
|
|
||||||
local mod = {}
|
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()
|
function mod.GetBasalt()
|
||||||
if fs.exists("basalt.lua") then
|
if fs.exists("basalt.lua") then
|
||||||
utils.MonPrint("Basalt found!")
|
utils.MonPrint("Basalt found!")
|
||||||
|
@ -109,7 +62,6 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
||||||
local basalt = require("basalt")
|
local basalt = require("basalt")
|
||||||
local config = require("config.lua")
|
local config = require("config.lua")
|
||||||
local updater = require("updater.lua")
|
local updater = require("updater.lua")
|
||||||
local blibs = require("main").blibs;
|
|
||||||
local monitor = utils.Cast(peripheral.find("monitor"))
|
local monitor = utils.Cast(peripheral.find("monitor"))
|
||||||
local drive = utils.Cast(peripheral.find("drive"))
|
local drive = utils.Cast(peripheral.find("drive"))
|
||||||
local mod = {}
|
local mod = {}
|
||||||
|
@ -127,7 +79,6 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
||||||
drive:ejectDisk()
|
drive:ejectDisk()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
basalt.debug("test")
|
|
||||||
if ui.pin == config.correctPin then
|
if ui.pin == config.correctPin then
|
||||||
blibs.notifier.notify("5", "Unlocked door :3 love u");
|
blibs.notifier.notify("5", "Unlocked door :3 love u");
|
||||||
ui.enterButton:setBackground(colors.green)
|
ui.enterButton:setBackground(colors.green)
|
||||||
|
@ -199,8 +150,8 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
|
||||||
parallel.waitForAll(basalt.autoUpdate)
|
parallel.waitForAll(basalt.autoUpdate)
|
||||||
end)
|
end)
|
||||||
if not status and err ~= "Terminated" then
|
if not status and err ~= "Terminated" then
|
||||||
print("Error detected: " .. err)
|
log.error("Error detected: " .. err)
|
||||||
http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
|
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
|
||||||
sleep(5)
|
sleep(5)
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
fs.delete("basalt.lua")
|
fs.delete("basalt.lua")
|
||||||
|
@ -235,7 +186,8 @@ rawset(__BUNDLER_FILES, "main.lua", function ()
|
||||||
local mod = {}
|
local mod = {}
|
||||||
KEYPADOS_VERSION = "4.0"
|
KEYPADOS_VERSION = "4.0"
|
||||||
function mod.main(blibs)
|
function mod.main(blibs)
|
||||||
mod.blibs = blibs;
|
_G.log = blibs.log;
|
||||||
|
_G.blibs = blibs;
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
updater.GetBasalt()
|
updater.GetBasalt()
|
||||||
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
||||||
|
@ -244,3 +196,4 @@ rawset(__BUNDLER_FILES, "main.lua", function ()
|
||||||
end
|
end
|
||||||
return mod;
|
return mod;
|
||||||
end)
|
end)
|
||||||
|
return require("main.lua")
|
||||||
|
|
|
@ -30,7 +30,8 @@ KEYPADOS_VERSION = "4.0"
|
||||||
|
|
||||||
---@param blibs BootloaderLibs
|
---@param blibs BootloaderLibs
|
||||||
function mod.main(blibs)
|
function mod.main(blibs)
|
||||||
mod.blibs = blibs;
|
_G.log = blibs.log;
|
||||||
|
_G.blibs = blibs;
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
updater.GetBasalt()
|
updater.GetBasalt()
|
||||||
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
|
||||||
|
|
|
@ -2,7 +2,6 @@ local utils = require("utils.lua")
|
||||||
local basalt = require("basalt")
|
local basalt = require("basalt")
|
||||||
local config = require("config.lua")
|
local config = require("config.lua")
|
||||||
local updater = require("updater.lua")
|
local updater = require("updater.lua")
|
||||||
local blibs = require("main").blibs;
|
|
||||||
|
|
||||||
--- @type Monitor
|
--- @type Monitor
|
||||||
local monitor = utils.Cast(peripheral.find("monitor"))
|
local monitor = utils.Cast(peripheral.find("monitor"))
|
||||||
|
@ -38,7 +37,6 @@ local function unlockDoor(ui)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
basalt.debug("test")
|
|
||||||
if ui.pin == config.correctPin then
|
if ui.pin == config.correctPin then
|
||||||
blibs.notifier.notify("5", "Unlocked door :3 love u");
|
blibs.notifier.notify("5", "Unlocked door :3 love u");
|
||||||
ui.enterButton:setBackground(colors.green)
|
ui.enterButton:setBackground(colors.green)
|
||||||
|
@ -124,8 +122,8 @@ function mod.InitUi()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not status and err ~= "Terminated" then
|
if not status and err ~= "Terminated" then
|
||||||
print("Error detected: " .. err)
|
log.error("Error detected: " .. err)
|
||||||
http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
|
blibs.notifier.notify("5", err); --exposed ntfy url no spam me pls
|
||||||
sleep(5)
|
sleep(5)
|
||||||
utils.MonReset(0.5)
|
utils.MonReset(0.5)
|
||||||
fs.delete("basalt.lua")
|
fs.delete("basalt.lua")
|
||||||
|
|
|
@ -1,65 +1,8 @@
|
||||||
local utils = require("utils.lua")
|
local utils = require("utils.lua")
|
||||||
local config = require("config.lua")
|
local config = require("config.lua")
|
||||||
local LAST_USED = os.time()
|
|
||||||
|
|
||||||
local mod = {}
|
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()
|
function mod.GetBasalt()
|
||||||
if fs.exists("basalt.lua") then
|
if fs.exists("basalt.lua") then
|
||||||
|
|
29
x.py
29
x.py
|
@ -40,22 +40,29 @@ def get_hash(buf: str) -> str:
|
||||||
hasher.update(bytes(buf, "utf-8"));
|
hasher.update(bytes(buf, "utf-8"));
|
||||||
return hasher.hexdigest();
|
return hasher.hexdigest();
|
||||||
|
|
||||||
|
REQ_HEADER = """
|
||||||
|
local __BUNDLER_FILES = {}
|
||||||
|
local __DEFAULT_IMPORT = require
|
||||||
|
local require = function(path)
|
||||||
|
if __BUNDLER_FILES[path] then
|
||||||
|
return __BUNDLER_FILES[path]()
|
||||||
|
elseif __BUNDLER_FILES[path .. ".lua"] then
|
||||||
|
return __BUNDLER_FILES[path .. ".lua"]()
|
||||||
|
else
|
||||||
|
return __DEFAULT_IMPORT(path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local __UPDATE_HASH = __BUNDLER_REPLACE_HASH__
|
||||||
|
"""
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
buf = ""
|
buf = ""
|
||||||
buf += "local __BUNDLER_FILES = {}\n";
|
buf += REQ_HEADER;
|
||||||
buf += "local __DEFAULT_IMPORT = require\n";
|
|
||||||
buf += "local require = function(path)\n";
|
|
||||||
buf += " if __BUNDLER_FILES[path] then\n";
|
|
||||||
buf += " return __BUNDLER_FILES[path]()\n";
|
|
||||||
buf += " else\n";
|
|
||||||
buf += " return __DEFAULT_IMPORT(path)\n";
|
|
||||||
buf += " end\n";
|
|
||||||
buf += "end\n";
|
|
||||||
buf += "local __UPDATE_HASH = __BUNDLER_REPLACE_HASH__\n";
|
|
||||||
for file in FILES:
|
for file in FILES:
|
||||||
print(f"=== FILE: {file}");
|
print(f"=== FILE: {file}");
|
||||||
buf += read_file(file);
|
buf += read_file(file);
|
||||||
|
|
||||||
|
buf += "return require(\"main.lua\")";
|
||||||
|
|
||||||
if MINIMISE:
|
if MINIMISE:
|
||||||
buf = minimise(buf);
|
buf = minimise(buf);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user