Advertisement
DOGGYWOOF

Untitled

Feb 22nd, 2025 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 KB | None | 0 0
  1. -- Puppy OS 1.0 (Simplified Version)
  2. local systemName = "Puppy OS"
  3. local username = nil
  4. local password = nil
  5. local configPath = "/PuppyOS/config.txt"
  6. local recoveryPath = "/PuppyOS/recovery/"
  7. local pastebinURL = "https://pastebin.com/jMuSk5UJ" -- URL for new "startup" file
  8.  
  9. -- Ensure config folder exists
  10. if not fs.exists("/PuppyOS") then fs.makeDir("/PuppyOS") end
  11. if not fs.exists(recoveryPath) then fs.makeDir(recoveryPath) end
  12.  
  13. -- Load Config
  14. local function loadConfig()
  15. if fs.exists(configPath) then
  16. local file = fs.open(configPath, "r")
  17. local data = textutils.unserialize(file.readAll())
  18. file.close()
  19. if data then
  20. systemName = data.systemName or systemName
  21. username = data.username or username
  22. password = data.password or password
  23. end
  24. end
  25. end
  26.  
  27. -- Save Config
  28. local function saveConfig()
  29. local data = {
  30. systemName = systemName,
  31. username = username,
  32. password = password
  33. }
  34. local file = fs.open(configPath, "w")
  35. file.write(textutils.serialize(data))
  36. file.close()
  37. end
  38.  
  39. -- Boot Menu: Allows user to choose between regular boot or recovery mode
  40. local function bootMenu()
  41. term.clear()
  42. term.setCursorPos(1, 1)
  43. print("Welcome to ".. systemName)
  44. print("[1] Boot into OS")
  45. print("[2] Enter Recovery Mode")
  46. write("Select an option: ")
  47. local choice = read()
  48.  
  49. if choice == "1" then
  50. boot()
  51. elseif choice == "2" then
  52. recoveryMenu()
  53. else
  54. print("Invalid option. Restarting boot menu...")
  55. sleep(2)
  56. bootMenu()
  57. end
  58. end
  59.  
  60. -- Booting into the system
  61. local function boot()
  62. term.clear()
  63. term.setCursorPos(1, 1)
  64. print("Booting ".. systemName .." ...")
  65. sleep(1)
  66. loadConfig()
  67. if not username or not password then
  68. systemSetup()
  69. end
  70. if loginScreen() then
  71. desktop()
  72. end
  73. end
  74.  
  75. -- Recovery: Download system from Pastebin
  76. local function downloadSystem()
  77. print("Downloading the system...")
  78. local success, error = pcall(function()
  79. local response = http.get(pastebinURL)
  80. if not response then
  81. error("Download failed")
  82. end
  83. local file = fs.open(recoveryPath.."/startup.lua", "w")
  84. file.write(response.readAll())
  85. file.close()
  86. print("Download successful! Reinstalling system...")
  87. sleep(1)
  88. end)
  89. if not success then
  90. print("Error: " .. error)
  91. sleep(2)
  92. end
  93. end
  94.  
  95. -- Factory Reset
  96. local function factoryReset()
  97. print("Performing factory reset...")
  98. fs.delete(configPath) -- Remove user configurations
  99. fs.delete("/PuppyOS") -- Remove all data in /PuppyOS
  100. print("System reset. Restarting...")
  101. sleep(2)
  102. os.reboot()
  103. end
  104.  
  105. -- Recovery Menu
  106. local function recoveryMenu()
  107. term.clear()
  108. term.setCursorPos(1, 1)
  109. print("Recovery Menu")
  110. print("[1] Factory Reset")
  111. print("[2] Reinstall System")
  112. print("[3] Return to Boot Menu")
  113. write("Select an option: ")
  114. local choice = read()
  115.  
  116. if choice == "1" then
  117. factoryReset()
  118. elseif choice == "2" then
  119. downloadSystem()
  120. print("Reinstall completed! Rebooting...")
  121. sleep(2)
  122. os.reboot()
  123. elseif choice == "3" then
  124. bootMenu() -- Go back to the Boot Menu
  125. else
  126. print("Invalid option. Returning to Boot Menu...")
  127. sleep(2)
  128. bootMenu() -- Go back to the Boot Menu
  129. end
  130. end
  131.  
  132. -- System Setup (simple setup process)
  133. local function systemSetup()
  134. term.clear()
  135. term.setCursorPos(1, 1)
  136. print("Initial System Setup")
  137.  
  138. write("Enter System Name: ")
  139. local newName = read()
  140. systemName = newName ~= "" and newName or systemName
  141.  
  142. while not username do
  143. write("Set new username: ")
  144. local newUser = read()
  145. if newUser ~= "" then username = newUser end
  146. end
  147.  
  148. while not password do
  149. write("Set new password: ")
  150. local newPass = read("*")
  151. if newPass ~= "" then password = newPass end
  152. end
  153.  
  154. saveConfig()
  155. print("Setup Complete! Rebooting...")
  156. sleep(2)
  157. os.reboot()
  158. end
  159.  
  160. -- Login Screen
  161. local function loginScreen()
  162. while true do
  163. term.clear()
  164. term.setCursorPos(1, 1)
  165. print("Welcome to ".. systemName .."!")
  166. write("Username: ")
  167. local inputUser = read()
  168. write("Password: ")
  169. local inputPass = read("*")
  170.  
  171. if inputUser == username and inputPass == password then
  172. print("Login successful!")
  173. sleep(1)
  174. return true
  175. else
  176. print("Invalid credentials. Try again.")
  177. sleep(1)
  178. end
  179. end
  180. end
  181.  
  182. -- Draw Desktop
  183. local function drawDesktop()
  184. term.setBackgroundColor(colors.cyan)
  185. term.clear()
  186. term.setCursorPos(1, 1)
  187. print("Welcome to ".. systemName)
  188. print("[1] File Explorer")
  189. print("[2] Settings")
  190. print("[3] Terminal")
  191. print("[4] Power Menu")
  192. end
  193.  
  194. -- Desktop: Main interface
  195. local function desktop()
  196. while true do
  197. drawDesktop()
  198. local event, key = os.pullEvent("key")
  199. if key == keys.one then fileExplorer()
  200. elseif key == keys.two then settingsMenu()
  201. elseif key == keys.three then terminal()
  202. elseif key == keys.four then powerMenu()
  203. end
  204. end
  205. end
  206.  
  207. -- Simple File Explorer
  208. local function fileExplorer()
  209. term.clear()
  210. term.setCursorPos(1, 1)
  211. print("File Explorer")
  212. print("------------")
  213. local files = fs.list("/")
  214. for i, file in ipairs(files) do
  215. print(i .. ". " .. file)
  216. end
  217. print("Press any key to return...")
  218. os.pullEvent("key")
  219. end
  220.  
  221. -- Settings Menu
  222. local function settingsMenu()
  223. term.clear()
  224. term.setCursorPos(1, 1)
  225. print("System Settings")
  226. print("--------------")
  227. print("[1] Change System Name")
  228. print("[2] Change Username")
  229. print("[3] Change Password")
  230. print("[4] Back to Desktop")
  231. write("Select an option: ")
  232. local choice = read()
  233.  
  234. if choice == "1" then
  235. write("New System Name: ")
  236. systemName = read()
  237. print("System name updated!")
  238. elseif choice == "2" then
  239. write("New Username: ")
  240. username = read()
  241. print("Username updated!")
  242. elseif choice == "3" then
  243. write("New Password: ")
  244. password = read("*")
  245. print("Password updated!")
  246. end
  247. saveConfig()
  248. sleep(1)
  249. end
  250.  
  251. -- Terminal
  252. local function terminal()
  253. while true do
  254. term.clear()
  255. term.setCursorPos(1, 1)
  256. print("Puppy OS Terminal")
  257. print("Type 'exit' to leave terminal.")
  258. write("> ")
  259. local command = read()
  260. if command == "exit" then
  261. return
  262. else
  263. shell.run(command)
  264. end
  265. end
  266. end
  267.  
  268. -- Power Menu
  269. local function powerMenu()
  270. term.clear()
  271. term.setCursorPos(1, 1)
  272. print("Power Menu")
  273. print("[1] Restart")
  274. print("[2] Shutdown")
  275. print("[3] Back to Desktop")
  276. write("Select an option: ")
  277. local choice = read()
  278.  
  279. if choice == "1" then
  280. print("Restarting...")
  281. sleep(2)
  282. os.reboot()
  283. elseif choice == "2" then
  284. print("Shutting down...")
  285. sleep(2)
  286. os.shutdown()
  287. end
  288. end
  289.  
  290. -- Start Puppy OS
  291. bootMenu()
  292.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement