Advertisement
No_Zen

CarpetBackup

May 12th, 2024
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. local modem = peripheral.wrap("right")  -- Wrap the modem on the right side.
  2. modem.open(25813)  -- Open channel 25813
  3.  
  4. local seed = os.time() * os.getComputerID()
  5.  
  6. term.clear()
  7. term.setCursorPos(1, 1)
  8. print("Emergency System")
  9. print("Seed: " .. seed)
  10.  
  11. math.randomseed(seed)
  12.  
  13. while true do
  14.     local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  15.     print("Received message: " .. message)
  16.  
  17.     local args = {}
  18.     for word in string.gmatch(message, "%S+") do  -- Split the message into words
  19.         table.insert(args, word)
  20.     end
  21.     local command = table.remove(args, 1)  -- Remove the first element as the command
  22.  
  23.     local count = tonumber(args[1]) or 1  -- Default count is 1 if no amount specified
  24.     local slot = tonumber(args[1]) or 1  -- Default slot is 1 if no slot specified
  25.  
  26.     if command == "update" then
  27.         modem.closeAll()
  28.         local code = message:sub(8)  -- Ensure this starts at the correct index
  29.         local file = fs.open("startup", "w")  -- Open (or create) startup.lua for writing
  30.  
  31.         if file then
  32.             file.write(code)  -- Write the received code to the file
  33.             file.close()  -- Ensure the file is closed after writing
  34.             print("Updated startup script. Rebooting soon...")
  35.         else
  36.            print("Failed to open file for writing.")
  37.            return  -- Exit or handle error appropriately
  38.         end
  39.  
  40.         -- Generate a random wait time between 1 and 10 seconds
  41.         local waitTime = math.random(1, 10)
  42.         os.sleep(waitTime)  -- Wait for the randomly generated time
  43.  
  44.         -- Reboot the system
  45.         os.reboot()
  46.     else
  47.         print("Unknown command: " .. command)
  48.     end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement