Merge commits

This commit is contained in:
Gvidas Juknevičius 2024-08-18 14:48:03 +03:00
commit a2546cb9ba
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
6 changed files with 88 additions and 37 deletions

View File

@ -7,7 +7,7 @@ local require = function(path)
return __DEFAULT_IMPORT(path) return __DEFAULT_IMPORT(path)
end end
end end
rawset(__BUNDLER_FILES, "updater.lua", function () local KEYPADOS_UPDATE_HASH = "ThZGemtZHshNpaflGvUHcJoZ"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 LAST_USED = os.time()
@ -17,24 +17,36 @@ rawset(__BUNDLER_FILES, "updater.lua", function ()
local difference = math.abs(current_time - LAST_USED) local difference = math.abs(current_time - LAST_USED)
if difference > .5 then if difference > .5 then
print("INFO: Updating! (diff: " .. tostring(difference) .. ")") print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url) local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
if update_code_request then if update_code_request then
local update_code_text = update_code_request.readAll() local update_code_text = update_code_request.readAll()
if update_code_text then if update_code_text then
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
fs.copy("startup.lua","backup.lua") if fs.exists("backup.lua") then
fs.delete("backup.lua")
end
fs.copy("startup.lua", "backup.lua")
if not string.find(update_code_text, KEYPADOS_UPDATE_HASH) then
local file = fs.open("startup.lua", "w") local file = fs.open("startup.lua", "w")
file.write(update_code_text) file.write(update_code_text)
file.close() file.close()
os.reboot() os.reboot()
else
print("Nothing changed, not updating.")
LAST_USED = os.time()
return
end end
else
print("Bad file download (core)") print("Bad file download (core)")
end end
else
print("Bad mem read (core)") print("Bad mem read (core)")
end end
else
print("Bad download (core)") print("Bad download (core)")
end end
end end
end
function mod.UpdateChecker() function mod.UpdateChecker()
while true do while true do
checkForUpdate() checkForUpdate()
@ -144,13 +156,20 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
ui.enterButton = ui.main:addButton() ui.enterButton = ui.main:addButton()
:setText(">>>>") :setText(">>>>")
:setBackground(colors.blue) :setBackground(colors.blue)
:setPosition(6,3) :setPosition(6,2)
:setSize(1.5,3.2) :setSize(1.5,3.2)
:onClick(function() :onClick(function()
unlockDoor(ui) unlockDoor(ui)
end) end)
local btnX = 1 local btnX = 1
local btnY = 3 local btnY = 2
ui.main:addButton()
:setPosition(1, 5)
:setText("0")
:setSize(6,1)
:onClick(function()
addToPin(ui, 0)
end)
for i = 1, 9 do for i = 1, 9 do
ui.main:addButton() ui.main:addButton()
:setPosition(btnX, btnY) :setPosition(btnX, btnY)
@ -170,11 +189,13 @@ rawset(__BUNDLER_FILES, "ui.lua", function ()
end) end)
if not status and err ~= "Terminated" then if not status and err ~= "Terminated" then
print("Error detected: " .. err) print("Error detected: " .. err)
monitor.clear() http.post("https://ntfy.sh/keypadOS_alerts", err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
fs.delete("basalt.lua") fs.delete("basalt.lua")
fs.delete("startup.lua") fs.delete("startup.lua")
fs.copy("backup.lua", "startup.lua") fs.copy("backup.lua", "startup.lua")
os.exit() os.reboot()
end end
end end
return mod return mod
@ -201,12 +222,12 @@ rawset(__BUNDLER_FILES, "main.lua", function ()
local utils = require("utils.lua") local utils = require("utils.lua")
local updater = require("updater.lua") local updater = require("updater.lua")
local main = {} local main = {}
KEYPADOS_VERSION = "3.0" KEYPADOS_VERSION = "4.0"
function main.Main() function main.Main()
utils.MonPrint(0.5) utils.MonReset(0.5)
updater.GetBasalt() updater.GetBasalt()
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION) utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
utils.MonPrint(1) utils.MonReset(1)
require("ui.lua").InitUi() require("ui.lua").InitUi()
end end
return main return main

View File

@ -2,6 +2,7 @@ local config = {
correctPin = "42169", correctPin = "42169",
release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua", release_url = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/main/keypadOS.lua",
basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua", basalt_url = "https://raw.githubusercontent.com/Pyroxenium/Basalt/master/docs/versions/latest.lua",
ntfy_url = "https://ntfy.sh/keypadOS_alerts",
config_path = "keypadOS.config.lua" config_path = "keypadOS.config.lua"
} }

View File

@ -5,13 +5,13 @@ local updater = require("updater.lua")
local main = {} local main = {}
KEYPADOS_VERSION = "3.0" KEYPADOS_VERSION = "4.0"
function main.Main() function main.Main()
utils.MonPrint(0.5) utils.MonReset(0.5)
updater.GetBasalt() updater.GetBasalt()
utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION) utils.MonPrint("keypadOS v" .. KEYPADOS_VERSION)
utils.MonPrint(1) utils.MonReset(1)
require("ui.lua").InitUi() require("ui.lua").InitUi()
end end

View File

@ -83,14 +83,22 @@ function mod.InitUi()
ui.enterButton = ui.main:addButton() ui.enterButton = ui.main:addButton()
:setText(">>>>") :setText(">>>>")
:setBackground(colors.blue) :setBackground(colors.blue)
:setPosition(6,3) :setPosition(6,2)
:setSize(1.5,3.2) :setSize(1.5,3.2)
:onClick(function() :onClick(function()
unlockDoor(ui) unlockDoor(ui)
end) end)
local btnX = 1 local btnX = 1
local btnY = 3 local btnY = 2
ui.main:addButton()
:setPosition(1, 5)
:setText("0")
:setSize(6,1)
:onClick(function()
addToPin(ui, 0)
end)
for i = 1, 9 do for i = 1, 9 do
ui.main:addButton() ui.main:addButton()
@ -114,12 +122,13 @@ function mod.InitUi()
if not status and err ~= "Terminated" then if not status and err ~= "Terminated" then
print("Error detected: " .. err) print("Error detected: " .. err)
monitor.clear() http.post(config.ntfy_url, err, {Priority = "urgent"}) --exposed ntfy url no spam me pls
sleep(5)
utils.MonReset(0.5)
fs.delete("basalt.lua") fs.delete("basalt.lua")
fs.delete("startup.lua") fs.delete("startup.lua")
fs.copy("backup.lua", "startup.lua") fs.copy("backup.lua", "startup.lua")
os.exit() os.reboot()
-- os.reboot()
end end
end end

View File

@ -4,6 +4,11 @@ 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 function checkForUpdate()
local current_time = os.time() local current_time = os.time()
local difference = math.abs(current_time - LAST_USED) local difference = math.abs(current_time - LAST_USED)
@ -12,26 +17,37 @@ local function checkForUpdate()
--therefore it's time to force an update down the users throat (microsoft moment) --therefore it's time to force an update down the users throat (microsoft moment)
if difference > .5 then if difference > .5 then
print("INFO: Updating! (diff: " .. tostring(difference) .. ")") print("INFO: Updating! (diff: " .. tostring(difference) .. ")")
local update_code_request = http.get(config.release_url) local update_code_request = http.get(config.release_url .. "?x=" .. tostring(math.random(11111111, 99999999))) -- I HATE CACHE REEEEEEEEEEEEEEEEE
if update_code_request then if update_code_request then
local update_code_text = update_code_request.readAll() local update_code_text = update_code_request.readAll()
if update_code_text then if update_code_text then
if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then if string.find(update_code_text, "^local __BUNDLER_FILES = {}") then
--make backup -- Make backup
fs.copy("startup.lua","backup.lua") if fs.exists("backup.lua") then
fs.delete("backup.lua")
end
fs.copy("startup.lua", "backup.lua")
--install update if not string.find(update_code_text, __UPDATE_HASH) then
local file = fs.open("startup.lua", "w") local file = fs.open("startup.lua", "w")
file.write(update_code_text) file.write(update_code_text)
file.close() file.close()
os.reboot() os.reboot()
else
print("Nothing changed, not updating.")
LAST_USED = os.time()
return
end end
else
print("Bad file download (core)") print("Bad file download (core)")
end end
else
print("Bad mem read (core)") print("Bad mem read (core)")
end end
else
print("Bad download (core)") print("Bad download (core)")
end end
end
end end
function mod.UpdateChecker() function mod.UpdateChecker()

6
x.py
View File

@ -1,5 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
import string
import random
UPDATE_ID= ''.join(random.choices(string.ascii_letters, k=24))
OUTPUT="keypadOS.lua"; OUTPUT="keypadOS.lua";
FILES= [ FILES= [
"updater.lua", "updater.lua",
@ -36,6 +38,7 @@ def minimise(buf: str) -> str:
def main(): def main():
buf = "" buf = ""
buf += "local __UPDATE_HASH = \"" + {UPDATE_ID} + "\"";
buf += "local __BUNDLER_FILES = {}\n"; buf += "local __BUNDLER_FILES = {}\n";
buf += "local __DEFAULT_IMPORT = require\n"; buf += "local __DEFAULT_IMPORT = require\n";
buf += "local require = function(path)\n"; buf += "local require = function(path)\n";
@ -49,6 +52,7 @@ def main():
for file in FILES: for file in FILES:
print(f"=== FILE: {file}"); print(f"=== FILE: {file}");
buf += read_file(file); buf += read_file(file);
print(f"=== UPDATE HASH: {UPDATE_ID}")
buf += "require(\"main.lua\").Main()\n"; buf += "require(\"main.lua\").Main()\n";