SHARE
TWEET

Miner Turtle Updater

Crunchy_Nut Jun 1st, 2020 (edited) 622 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2. local sides = rs.getSides()
  3. local updateFromShell = args[1]
  4. local turtleType = args[2]
  5.  
  6. local turtle_channel = "coms_turtles_" .. turtleType
  7.  
  8. for i = 1, #sides do
  9.     side = sides[i]
  10.     if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  11.         rednet.open(side)
  12.         break
  13.     end
  14. end
  15.  
  16. if updateFromShell == "true" then
  17.     rednet.receive(turtle_channel)
  18. end
  19.  
  20. rednet.broadcast("UPDATE_READY", turtle_channel)
  21. id, msg = rednet.receive("coms_turtles_payload", 15)
  22.  
  23. print("Received msg: " .. msg)
  24.  
  25. if not msg then
  26.     print("Failed to receieve an updated program packet!")
  27. else
  28.     packet = textutils.unserialize(msg)
  29.     file = fs.open(packet.name, "w")
  30.     file.write(packet.content)
  31.     file.close()
  32.     print("Update successful. Rebooting turtle..")
  33.     sleep(1)
  34.     os.reboot()
  35. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top