Auto update

This commit is contained in:
2026-01-01 22:36:04 -05:00
parent 3c570c9682
commit 955b0b867b
2 changed files with 71 additions and 27 deletions

View File

@ -72,8 +72,8 @@ config.logFile = "stargate.log"
-- AUTO-UPDATE -- AUTO-UPDATE
--------------------------------------------- ---------------------------------------------
-- Auto-update addresses file from git repository -- Auto-update all program files from git repository on startup
config.autoUpdateAddresses = true config.autoUpdate = true
config.addressesRepoUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/addresses.lua" config.repoBaseUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/"
return config return config

View File

@ -17,37 +17,81 @@
local config = require("config") local config = require("config")
-- Auto-update addresses file if enabled ---------------------------------------------
local function updateAddressesFile() -- AUTO-UPDATE SYSTEM
if config.autoUpdateAddresses and http then ---------------------------------------------
print("Checking for addresses file update...")
local response = http.get(config.addressesRepoUrl)
if response then
local content = response.readAll()
response.close()
local file = fs.open("addresses.lua", "w") local function autoUpdate()
if file then if not (config.autoUpdate and http) then
file.write(content)
file.close()
print("Addresses file updated successfully")
return true
else
print("Failed to write addresses file")
end
else
print("Failed to download addresses file - using local version")
end
end
return false return false
end end
-- Try to update addresses file print("Checking for program updates...")
local addressesUpdated = updateAddressesFile()
-- Reload addresses module if updated local filesToUpdate = {
if addressesUpdated then "startup.lua",
package.loaded["addresses"] = nil "addresses.lua",
"utils.lua",
"display.lua",
"events.lua",
"handlers.lua"
}
local updated = false
for _, filename in ipairs(filesToUpdate) do
local url = config.repoBaseUrl .. filename
local response = http.get(url)
if response then
local newContent = response.readAll()
response.close()
-- Check if file exists and compare content
local needsUpdate = true
if fs.exists(filename) then
local file = fs.open(filename, "r")
if file then
local currentContent = file.readAll()
file.close()
-- Only update if content is different
if currentContent == newContent then
needsUpdate = false
print(" [SKIP] " .. filename .. " (unchanged)")
end
end
end
if needsUpdate then
-- Delete old file if it exists
if fs.exists(filename) then
fs.delete(filename)
end
local file = fs.open(filename, "w")
if file then
file.write(newContent)
file.close()
print(" [UPDATE] " .. filename)
updated = true
else
print(" [FAIL] Could not write " .. filename)
end
end
else
print(" [SKIP] Could not download " .. filename)
end
end
return updated
end
-- Perform auto-update
if autoUpdate() then
print("Program updated! Restarting...")
sleep(2)
os.reboot()
end end
local addresses = require("addresses") local addresses = require("addresses")