Advertisement
osmarks

Potatobox

Aug 30th, 2019
445
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.22 KB | None | 0 0
  1. if os.getComputerLabel() == nil then os.setComputerLabel(("Sandbox-%d"):format(os.getComputerID())) end
  2.  
  3. local function update()
  4.     local h = http.get "https://pastebin.com/raw/SJHZqiGY"
  5.     local f = fs.open("startup", "w")
  6.     f.write(h.readAll())
  7.     h.close()
  8.     f.close()
  9. end
  10.  
  11. local function run()
  12.     term.setPaletteColor(colors.white, 0xffffff)
  13.     term.setPaletteColor(colors.black, 0x000000)
  14.     term.clear()
  15.     term.setCursorPos(1, 1)
  16.  
  17.     local h = http.get "https://pastebin.com/raw/Frv3xkB9"
  18.     local fn, err = load(h.readAll(), "@yafss")
  19.     h.close()
  20.     if not fn then error(err) end
  21.     local yafss = fn()
  22.  
  23.     local startup_message = [[Welcome to this GTech-sponsored computer.
  24. This shell is running in a sandbox. Any changes you make outside of "/persistent" will NOT be saved.
  25. Please save any important data or work elsewhere.]]
  26.  
  27.     local FS_overlay = {
  28.         ["startup"] = ([[
  29. print(%q)
  30. shell.setPath(shell.path() .. ":/persistent")
  31. ]]):format(startup_message),
  32.         ["/rom/programs/update.lua"] = [[os.update()
  33. print "Updated sandbox"
  34. os.full_reboot()]]
  35.     }
  36.  
  37.     local running = true
  38.     local function reinit_sandbox() running = false end
  39.  
  40.     local API_overrides = {
  41.         ["~expect"] = _G["~expect"],
  42.         os = {
  43.             shutdown = reinit_sandbox,
  44.             reboot = reinit_sandbox,
  45.             setComputerLabel = function() error "Nope." end,
  46.             update = update,
  47.             full_reboot = os.reboot
  48.         }
  49.     }
  50.  
  51.     if not fs.exists "boxdata" then fs.makeDir "boxdata" end
  52.     if not fs.exists "boxdata/persistent" then fs.makeDir "boxdata/persistent" end
  53.     for _, file in pairs(fs.list "boxdata") do
  54.         if file ~= "persistent" then fs.delete(fs.combine("boxdata", file)) end
  55.     end
  56.    
  57.     parallel.waitForAny(function()
  58.         yafss("boxdata", FS_overlay, API_overrides, { URL = "https://pastebin.com/raw/hvy03JuM" })
  59.     end,
  60.     function()
  61.         while running do coroutine.yield() end
  62.     end)
  63. end
  64.  
  65. local ok, err = pcall(update)
  66. if not ok then printError("Update error: " .. err) end
  67.  
  68. local function full_screen_message(msg)
  69.     term.setBackgroundColor(colors.black)
  70.     term.setTextColor(colors.white)
  71.     term.clear()
  72.     term.setCursorPos(1, 1)
  73.     print(msg)
  74. end
  75.  
  76. while true do
  77.     local ok, err = pcall(run)
  78.     if not ok then
  79.         full_screen_message("Sandbox crashed. Press any key to restart. Error: \n" .. err)
  80.     else
  81.         full_screen_message "Sandbox exited. Press any key to restart."
  82.     end
  83.     coroutine.yield "key"
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement