Advertisement
DOGGYWOOF

Advanced and secure Doggy OS Recovery

Feb 23rd, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. -- Doggy OS Recovery
  2.  
  3. local function clearScreen()
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. end
  7.  
  8. local function setRecoveryPassword(password)
  9. local file = fs.open("/config.txt", "w")
  10. file.write(password)
  11. file.close()
  12. end
  13.  
  14. local function getRecoveryPassword()
  15. local file = fs.open("/config.txt", "r")
  16. local password = file.readAll()
  17. file.close()
  18. return password
  19. end
  20.  
  21. local function checkPassword()
  22. local password = getRecoveryPassword()
  23.  
  24. if password ~= "false" then
  25. while true do
  26. clearScreen()
  27. term.setCursorPos(1, 1)
  28. print("Enter Recovery Password:")
  29. local inputPassword = io.read("*l") or "" -- Use default value to handle possible EOF errors
  30. if inputPassword == password then
  31. break
  32. else
  33. print("Incorrect password. Try again.")
  34. sleep(2)
  35. end
  36. end
  37. end
  38. end
  39.  
  40. local function resetRecoveryPassword()
  41. local newPassword = io.read("Enter new recovery password: ")
  42. setRecoveryPassword(newPassword)
  43. print("Recovery password updated.")
  44. sleep(2)
  45. end
  46.  
  47. local function removeRecoveryPassword()
  48. setRecoveryPassword("false")
  49. print("Recovery password removed.")
  50. sleep(2)
  51. end
  52.  
  53. local function fullSystemRecovery()
  54. clearScreen()
  55. shell.run("delete /disk")
  56. shell.run("copy /recovery /disk")
  57. print("Full System Recovery completed.")
  58. sleep(2)
  59. end
  60.  
  61. local function refreshRecoveryPartition()
  62. clearScreen()
  63. print("Please insert Doggy OS disk!")
  64.  
  65. while not fs.exists("/disk2/") do
  66. sleep(1)
  67. end
  68.  
  69. shell.run("delete /recovery")
  70. shell.run("copy /disk2 /recovery")
  71. print("Recovery partition refreshed.")
  72. sleep(2)
  73. end
  74.  
  75. local function installUpdateFromDisk()
  76. clearScreen()
  77. print("Please insert Doggy OS disk!")
  78.  
  79. while not fs.exists("/disk2/") do
  80. sleep(1)
  81. end
  82.  
  83. shell.run("delete /disk")
  84. shell.run("copy /disk2 /disk")
  85. print("Update installed from disk.")
  86. sleep(2)
  87. end
  88.  
  89. -- Main loop
  90. while true do
  91. checkPassword()
  92.  
  93. clearScreen()
  94. print("Doggy OS Recovery Menu:")
  95. print("1. Recovery Options")
  96. print("2. Power Options")
  97. print("3. Security")
  98.  
  99. local mainChoice = tonumber(io.read())
  100.  
  101. if mainChoice == 1 then
  102. while true do
  103. clearScreen()
  104. term.setCursorPos(1, 1)
  105. print("Recovery Options:")
  106. print("1. Full System Recovery")
  107. print("2. Refresh Recovery Partition")
  108. print("3. Install Update from Disk")
  109. print("4. Back")
  110.  
  111. local recoveryChoice = tonumber(io.read())
  112.  
  113. if recoveryChoice == 1 then
  114. fullSystemRecovery()
  115. elseif recoveryChoice == 2 then
  116. refreshRecoveryPartition()
  117. elseif recoveryChoice == 3 then
  118. installUpdateFromDisk()
  119. elseif recoveryChoice == 4 then
  120. break -- Go back to the main menu
  121. else
  122. print("Invalid choice.")
  123. sleep(2)
  124. end
  125. end
  126. elseif mainChoice == 2 then
  127. clearScreen()
  128. term.setCursorPos(1, 1)
  129. print("Power Options:")
  130. print("1. Reboot system")
  131. print("2. Shutdown system")
  132.  
  133. local powerChoice = tonumber(io.read())
  134.  
  135. if powerChoice == 1 then
  136. os.reboot()
  137. elseif powerChoice == 2 then
  138. os.shutdown()
  139. else
  140. print("Invalid choice.")
  141. sleep(2)
  142. end
  143. elseif mainChoice == 3 then
  144. while true do
  145. clearScreen()
  146. term.setCursorPos(1, 1)
  147. print("Security Options:")
  148. print("1. Reset Recovery Password")
  149. print("2. Remove Recovery Password")
  150. print("3. Back")
  151.  
  152. local securityChoice = tonumber(io.read())
  153.  
  154. if securityChoice == 1 then
  155. resetRecoveryPassword()
  156. elseif securityChoice == 2 then
  157. removeRecoveryPassword()
  158. elseif securityChoice == 3 then
  159. break -- Go back to the main menu
  160. else
  161. print("Invalid choice.")
  162. sleep(2)
  163. end
  164. end
  165. else
  166. print("Invalid choice. Please try again.")
  167. sleep(2)
  168. end
  169. end
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement