diff --git a/install_ticketmachine.lua b/install_ticketmachine.lua index 513e30a..0012259 100644 --- a/install_ticketmachine.lua +++ b/install_ticketmachine.lua @@ -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 diff --git a/installer.lua b/installer.lua index 021ff86..d93e5d4 100644 --- a/installer.lua +++ b/installer.lua @@ -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 diff --git a/installer_bi.lua b/installer_bi.lua index 5584933..10c5efd 100644 --- a/installer_bi.lua +++ b/installer_bi.lua @@ -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 diff --git a/installer_refill.lua b/installer_refill.lua index a263d48..be457c6 100644 --- a/installer_refill.lua +++ b/installer_refill.lua @@ -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 diff --git a/update_gate.lua b/update_gate.lua index ea0d2be..515e85f 100644 --- a/update_gate.lua +++ b/update_gate.lua @@ -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.") diff --git a/update_machine.lua b/update_machine.lua index 7e8e0d4..62beaa5 100644 --- a/update_machine.lua +++ b/update_machine.lua @@ -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.") diff --git a/update_refill.lua b/update_refill.lua index 39bbca7..a47f112 100644 --- a/update_refill.lua +++ b/update_refill.lua @@ -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