neuroticfox

DC17 Redux (Installer)

Nov 22nd, 2026
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.02 KB | None | 0 0
  1. --[[
  2.   Draconic Control Redux — Installer
  3.   Normal pastebin-get version.
  4.   Also refreshes /bin/dctail.lua from /home/dctail.lua.
  5. ]]
  6.  
  7. local term = require("term")
  8. local fs   = require("filesystem")
  9.  
  10. term.clear()
  11. term.setCursor(1, 1)
  12.  
  13. print("Draconic Control Redux Installer")
  14. print(string.rep("-", 36))
  15. print()
  16.  
  17. local function fileSize(path)
  18.   if not fs.exists(path) then return 0 end
  19.   local ok, size = pcall(fs.size, path)
  20.   if ok and size then return tonumber(size) or 0 end
  21.   return 0
  22. end
  23.  
  24. local function verifyLua(path, label)
  25.   if not path:match("%.lua$") then return true end
  26.  
  27.   local ok, err = loadfile(path)
  28.   if not ok then
  29.     print("FAILED")
  30.     print(label .. " downloaded/copied, but Lua syntax check failed:")
  31.     print(tostring(err))
  32.     return false
  33.   end
  34.  
  35.   return true
  36. end
  37.  
  38. local function ensureDir(path)
  39.   local dir = fs.path(path)
  40.   if dir and dir ~= "" and not fs.exists(dir) then
  41.     fs.makeDirectory(dir)
  42.   end
  43. end
  44.  
  45. local function copyFile(src, dest, label)
  46.   io.write("Installing " .. label .. " to " .. dest .. "... ")
  47.  
  48.   if not fs.exists(src) then
  49.     print("FAILED")
  50.     print("Source file does not exist: " .. src)
  51.     return false
  52.   end
  53.  
  54.   local srcSize = fileSize(src)
  55.   if srcSize <= 0 then
  56.     print("FAILED")
  57.     print("Source file is empty: " .. src)
  58.     return false
  59.   end
  60.  
  61.   ensureDir(dest)
  62.  
  63.   if fs.exists(dest) then
  64.     fs.remove(dest)
  65.   end
  66.  
  67.   local inFile, inErr = io.open(src, "rb")
  68.   if not inFile then
  69.     print("FAILED")
  70.     print("Could not open source: " .. tostring(inErr))
  71.     return false
  72.   end
  73.  
  74.   local data = inFile:read("*a")
  75.   inFile:close()
  76.  
  77.   local outFile, outErr = io.open(dest, "wb")
  78.   if not outFile then
  79.     print("FAILED")
  80.     print("Could not write destination: " .. tostring(outErr))
  81.     return false
  82.   end
  83.  
  84.   outFile:write(data)
  85.   outFile:close()
  86.  
  87.   if not fs.exists(dest) then
  88.     print("FAILED")
  89.     print("Destination was not created: " .. dest)
  90.     return false
  91.   end
  92.  
  93.   local destSize = fileSize(dest)
  94.   if destSize <= 0 then
  95.     print("FAILED")
  96.     print("Destination is empty after copy: " .. dest)
  97.     return false
  98.   end
  99.  
  100.   if destSize ~= srcSize then
  101.     print("FAILED")
  102.     print("Copy size mismatch.")
  103.     print("Source: " .. tostring(srcSize) .. " bytes")
  104.     print("Dest:   " .. tostring(destSize) .. " bytes")
  105.     return false
  106.   end
  107.  
  108.   if not verifyLua(dest, label) then
  109.     return false
  110.   end
  111.  
  112.   print("OK (" .. tostring(destSize) .. " bytes)")
  113.   return true
  114. end
  115.  
  116. local function download(id, dest, label)
  117.   io.write("Downloading " .. label .. "... ")
  118.  
  119.   ensureDir(dest)
  120.  
  121.   -- Remove stale/blank old copy first.
  122.   if fs.exists(dest) then
  123.     fs.remove(dest)
  124.   end
  125.  
  126.   os.execute("pastebin get -f " .. id .. " " .. dest)
  127.  
  128.   if not fs.exists(dest) then
  129.     print("FAILED")
  130.     print("File was not created: " .. dest)
  131.     return false
  132.   end
  133.  
  134.   local size = fileSize(dest)
  135.   if size <= 0 then
  136.     print("FAILED")
  137.     print(label .. " is empty/zero bytes after download.")
  138.     print("Pastebin ID: " .. id)
  139.     print("Destination: " .. dest)
  140.     return false
  141.   end
  142.  
  143.   if size < 20 then
  144.     print("FAILED")
  145.     print(label .. " is suspiciously tiny: " .. tostring(size) .. " bytes.")
  146.     print("Pastebin ID: " .. id)
  147.     print("Destination: " .. dest)
  148.     return false
  149.   end
  150.  
  151.   if not verifyLua(dest, label) then
  152.     return false
  153.   end
  154.  
  155.   print("OK (" .. tostring(size) .. " bytes)")
  156.   return true
  157. end
  158.  
  159. if not download("FJCyZYWD", "/home/dclib.lua",   "dclib.lua")   then print("Could not download dclib.lua. Aborting.");   return end
  160. if not download("ECCfT8y8", "/home/dc1.lua",     "dc1.lua")     then print("Could not download dc1.lua. Aborting.");     return end
  161.  
  162. -- New dctail paste:
  163. -- https://pastebin.com/XxHT0mjC
  164. if not download("XxHT0mjC", "/home/dctail.lua",  "dctail.lua")  then print("Could not download dctail.lua. Aborting."); return end
  165.  
  166. -- Critical: keep /bin from shadowing /home with an old/blank dctail.lua.
  167. if not copyFile("/home/dctail.lua", "/bin/dctail.lua", "dctail.lua") then
  168.   print("Could not refresh /bin/dctail.lua. Aborting.")
  169.   return
  170. end
  171.  
  172. print()
  173. io.write("Name for the master script (default: dcmaster): ")
  174. local name = io.read()
  175.  
  176. if not name or name:match("^%s*$") then
  177.   name = "dcmaster"
  178. end
  179.  
  180. name = name:gsub("%.lua$", "")
  181.  
  182. print()
  183.  
  184. if not download("wH0e0MC7", "/home/" .. name .. ".lua", name .. ".lua") then
  185.   print("Could not download " .. name .. ".lua. Aborting.")
  186.   return
  187. end
  188.  
  189. print()
  190. print(string.rep("-", 36))
  191. print("Install complete!")
  192. print()
  193. print("Run:  dc1            (single reactor)")
  194. print("Run:  dc1 -d         (danger mode)")
  195. print("Run:  " .. name .. "       (multi-reactor, up to 10)")
  196. print()
  197. print("Run:  dctail.lua     (live log tail)")
  198. print("Run:  dctail.lua --list")
  199. print("Run:  dctail.lua /home/dcmaster_log.txt")
  200. print()
  201. print("Installed files:")
  202. print("  /home/dclib.lua")
  203. print("  /home/dc1.lua")
  204. print("  /home/dctail.lua")
  205. print("  /bin/dctail.lua")
  206. print("  /home/" .. name .. ".lua")
  207. print()
Advertisement
Add Comment
Please, Sign In to add comment