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 addresses file from git repository
config.autoUpdateAddresses = true
config.addressesRepoUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/addresses.lua"
-- Auto-update all program files from git repository on startup
config.autoUpdate = true
config.repoBaseUrl = "https://git.munebase.dev/Munelit/StargateControl/raw/branch/master/"
return config

View File

@ -17,37 +17,81 @@
local config = require("config")
-- Auto-update addresses file if enabled
local function updateAddressesFile()
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()
---------------------------------------------
-- AUTO-UPDATE SYSTEM
---------------------------------------------
local file = fs.open("addresses.lua", "w")
if file 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
local function autoUpdate()
if not (config.autoUpdate and http) then
return false
end
-- Try to update addresses file
local addressesUpdated = updateAddressesFile()
print("Checking for program updates...")
-- Reload addresses module if updated
if addressesUpdated then
package.loaded["addresses"] = nil
local filesToUpdate = {
"startup.lua",
"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
local addresses = require("addresses")