diff --git a/install_ticketmachine.lua b/install_ticketmachine.lua new file mode 100644 index 0000000..f14d709 --- /dev/null +++ b/install_ticketmachine.lua @@ -0,0 +1,79 @@ + +local URL_MACHINE_HTTP = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/ticketmachine.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 err = p2 + local res = p3 + if type(p2) == "table" and type(p2.readAll) == "function" then + res = p2 + err = 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(err or "http_failure") + end + end +end + +term.clear() +term.setCursorPos(1, 1) +print("Ticket Machine Installer") +print("") +print("Downloading ticket machine program...") + +local ok, code = httpGet(URL_MACHINE_HTTP) + +if not ok or type(code) ~= "string" or #code == 0 then + print("Download failed: " .. tostring(code or "")) + return +end + +if not atomicWrite("startup", code, false) then + print("Write failed: startup") + return +end +atomicWrite("startup.lua", code, false) +if fs.exists("ticketmachine.lua") then atomicWrite("ticketmachine.lua", code, false) end + +print("") +print("Done.") +print("Reboot the computer to start the ticket machine.") diff --git a/installer.lua b/installer.lua index 354783a..6a084d0 100644 --- a/installer.lua +++ b/installer.lua @@ -1,6 +1,6 @@ -local URL_ERROR = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/108435e90d81c1c0a6e34486dee6cc6efd48ca53/error.dfpwm" -local URL_PASS = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/108435e90d81c1c0a6e34486dee6cc6efd48ca53/pass.dfpwm" -local URL_GATE = "http://cloud.fse-media.group/d/API/TicketMachine/gate.lua?sign=OWy1wKkKhUhpnxXKeX6fRLePSg1XcaQgWOLvQbMuHRQ=:0" +local URL_ERROR = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/error.dfpwm" +local URL_PASS = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/pass.dfpwm" +local URL_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/gate.lua" local CONFIG_PATH = "gate_config.json" diff --git a/installer_bi.lua b/installer_bi.lua index 5c44dfc..ab4c7a6 100644 --- a/installer_bi.lua +++ b/installer_bi.lua @@ -1,6 +1,6 @@ -local URL_ERROR = "http://cloud.fse-media.group/d/API/TicketMachine/error.dfpwm?sign=DvQ39wQDN6Cej4KPhAkM3JyXPM466koan6w9CckPxWU=:0" -local URL_PASS = "http://cloud.fse-media.group/d/API/TicketMachine/pass.dfpwm?sign=ZJfGDYnaxQU4JrGSh4NDzKZtjq3eMjYh9KHmMSAMKZA=:0" -local URL_GATE = "http://cloud.fse-media.group/d/API/TicketMachine/gate.lua?sign=OWy1wKkKhUhpnxXKeX6fRLePSg1XcaQgWOLvQbMuHRQ=:0" +local URL_ERROR = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/error.dfpwm" +local URL_PASS = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/pass.dfpwm" +local URL_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/gate.lua" local CONFIG_PATH = "gate_config.json" diff --git a/installer_refill.lua b/installer_refill.lua new file mode 100644 index 0000000..bc3edc6 --- /dev/null +++ b/installer_refill.lua @@ -0,0 +1,84 @@ +local URL_REFILL_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/refillmachine.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 + +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 + +print("") +print("Done.") +print("refillmachine.lua has been installed as startup.") +print("Reboot the computer to start the refill machine.") diff --git a/update_gate.lua b/update_gate.lua index 6a99e95..b17a6e3 100644 --- a/update_gate.lua +++ b/update_gate.lua @@ -1,5 +1,5 @@ -local URL_GATE = "http://cloud.fse-media.group/d/API/TicketMachine/gate.lua?sign=OWy1wKkKhUhpnxXKeX6fRLePSg1XcaQgWOLvQbMuHRQ=:0" +local URL_GATE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/gate.lua" local function writeFile(path, content, binary) local mode = binary and "wb" or "w" diff --git a/update_machine.lua b/update_machine.lua index 0e577f5..2f1bc8a 100644 --- a/update_machine.lua +++ b/update_machine.lua @@ -1,5 +1,5 @@ -local URL_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/db1562b83045284bfdec9e4a3feb829193963943/ticketmachine.lua" +local URL_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/ticketmachine.lua" local function writeFile(path, content, binary) local mode = binary and "wb" or "w" diff --git a/update_refill.lua b/update_refill.lua new file mode 100644 index 0000000..bb9f0cf --- /dev/null +++ b/update_refill.lua @@ -0,0 +1,84 @@ +local URL_REFILL_MACHINE = "http://gitea.fse-media.group/Henry_Du/FSE-Ticket.sys/src/commit/d6aa03d3a78f8b6fbd2754bf3f4199392c6ef4c1/refillmachine.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 Updater") +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 + +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("refillmachine.lua", code, false) then + print("Write failed: refillmachine.lua") + return +end + +print("") +print("Done.") +print("refillmachine.lua has been updated and installed as startup.") +print("Reboot the computer to apply the update.")