Add startup script for Inventory Client with auto-update functionality
This commit is contained in:
75
startup/client.lua
Normal file
75
startup/client.lua
Normal file
@@ -0,0 +1,75 @@
|
||||
-- startup.lua for Inventory Client computer
|
||||
-- Auto-updates from git then launches inventoryClient + dropperController in parallel
|
||||
|
||||
local REPO_RAW = "https://git.spatulaa.com/MayaTheShy/Inventory-Manager-CC/raw/branch/main"
|
||||
|
||||
-- Files to download (destination -> repo path)
|
||||
local FILES = {
|
||||
["inventoryClient.lua"] = "inventoryClient.lua",
|
||||
["dropperController.lua"] = "dropperController.lua",
|
||||
["lib/log.lua"] = "lib/log.lua",
|
||||
["lib/ui.lua"] = "lib/ui.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 Client - 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 inventoryClient + dropperController...")
|
||||
sleep(1)
|
||||
|
||||
parallel.waitForAny(
|
||||
function() shell.run("inventoryClient.lua") end,
|
||||
function() shell.run("dropperController.lua") end
|
||||
)
|
||||
Reference in New Issue
Block a user