Files
FSE-Ticket.sys/installer_refill.lua
Henry_Du 0a70ffe931 feat(installers): 切换资源URL到main分支并添加更新脚本安装
将所有安装脚本的资源下载链接从固定commit路径切换为main分支原始路径,同时为各安装器新增下载并写入对应更新脚本的逻辑,支持后续程序更新。
2026-06-28 13:20:49 +08:00

96 lines
2.7 KiB
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 writeFile(path, content, binary)
local mode = binary and "wb" or "w"
local f = fs.open(path, mode)
if not f then return false end
f.write(content)
f.close()
return true
end
local function atomicWrite(path, content, binary)
local tmp = path .. ".new"
if fs.exists(tmp) then fs.delete(tmp) end
if not writeFile(tmp, content, binary) then return false end
if fs.exists(path) then fs.delete(path) end
fs.move(tmp, path)
return true
end
local function httpGet(url)
if not http then return false, "HTTP API disabled" end
local okReq, err = pcall(function()
http.request({ url = url, method = "GET" })
end)
if not okReq then return false, tostring(err) end
while true do
local ev, p1, p2, p3 = os.pullEvent()
if ev == "http_success" and p1 == url then
local res = p2
if type(res) == "table" and type(res.readAll) == "function" then
local data = res.readAll()
res.close()
return true, data
end
return false, "invalid http response"
end
if ev == "http_failure" and p1 == url then
local failErr = p2
local res = p3
if type(p2) == "table" and type(p2.readAll) == "function" then
res = p2
failErr = p3
end
if type(res) == "table" and type(res.readAll) == "function" then
local data = res.readAll()
res.close()
return false, data
end
return false, tostring(failErr or "http_failure")
end
end
end
term.clear()
term.setCursorPos(1, 1)
print("Refill Machine Installer")
print("")
print("Downloading refill machine program...")
local ok, code = httpGet(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)
if not okUpdate or type(updateCode) ~= "string" or #updateCode == 0 then
print("Download failed: " .. tostring(updateCode or ""))
return
end
if not atomicWrite("refillmachine.lua", code, false) then
print("Write failed: refillmachine.lua")
return
end
if not atomicWrite("startup.lua", code, false) then
print("Write failed: startup.lua")
return
end
if not atomicWrite("startup", code, false) then
print("Write failed: startup")
return
end
if not atomicWrite("update_refill.lua", updateCode, false) then
print("Write failed: update_refill.lua")
return
end
print("")
print("Done.")
print("refillmachine.lua has been installed as startup.")
print("Reboot the computer to start the refill machine.")