Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Draconic Control Redux — Installer
- Normal pastebin-get version.
- Also refreshes /bin/dctail.lua from /home/dctail.lua.
- ]]
- local term = require("term")
- local fs = require("filesystem")
- term.clear()
- term.setCursor(1, 1)
- print("Draconic Control Redux Installer")
- print(string.rep("-", 36))
- print()
- local function fileSize(path)
- if not fs.exists(path) then return 0 end
- local ok, size = pcall(fs.size, path)
- if ok and size then return tonumber(size) or 0 end
- return 0
- end
- local function verifyLua(path, label)
- if not path:match("%.lua$") then return true end
- local ok, err = loadfile(path)
- if not ok then
- print("FAILED")
- print(label .. " downloaded/copied, but Lua syntax check failed:")
- print(tostring(err))
- return false
- end
- return true
- end
- local function ensureDir(path)
- local dir = fs.path(path)
- if dir and dir ~= "" and not fs.exists(dir) then
- fs.makeDirectory(dir)
- end
- end
- local function copyFile(src, dest, label)
- io.write("Installing " .. label .. " to " .. dest .. "... ")
- if not fs.exists(src) then
- print("FAILED")
- print("Source file does not exist: " .. src)
- return false
- end
- local srcSize = fileSize(src)
- if srcSize <= 0 then
- print("FAILED")
- print("Source file is empty: " .. src)
- return false
- end
- ensureDir(dest)
- if fs.exists(dest) then
- fs.remove(dest)
- end
- local inFile, inErr = io.open(src, "rb")
- if not inFile then
- print("FAILED")
- print("Could not open source: " .. tostring(inErr))
- return false
- end
- local data = inFile:read("*a")
- inFile:close()
- local outFile, outErr = io.open(dest, "wb")
- if not outFile then
- print("FAILED")
- print("Could not write destination: " .. tostring(outErr))
- return false
- end
- outFile:write(data)
- outFile:close()
- if not fs.exists(dest) then
- print("FAILED")
- print("Destination was not created: " .. dest)
- return false
- end
- local destSize = fileSize(dest)
- if destSize <= 0 then
- print("FAILED")
- print("Destination is empty after copy: " .. dest)
- return false
- end
- if destSize ~= srcSize then
- print("FAILED")
- print("Copy size mismatch.")
- print("Source: " .. tostring(srcSize) .. " bytes")
- print("Dest: " .. tostring(destSize) .. " bytes")
- return false
- end
- if not verifyLua(dest, label) then
- return false
- end
- print("OK (" .. tostring(destSize) .. " bytes)")
- return true
- end
- local function download(id, dest, label)
- io.write("Downloading " .. label .. "... ")
- ensureDir(dest)
- -- Remove stale/blank old copy first.
- if fs.exists(dest) then
- fs.remove(dest)
- end
- os.execute("pastebin get -f " .. id .. " " .. dest)
- if not fs.exists(dest) then
- print("FAILED")
- print("File was not created: " .. dest)
- return false
- end
- local size = fileSize(dest)
- if size <= 0 then
- print("FAILED")
- print(label .. " is empty/zero bytes after download.")
- print("Pastebin ID: " .. id)
- print("Destination: " .. dest)
- return false
- end
- if size < 20 then
- print("FAILED")
- print(label .. " is suspiciously tiny: " .. tostring(size) .. " bytes.")
- print("Pastebin ID: " .. id)
- print("Destination: " .. dest)
- return false
- end
- if not verifyLua(dest, label) then
- return false
- end
- print("OK (" .. tostring(size) .. " bytes)")
- return true
- end
- if not download("drTghNFY", "/home/dclib.lua", "dclib.lua") then print("Could not download dclib.lua. Aborting."); return end
- if not download("ECCfT8y8", "/home/dc1.lua", "dc1.lua") then print("Could not download dc1.lua. Aborting."); return end
- -- New dctail paste:
- -- https://pastebin.com/0w7hTLCw
- if not download("0w7hTLCw", "/home/dctail.lua", "dctail.lua") then print("Could not download dctail.lua. Aborting."); return end
- -- Critical: keep /bin from shadowing /home with an old/blank dctail.lua.
- if not copyFile("/home/dctail.lua", "/bin/dctail.lua", "dctail.lua") then
- print("Could not refresh /bin/dctail.lua. Aborting.")
- return
- end
- print()
- io.write("Name for the master script (default: dcmaster): ")
- local name = io.read()
- if not name or name:match("^%s*$") then
- name = "dcmaster"
- end
- name = name:gsub("%.lua$", "")
- print()
- if not download("BxwLye1E", "/home/" .. name .. ".lua", name .. ".lua") then
- print("Could not download " .. name .. ".lua. Aborting.")
- return
- end
- print()
- print(string.rep("-", 36))
- print("Install complete!")
- print()
- print("Run: dc1 (single reactor)")
- print("Run: dc1 -d (danger mode)")
- print("Run: " .. name .. " (multi-reactor, up to 10)")
- print()
- print("Run: dctail.lua (live log tail)")
- print("Run: dctail.lua --list")
- print("Run: dctail.lua /home/dcmaster_log.txt")
- print()
- print("Installed files:")
- print(" /home/dclib.lua")
- print(" /home/dc1.lua")
- print(" /home/dctail.lua")
- print(" /bin/dctail.lua")
- print(" /home/" .. name .. ".lua")
- print()
Advertisement
Add Comment
Please, Sign In to add comment