Advertisement
DOGGYWOOF

Untitled

Feb 25th, 2025 (edited)
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.06 KB | None | 0 0
  1. -- Doggy OS Systems
  2. -- DogRE 13.0 (N3K0 V13 CFG)
  3.  
  4. local function clearScreen(message)
  5. term.clear()
  6. term.setCursorPos(1, 1)
  7. if message then
  8. print(message)
  9. end
  10. end
  11.  
  12. local function waitForDisk(diskPath, message)
  13. clearScreen(message)
  14. while not fs.exists(diskPath) do
  15. sleep(1)
  16. end
  17. end
  18.  
  19. local function promptForEnter(message)
  20. print(message .. " Press Enter to continue...")
  21. io.read() -- Wait for user to press Enter
  22. end
  23.  
  24. local function askToOverride(filePath)
  25. clearScreen("File " .. filePath .. " already exists.\nDo you want to override it?\n1. Yes\n2. No (Skip)")
  26. local choice = tonumber(io.read())
  27. if choice == 1 then
  28. return true -- User wants to override
  29. else
  30. return false -- User wants to skip
  31. end
  32. end
  33.  
  34. -- Enhanced error display
  35. local function displayError(errorMsg, errorCode)
  36. clearScreen("===== DOGGY OS SYSTEM RECOVERY ERROR =====")
  37. print("Error Message: " .. errorMsg)
  38. print("Error Code: DOSx7002")
  39.  
  40. print("\nPossible Causes:")
  41. print("1. Missing or corrupted files.")
  42. print("2. Disk access errors.")
  43. print("3. Unexpected system behavior.")
  44. print("\nSuggested Actions:")
  45. print("1. Check disk connections and try again.")
  46. print("2. Run a full system recovery.")
  47. print("3. Contact support if the issue persists.\n")
  48. promptForEnter("Press Enter to Reboot system and return to normal system environment")
  49. end
  50.  
  51. local function performAction(action, successMessage, failureMessage)
  52. clearScreen()
  53. local success, err = pcall(action)
  54. if success then
  55. print(successMessage)
  56. else
  57. -- Generate an error screen with detailed information
  58. displayError(failureMessage or "An unexpected error occurred.", err)
  59. end
  60. sleep(2)
  61. end
  62.  
  63. -- Function to create a snapshot of the current system
  64. local function createSnapshot()
  65. clearScreen("===== Doggy OS Snapshot =====")
  66. print("Enter a name for this snapshot:")
  67. local snapshotName = io.read()
  68. local snapshotDir = "./bkps/" .. snapshotName
  69.  
  70. if fs.exists(snapshotDir) then
  71. if not askToOverride(snapshotDir) then
  72. return
  73. end
  74. end
  75.  
  76. clearScreen("Saving snapshot...")
  77.  
  78. -- Create the snapshot directory
  79. fs.makeDir(snapshotDir)
  80.  
  81. -- Backup system files excluding /disk/users/ and /disk/config/
  82. local function backupDirectory(sourceDir, targetDir)
  83. for _, file in pairs(fs.list(sourceDir)) do
  84. local filePath = sourceDir .. "/" .. file
  85. local targetPath = targetDir .. "/" .. file
  86. if fs.isDir(filePath) then
  87. fs.makeDir(targetPath)
  88. backupDirectory(filePath, targetPath)
  89. else
  90. local fileData = fs.open(filePath, "r").readAll()
  91. local newFile = fs.open(targetPath, "w")
  92. newFile.write(fileData)
  93. newFile.close()
  94. end
  95. end
  96. end
  97.  
  98. backupDirectory("/disk", snapshotDir) -- Backup the whole /disk except the user data
  99.  
  100. print("Snapshot saved successfully!")
  101. promptForEnter("Press Enter to return to the menu")
  102. end
  103.  
  104. -- Function to list all saved snapshots
  105. local function listSnapshots()
  106. local snapshots = fs.list("./bkps")
  107. local snapshotNames = {}
  108.  
  109. for _, snapshot in pairs(snapshots) do
  110. local snapshotPath = "./bkps/" .. snapshot
  111. if fs.isDir(snapshotPath) then
  112. table.insert(snapshotNames, snapshot)
  113. end
  114. end
  115.  
  116. if #snapshotNames == 0 then
  117. clearScreen("No snapshots found.")
  118. promptForEnter("Press Enter to return to the menu")
  119. return nil
  120. end
  121.  
  122. clearScreen("Available Snapshots:\n")
  123. for i, snapshotName in ipairs(snapshotNames) do
  124. print(i .. ". " .. snapshotName)
  125. end
  126. print("\nEnter the number of the snapshot you want to load:")
  127. local choice = tonumber(io.read())
  128.  
  129. if choice and choice >= 1 and choice <= #snapshotNames then
  130. return snapshotNames[choice]
  131. else
  132. clearScreen("Invalid choice. Please try again.")
  133. sleep(2)
  134. return nil
  135. end
  136. end
  137.  
  138. -- Function to load a snapshot
  139. local function loadSnapshot()
  140. clearScreen("===== Load Snapshot =====")
  141. local snapshotName = listSnapshots()
  142.  
  143. if not snapshotName then
  144. return
  145. end
  146.  
  147. local snapshotDir = "./bkps/" .. snapshotName
  148. clearScreen("Loading snapshot...")
  149.  
  150. -- Backup user data (excluding /disk/users/ and /disk/config/)
  151. local function backupUserData()
  152. local userBackupDir = "./bkps/temp_users"
  153. fs.makeDir(userBackupDir)
  154.  
  155. -- Backup /disk/users/
  156. local function backupDirectory(sourceDir, targetDir)
  157. for _, file in pairs(fs.list(sourceDir)) do
  158. local filePath = sourceDir .. "/" .. file
  159. local targetPath = targetDir .. "/" .. file
  160. if fs.isDir(filePath) then
  161. fs.makeDir(targetPath)
  162. backupDirectory(filePath, targetPath)
  163. else
  164. local fileData = fs.open(filePath, "r").readAll()
  165. local newFile = fs.open(targetPath, "w")
  166. newFile.write(fileData)
  167. newFile.close()
  168. end
  169. end
  170. end
  171.  
  172. backupDirectory("/disk/users", userBackupDir)
  173. backupDirectory("/disk/config", "./bkps/temp_config")
  174. end
  175.  
  176. backupUserData()
  177.  
  178. -- Restore snapshot system files
  179. local function restoreDirectory(sourceDir, targetDir)
  180. for _, file in pairs(fs.list(sourceDir)) do
  181. local filePath = sourceDir .. "/" .. file
  182. local targetPath = targetDir .. "/" .. file
  183. if fs.isDir(filePath) then
  184. if file ~= "users" and file ~= "config" then -- Skip user data and config data
  185. fs.makeDir(targetPath)
  186. restoreDirectory(filePath, targetPath)
  187. end
  188. else
  189. local fileData = fs.open(filePath, "r").readAll()
  190. local newFile = fs.open(targetPath, "w")
  191. newFile.write(fileData)
  192. newFile.close()
  193. end
  194. end
  195. end
  196.  
  197. restoreDirectory(snapshotDir, "/disk") -- Restore system files
  198.  
  199. -- Restore user data
  200. local function restoreUserData()
  201. local function restoreDirectory(sourceDir, targetDir)
  202. for _, file in pairs(fs.list(sourceDir)) do
  203. local filePath = sourceDir .. "/" .. file
  204. local targetPath = targetDir .. "/" .. file
  205. if fs.isDir(filePath) then
  206. fs.makeDir(targetPath)
  207. restoreDirectory(filePath, targetPath)
  208. else
  209. local fileData = fs.open(filePath, "r").readAll()
  210. local newFile = fs.open(targetPath, "w")
  211. newFile.write(fileData)
  212. newFile.close()
  213. end
  214. end
  215. end
  216.  
  217. restoreDirectory("./bkps/temp_users", "/disk/users")
  218. restoreDirectory("./bkps/temp_config", "/disk/config")
  219. end
  220.  
  221. restoreUserData()
  222.  
  223. print("Snapshot loaded and user data restored successfully!")
  224. promptForEnter("Press Enter to return to the menu")
  225. end
  226.  
  227. local function recoverPassword()
  228. clearScreen("===== Doggy OS Password Recovery =====")
  229. print("Enter your username:")
  230. local username = io.read()
  231. local userPath = "/disk/users/" .. username .. "/password.txt"
  232.  
  233. -- Prompt for the system-wide recovery key
  234. local recoveryKeyPath = "/recovery/rckey.txt"
  235. if fs.exists(recoveryKeyPath) then
  236. print("Enter recovery key to proceed:")
  237. local enteredKey = io.read()
  238.  
  239. -- Check if the entered key matches the saved key
  240. local recoveryKeyFile = fs.open(recoveryKeyPath, "r")
  241. local storedKey = recoveryKeyFile.readAll()
  242. recoveryKeyFile.close()
  243.  
  244. if enteredKey == storedKey then
  245. if fs.exists(userPath) then
  246. print("A password reset has been initiated.")
  247. print("Enter new password:")
  248. local newPassword = io.read()
  249.  
  250. local file = fs.open(userPath, "w")
  251. file.write(newPassword)
  252. file.close()
  253.  
  254. print("Password reset successful.")
  255. else
  256. print("User not found.")
  257. end
  258. else
  259. print("Invalid recovery key. Access denied.")
  260. end
  261. else
  262. print("Recovery key file not found.")
  263. end
  264.  
  265. promptForEnter("Press Enter to return to the menu")
  266. end
  267.  
  268. local function recoveryMenu()
  269. while true do
  270. clearScreen("===== Recovery Options =====\n1. Full System Recovery\n2. Wipe data / Reset to factory defaults\n3. Password Recovery\n4. Create Snapshot\n5. Load Snapshot\n6. Exit")
  271. local choice = tonumber(io.read())
  272. if choice == 1 then
  273. fullSystemRecovery()
  274. elseif choice == 2 then
  275. wipeDataAndResetFactoryDefaults()
  276. elseif choice == 3 then
  277. recoverPassword()
  278. elseif choice == 4 then
  279. createSnapshot()
  280. elseif choice == 5 then
  281. loadSnapshot()
  282. elseif choice == 6 then
  283. break
  284. else
  285. clearScreen("Invalid choice. Please try again.")
  286. sleep(2)
  287. end
  288. end
  289. end
  290.  
  291. local function powerMenu()
  292. clearScreen("===== Power Options =====\n1. Reboot system\n2. Shutdown system")
  293. local choice = tonumber(io.read())
  294. if choice == 1 then
  295. os.reboot()
  296. elseif choice == 2 then
  297. os.shutdown()
  298. else
  299. clearScreen("Invalid choice. Please try again.")
  300. sleep(2)
  301. end
  302. end
  303.  
  304. local function mainMenu()
  305. while true do
  306. clearScreen("===== Doggy OS DEV Recovery GUI =====\n1. Recovery Options\n2. Power Options\n3. Exit")
  307. local choice = tonumber(io.read())
  308. if choice == 1 then
  309. recoveryMenu()
  310. elseif choice == 2 then
  311. powerMenu()
  312. else
  313. clearScreen("Invalid choice. Please try again.")
  314. sleep(2)
  315. end
  316. end
  317. end
  318.  
  319. -- Start the main menu
  320. if fs.exists("/disk/config/dogRE/disableRE.cfg/") then
  321. clearScreen("===== DOGGY OS SYSTEM RECOVERY ERROR =====")
  322. print("Error Message: " .. "Recovery Environment Disabled")
  323. print("Error Code: DOSx7000")
  324. print("\nPossible Causes:")
  325. print("1. Recovery Environment has been disabled by your system administrator")
  326. print("2. Malware or unwanted software disabled DogRE")
  327. print("3. System config errors or corruption")
  328. print("\nSuggested Actions:")
  329. print("1. Reboot the computer and re-enable DogRE")
  330. print("2. Reinstall Doggy OS or rebuild the recovery partition")
  331. print("3. Contact support if the issue persists.\n")
  332. promptForEnter("Press Enter to Reboot system")
  333. else
  334. mainMenu()
  335. end
  336.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement