From 9a7d4b3175de42e7745865a93e7b4a854492f175 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 03:08:51 -0400 Subject: [PATCH] Add startup script for automatic file updates and launching inventoryManager --- startup/manager.lua | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 startup/manager.lua diff --git a/startup/manager.lua b/startup/manager.lua new file mode 100644 index 0000000..ab5095d --- /dev/null +++ b/startup/manager.lua @@ -0,0 +1,76 @@ +-- startup.lua for Inventory Manager computer +-- Auto-updates from git then launches inventoryManager.lua + +local REPO_RAW = "https://git.spatulaa.com/MayaTheShy/Inventory-Manager-CC/raw/branch/main" + +-- Files to download (destination -> repo path) +local FILES = { + ["inventoryManager.lua"] = "inventoryManager.lua", + ["lib/log.lua"] = "lib/log.lua", + ["lib/ui.lua"] = "lib/ui.lua", + ["data/smeltable.lua"] = "data/smeltable.lua", + ["data/fuel.lua"] = "data/fuel.lua", + ["data/compostable.lua"] = "data/compostable.lua", + ["data/craftable.lua"] = "data/craftable.lua", + ["data/alerts.lua"] = "data/alerts.lua", +} + +------------------------------------------------- + +local function ensureDir(filePath) + local dir = filePath:match("^(.+)/") + if dir and not fs.isDir(dir) then + fs.makeDir(dir) + end +end + +local function download(remotePath, localPath) + local url = REPO_RAW .. "/" .. remotePath + local response = http.get(url) + if response then + ensureDir(localPath) + local f = fs.open(localPath, "w") + f.write(response.readAll()) + f.close() + response.close() + return true + end + return false +end + +------------------------------------------------- + +term.clear() +term.setCursorPos(1, 1) +print("==================================") +print(" Inventory Manager - Startup") +print(" Computer ID: " .. os.getComputerID()) +print("==================================") +print("") + +-- Update files +local updated, failed = 0, 0 +for localPath, remotePath in pairs(FILES) do + write(" " .. localPath .. " ... ") + if download(remotePath, localPath) then + print("OK") + updated = updated + 1 + else + print("FAIL") + failed = failed + 1 + end +end + +print("") +if failed > 0 then + print(string.format("Updated %d files, %d failed.", updated, failed)) + print("Continuing with existing files...") +else + print(string.format("All %d files up to date.", updated)) +end + +print("") +print("Starting inventoryManager...") +sleep(1) + +shell.run("inventoryManager.lua")