Advertisement
DOGGYWOOF

Recovery Pocket Client

Feb 19th, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. -- Doggy OS Pocket Recovery Client
  2.  
  3. local modemSide = "right" -- Change this to the side where the wireless modem is attached
  4. local serverID
  5.  
  6. local function loadConfig()
  7. local configFilePath = "/config.txt"
  8. if fs.exists(configFilePath) then
  9. local file = fs.open(configFilePath, "r")
  10. serverID = file.readAll()
  11. file.close()
  12. return true
  13. else
  14. return false
  15. end
  16. end
  17.  
  18. local function requestFile(path)
  19. local modem = peripheral.wrap(modemSide)
  20. modem.transmit(tonumber(serverID), os.getComputerID(), "GET " .. path)
  21. local _, _, _, _, response = os.pullEvent("modem_message")
  22. return response
  23. end
  24.  
  25. local function copyFilesFromServer()
  26. local diskContents = requestFile("/disk/")
  27. if diskContents then
  28. local diskFile = fs.open("/disk/", "w")
  29. diskFile.write(diskContents)
  30. diskFile.close()
  31.  
  32. local recoveryContents = requestFile("/recovery/")
  33. if recoveryContents then
  34. local recoveryFile = fs.open("/recovery/", "w")
  35. recoveryFile.write(recoveryContents)
  36. recoveryFile.close()
  37.  
  38. print("Files copied successfully!")
  39. sleep(2)
  40. else
  41. print("Failed to copy recovery files.")
  42. sleep(2)
  43. end
  44. else
  45. print("Failed to copy disk files.")
  46. sleep(2)
  47. end
  48. end
  49.  
  50. local function recoverDevice()
  51. print("Please insert device into Doggy OS disk drive.")
  52. sleep(2)
  53. end
  54.  
  55. local function registerServer()
  56. print("Enter the Doggy OS Computer ID:")
  57. local newServerID = read()
  58. local configFilePath = "/config.txt"
  59. local file = fs.open(configFilePath, "w")
  60. file.write(newServerID)
  61. file.close()
  62. print("Server registered successfully!")
  63. sleep(2)
  64. end
  65.  
  66. -- Main Program
  67. if loadConfig() then
  68. print("Doggy OS Pocket Recovery Client")
  69. print("1. Recover Device")
  70. print("2. Exit")
  71. write("Select an option: ")
  72. local option = tonumber(read())
  73.  
  74. if option == 1 then
  75. copyFilesFromServer()
  76. elseif option == 2 then
  77. -- Do nothing, exit
  78. else
  79. print("Invalid option. Please try again.")
  80. sleep(2)
  81. end
  82. else
  83. print("Doggy OS Pocket Recovery Client (Not Registered)")
  84. print("1. Register Recovery Server")
  85. print("2. Connect to Server")
  86. print("3. Exit")
  87. write("Select an option: ")
  88. local option = tonumber(read())
  89.  
  90. if option == 1 then
  91. registerServer()
  92. elseif option == 2 then
  93. print("Enter the Doggy OS Computer ID to connect:")
  94. serverID = read()
  95. copyFilesFromServer()
  96. elseif option == 3 then
  97. -- Do nothing, exit
  98. else
  99. print("Invalid option. Please try again.")
  100. sleep(2)
  101. end
  102. end
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement