fix(ota): make update scripts self-updating and add cache-busting to installers
This commit is contained in:
@@ -63,20 +63,25 @@ local function httpGet(url)
|
||||
end
|
||||
end
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
print("Ticket Machine Installer")
|
||||
print("")
|
||||
print("Downloading ticket machine program...")
|
||||
|
||||
local ok, code = httpGet(URL_MACHINE_HTTP)
|
||||
local ok, code = httpGet(getCacheBustedUrl(URL_MACHINE_HTTP))
|
||||
|
||||
if not ok or type(code) ~= "string" or #code == 0 then
|
||||
print("Download failed: " .. tostring(code or ""))
|
||||
return
|
||||
end
|
||||
|
||||
local okUpdate, updateCode = httpGet(URL_UPDATE_MACHINE)
|
||||
local okUpdate, updateCode = httpGet(getCacheBustedUrl(URL_UPDATE_MACHINE))
|
||||
if not okUpdate or type(updateCode) ~= "string" or #updateCode == 0 then
|
||||
print("Download failed: " .. tostring(updateCode or ""))
|
||||
return
|
||||
|
||||
+7
-2
@@ -62,9 +62,14 @@ local function httpGet(url)
|
||||
end
|
||||
end
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
local function download(url, path, binary)
|
||||
print("Downloading: " .. path)
|
||||
local ok, data = httpGet(url)
|
||||
local ok, data = httpGet(getCacheBustedUrl(url))
|
||||
if not ok then
|
||||
print("Download failed: " .. tostring(data or ""))
|
||||
return false
|
||||
@@ -103,7 +108,7 @@ end
|
||||
if not download(URL_PASS, "pass.dfpwm", true) then return end
|
||||
if not download(URL_ERROR, "error.dfpwm", true) then return end
|
||||
|
||||
local okGate, gateCode = httpGet(URL_GATE)
|
||||
local okGate, gateCode = httpGet(getCacheBustedUrl(URL_GATE))
|
||||
if not okGate then
|
||||
print("Download failed: startup")
|
||||
return
|
||||
|
||||
+7
-2
@@ -69,9 +69,14 @@ local function httpGet(url)
|
||||
end
|
||||
end
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
local function download(url, path, binary)
|
||||
print("Downloading: " .. path)
|
||||
local ok, data = httpGet(url)
|
||||
local ok, data = httpGet(getCacheBustedUrl(url))
|
||||
if not ok then
|
||||
print("Download failed: " .. tostring(data or ""))
|
||||
return false
|
||||
@@ -130,7 +135,7 @@ end
|
||||
if not download(URL_PASS, "pass.dfpwm", true) then return end
|
||||
if not download(URL_ERROR, "error.dfpwm", true) then return end
|
||||
|
||||
local okGate, gateCode = httpGet(URL_GATE)
|
||||
local okGate, gateCode = httpGet(getCacheBustedUrl(URL_GATE))
|
||||
if not okGate then
|
||||
print("Download failed: startup")
|
||||
return
|
||||
|
||||
@@ -54,19 +54,24 @@ local function httpGet(url)
|
||||
end
|
||||
end
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
print("Refill Machine Installer")
|
||||
print("")
|
||||
print("Downloading refill machine program...")
|
||||
|
||||
local ok, code = httpGet(URL_REFILL_MACHINE)
|
||||
local ok, code = httpGet(getCacheBustedUrl(URL_REFILL_MACHINE))
|
||||
if not ok or type(code) ~= "string" or #code == 0 then
|
||||
print("Download failed: " .. tostring(code or ""))
|
||||
return
|
||||
end
|
||||
|
||||
local okUpdate, updateCode = httpGet(URL_UPDATE_REFILL)
|
||||
local okUpdate, updateCode = httpGet(getCacheBustedUrl(URL_UPDATE_REFILL))
|
||||
if not okUpdate or type(updateCode) ~= "string" or #updateCode == 0 then
|
||||
print("Download failed: " .. tostring(updateCode or ""))
|
||||
return
|
||||
|
||||
+14
-2
@@ -1,8 +1,14 @@
|
||||
|
||||
local URL_GATE = "https://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/gate.lua"
|
||||
local URL_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/gate.lua"
|
||||
local URL_UPDATE_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/update_gate.lua"
|
||||
local args = { ... }
|
||||
local silent = AUTO_UPDATE_SILENT == true or args[1] == "--silent"
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
local function log(msg)
|
||||
if not silent then
|
||||
print(msg)
|
||||
@@ -70,7 +76,7 @@ if not silent then
|
||||
end
|
||||
log("Downloading gate program...")
|
||||
|
||||
local ok, code = httpGet(URL_GATE)
|
||||
local ok, code = httpGet(getCacheBustedUrl(URL_GATE))
|
||||
if not ok or type(code) ~= "string" or #code == 0 then
|
||||
error("Download failed: " .. tostring(code or ""))
|
||||
end
|
||||
@@ -81,6 +87,12 @@ end
|
||||
atomicWrite("startup", code, false)
|
||||
if fs.exists("gate.lua") then atomicWrite("gate.lua", code, false) end
|
||||
|
||||
log("Downloading updater program...")
|
||||
local okUp, codeUp = httpGet(getCacheBustedUrl(URL_UPDATE_GATE))
|
||||
if okUp and type(codeUp) == "string" and #codeUp > 0 then
|
||||
atomicWrite("update_gate.lua", codeUp, false)
|
||||
end
|
||||
|
||||
if not silent then
|
||||
log("")
|
||||
log("Done.")
|
||||
|
||||
+14
-2
@@ -1,7 +1,13 @@
|
||||
local URL_MACHINE = "https://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/ticketmachine.lua"
|
||||
local URL_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/ticketmachine.lua"
|
||||
local URL_UPDATE_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/update_machine.lua"
|
||||
local args = { ... }
|
||||
local silent = AUTO_UPDATE_SILENT == true or args[1] == "--silent"
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
local function log(msg)
|
||||
if not silent then
|
||||
print(msg)
|
||||
@@ -69,7 +75,7 @@ if not silent then
|
||||
end
|
||||
log("Downloading ticket machine program...")
|
||||
|
||||
local ok, code = httpGet(URL_MACHINE)
|
||||
local ok, code = httpGet(getCacheBustedUrl(URL_MACHINE))
|
||||
if not ok or type(code) ~= "string" or #code == 0 then
|
||||
error("Download failed: " .. tostring(code or ""))
|
||||
end
|
||||
@@ -80,6 +86,12 @@ end
|
||||
atomicWrite("startup", code, false)
|
||||
if fs.exists("ticketmachine.lua") then atomicWrite("ticketmachine.lua", code, false) end
|
||||
|
||||
log("Downloading updater program...")
|
||||
local okUp, codeUp = httpGet(getCacheBustedUrl(URL_UPDATE_MACHINE))
|
||||
if okUp and type(codeUp) == "string" and #codeUp > 0 then
|
||||
atomicWrite("update_machine.lua", codeUp, false)
|
||||
end
|
||||
|
||||
if not silent then
|
||||
log("")
|
||||
log("Done.")
|
||||
|
||||
+14
-2
@@ -1,6 +1,12 @@
|
||||
|
||||
|
||||
local URL_REFILL_MACHINE = "https://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/refillmachine.lua"
|
||||
local URL_REFILL_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/refillmachine.lua"
|
||||
local URL_UPDATE_REFILL = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/raw/branch/main/update_refill.lua"
|
||||
|
||||
local function getCacheBustedUrl(url)
|
||||
local sep = url:find("?") and "&" or "?"
|
||||
return url .. sep .. "_t=" .. tostring(os.epoch and os.epoch("utc") or math.random(1, 999999))
|
||||
end
|
||||
|
||||
local function writeFile(path, content, binary)
|
||||
local mode = binary and "wb" or "w"
|
||||
@@ -61,12 +67,18 @@ print("Refill Machine Updater")
|
||||
print("")
|
||||
print("Downloading refill machine program...")
|
||||
|
||||
local ok, code = httpGet(URL_REFILL_MACHINE)
|
||||
local ok, code = httpGet(getCacheBustedUrl(URL_REFILL_MACHINE))
|
||||
if not ok or type(code) ~= "string" or #code == 0 then
|
||||
print("Download failed: " .. tostring(code or ""))
|
||||
return
|
||||
end
|
||||
|
||||
print("Downloading updater program...")
|
||||
local okUp, codeUp = httpGet(getCacheBustedUrl(URL_UPDATE_REFILL))
|
||||
if okUp and type(codeUp) == "string" and #codeUp > 0 then
|
||||
atomicWrite("update_refill.lua", codeUp, false)
|
||||
end
|
||||
|
||||
if not atomicWrite("startup.lua", code, false) then
|
||||
print("Write failed: startup.lua")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user