NusanTech

Untitled

Jun 23rd, 2025 (edited)
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.38 KB | Source Code | 0 0
  1. local fs = require("filesystem")
  2. local internet = require("internet")
  3. local computer = require("computer")
  4.  
  5. local file = {
  6.     name = "reactor.lua",
  7.     url = "https://raw.githubusercontent.com/NusanHuh/uc_big_reactor/refs/heads/main/reactor.lua"
  8. }
  9.  
  10. local home = "/home"
  11. fs.makeDirectory(home)
  12.  
  13. local function downloadFile(file)
  14.     local path = home .. "/" .. file.name
  15.     local handle, reason = internet.request(file.url)
  16.     if not handle then
  17.         io.stderr:write("Failed to download " .. file.name .. ": " .. tostring(reason) .. "\n")
  18.         return false
  19.     end
  20.  
  21.     local f = io.open(path, "w")
  22.     for chunk in handle do f:write(chunk) end
  23.     f:close()
  24.     return true
  25. end
  26.  
  27. local function isDownloaded()
  28.     return fs.exists(home .. "/" .. file.name)
  29. end
  30.  
  31. print("Downloading file to /home ...")
  32. print("→ " .. file.name)
  33. if downloadFile(file) then
  34.     print("  Download complete")
  35. else
  36.     print("  Download failed")
  37. end
  38.  
  39. if isDownloaded() then
  40.     local autorun = "/autorun.lua"
  41.     local f = io.open(autorun, "w")
  42.     f:write('os.execute("/home/reactor.lua")\n')
  43.     f:close()
  44.     print("\nFile downloaded successfully!")
  45.     print("'autorun.lua' created. The computer will auto-run reactor.lua at startup!")
  46.     print("Rebooting now...")
  47.  
  48.     os.sleep(2)
  49.     computer.shutdown(true)
  50. else
  51.     print("\nDownload failed. autorun.lua was not created.")
  52. end
Tags: opencomputer
Advertisement
Add Comment
Please, Sign In to add comment