This commit is contained in:
2024-08-25 22:35:33 +03:00
parent 5df9f33c2e
commit 4161160ab6
4 changed files with 56 additions and 11 deletions

View File

@@ -1,8 +1,13 @@
local updater = require("updater");
local log = require("log");
local MODULE_NAME = "keypadOS";
local MODULE_URL = "https://git.mcorangehq.xyz/xomf/keypadOS/raw/branch/keypad/keypadOS.lua";
if not __VERSION then
__VERSION = "DEV";
end
--- @param upd Updater
local function updaterLoop(upd)
while true do
@@ -12,6 +17,7 @@ local function updaterLoop(upd)
end
local function _start()
log.info("Starting bootloader (" .. __VERSION .. ")");
local upd = updater.new();
upd:addEntry(MODULE_NAME .. ".lua", "keypad", MODULE_URL);
parallel.waitForAny(function() updaterLoop(upd) end, require(MODULE_NAME))

View File

@@ -41,7 +41,7 @@ function updater:checkAndUpdateAll()
for path, entry in pairs(self.updated_files) do
if self:check(entry.branch) then
self:update(path, entry.url);
log.info("Updated!");
log.info("Rebooting!");
sleep(3);
os.reboot();
end
@@ -51,6 +51,7 @@ end
function updater:check(branch)
local curr = os.time();
if not ((math.abs(curr - self.last_check) >= self.threshold) and (self.curr_commit_hash ~= "")) then
log.debug("Not time for an update yet");
return false;
end
self.last_check = curr;
@@ -69,8 +70,10 @@ function updater:check(branch)
local data = json.decode(body);
if self.curr_commit_hash == "" then
log.debug("No commit hash found, setting");
self.curr_commit_hash = data[1].hash;
elseif data[1].hash == self.curr_commit_hash then
log.debug("Commit hash doesnt match, probbably an update");
return true;
end
@@ -100,6 +103,7 @@ function updater:update(path, url)
local fd = fs.open(path, "w");
fd.write(body);
fd.close();
log.debug("New update written to disk (" .. path .. ")");
end
function updater:notify()