Advertisement
DOGGYWOOF

User setup

Dec 8th, 2024 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.89 KB | None | 0 0
  1. -- WARNING: Use this script at your own risk.
  2. -- Ensure you have a backup before running it.
  3.  
  4. -- Doggy OS First Admin Account Setup Script with Clean UI
  5.  
  6. -- Function to clear the screen and set up UI
  7. local function setupUI(title, subtitle)
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10. term.setTextColor(colors.white)
  11. term.setBackgroundColor(colors.black)
  12. term.clear()
  13.  
  14. -- Center the title
  15. local w, h = term.getSize()
  16. local x = math.floor((w - #title) / 2)
  17. term.setCursorPos(x, 2)
  18. term.setTextColor(colors.cyan)
  19. print(title)
  20.  
  21. -- Subtitle below the title
  22. local x_subtitle = math.floor((w - #subtitle) / 2)
  23. term.setCursorPos(x_subtitle, 4)
  24. term.setTextColor(colors.lightGray)
  25. print(subtitle)
  26.  
  27. -- Draw horizontal line for separation
  28. term.setCursorPos(1, 6)
  29. term.setTextColor(colors.gray)
  30. print(string.rep("-", w))
  31. end
  32.  
  33. -- Function to draw an input box with grey shading from [ to ]
  34. local function drawInputBox(x, y, width)
  35. term.setBackgroundColor(colors.gray) -- Set background color to grey
  36. term.setTextColor(colors.lightBlue) -- Set text color to light blue
  37.  
  38. -- Draw the left bracket and shaded area
  39. term.setCursorPos(x, y)
  40. term.write("[")
  41. term.write(string.rep(" ", width - 2)) -- Fill with spaces for the shaded area
  42.  
  43. -- Draw the right bracket
  44. term.write("]")
  45.  
  46. -- Shadow effect (bottom-right)
  47. term.setTextColor(colors.lightGray)
  48. term.setCursorPos(x + width, y)
  49. term.write(" ")
  50. end
  51.  
  52. -- Function to get input with a clean input box
  53. local function readWithInputBox(x, y, width, isPassword)
  54. -- Draw the input box
  55. drawInputBox(x, y, width)
  56.  
  57. -- Move cursor inside the box for typing
  58. term.setCursorPos(x + 1, y)
  59.  
  60. -- Capture input (either password or regular)
  61. if isPassword then
  62. return read("*")
  63. else
  64. return read()
  65. end
  66. end
  67.  
  68. -- Function to delete all directories in /disk/users/ except "root"
  69. local function deleteDirectories()
  70. local usersPath = "/disk/users/"
  71.  
  72. -- Get a list of all directories
  73. local directories = fs.list(usersPath)
  74.  
  75. setupUI("Doggy OS Setup", "Cleaning up old user directories")
  76.  
  77. for _, dir in pairs(directories) do
  78. if dir ~= "root" then
  79. fs.delete(usersPath .. dir)
  80. end
  81. end
  82.  
  83. print("\nUnnecessary directories deleted.")
  84. os.sleep(2)
  85. end
  86.  
  87. -- Function to create /disk/users/ directory
  88. local function createUsersDirectory()
  89. local usersPath = "/disk/users/"
  90.  
  91. -- Recreate /disk/users/ directory
  92. fs.makeDir(usersPath)
  93.  
  94. setupUI("Doggy OS Setup", "Setting up the users directory")
  95. print("\nCreated /disk/users/ directory.")
  96. os.sleep(2)
  97. end
  98.  
  99. -- Function to generate a recovery key
  100. local function generateRecoveryKey()
  101. setupUI("Doggy OS Recovery Key Setup", "Generating recovery key")
  102.  
  103. -- Generate a random recovery key
  104. local chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  105. local recoveryKey = ""
  106. for i = 1, 16 do
  107. local index = math.random(1, #chars)
  108. recoveryKey = recoveryKey .. chars:sub(index, index)
  109. end
  110.  
  111. -- Display the recovery key to the user
  112. term.setCursorPos(3, 8)
  113. print("Recovery Key:")
  114. term.setCursorPos(3, 9)
  115. print(recoveryKey)
  116.  
  117. -- Save recovery key to the secure file
  118. local recoveryDir = "/disk/security/"
  119. fs.makeDir(recoveryDir) -- Ensure the directory exists
  120. local recoveryFile = fs.open(recoveryDir .. "RecoveryKEY.TXT", "w")
  121. recoveryFile.write(recoveryKey)
  122. recoveryFile.close()
  123.  
  124. print("\nPlease save this key securely. It will not be shown again.")
  125. print("\nPress any key to continue...")
  126. os.pullEvent("key") -- Wait for any key press before proceeding
  127. end
  128.  
  129. -- Function to set up the first admin account
  130. local function setupFirstAdminAccount()
  131. setupUI("Doggy OS First Admin Setup", "Please provide Admin credentials")
  132.  
  133. -- Enter username
  134. term.setCursorPos(3, 8)
  135. print("Admin Username:")
  136. local username = readWithInputBox(3, 9, 20, false)
  137.  
  138. -- Enter password
  139. term.setCursorPos(3, 12)
  140. print("Admin Password:")
  141. local password = readWithInputBox(3, 13, 20, true)
  142.  
  143. -- Confirm password
  144. term.setCursorPos(3, 16)
  145. print("Confirm Password:")
  146. local confirmPassword = readWithInputBox(3, 17, 20, true)
  147.  
  148. -- Check if passwords match
  149. while password ~= confirmPassword do
  150. setupUI("Doggy OS First Admin Setup", "Passwords do not match. Try again.")
  151.  
  152. term.setCursorPos(3, 12)
  153. print("Admin Password:")
  154. password = readWithInputBox(3, 13, 20, true)
  155.  
  156. term.setCursorPos(3, 16)
  157. print("Confirm Password:")
  158. confirmPassword = readWithInputBox(3, 17, 20, true)
  159. end
  160.  
  161. -- Store the user details in the directory
  162. local userPath = "/disk/users/" .. username
  163.  
  164. -- Create user directory
  165. fs.makeDir(userPath)
  166.  
  167. -- Store password in a file
  168. local passwordFile = fs.open(userPath .. "/password.txt", "w")
  169. passwordFile.write(password)
  170. passwordFile.close()
  171.  
  172. -- Create admin.txt file
  173. local adminFile = fs.open(userPath .. "/admin.txt", "w")
  174. adminFile.close()
  175.  
  176. setupUI("Doggy OS Setup", "Configuring admin account")
  177. print("Admin account for '" .. username .. "' has been successfully created.")
  178. os.sleep(3)
  179. end
  180.  
  181. -- Function to check for and enable root account if needed
  182. local function enableRootAccount()
  183. local rootPath = "/disk/users/root/"
  184. local disabledFile = rootPath .. "disabled.txt"
  185.  
  186. if fs.exists(disabledFile) then
  187. setupUI("Doggy OS Root Access", "Would you like to enable the root account?")
  188. print("Press 'Y' to enable, 'N' to skip.")
  189. local input = read()
  190.  
  191. if input:lower() == "y" then
  192. fs.delete(disabledFile)
  193. setupUI("Doggy OS Root Access", "Root account enabled.")
  194. print("Root account is now enabled.")
  195.  
  196. -- Ask if user wants to reset root password
  197. setupUI("Doggy OS Root Access", "Would you like to reset the root password?")
  198. print("Press 'Y' to reset, 'N' to keep the current password.")
  199. local resetInput = read()
  200.  
  201. if resetInput:lower() == "y" then
  202. -- Prompt for a new root password
  203. term.setCursorPos(3, 8)
  204. print("Enter new root password:")
  205. local newPassword = readWithInputBox(3, 9, 20, true)
  206.  
  207. term.setCursorPos(3, 12)
  208. print("Confirm new root password:")
  209. local confirmNewPassword = readWithInputBox(3, 13, 20, true)
  210.  
  211. -- Confirm password match
  212. while newPassword ~= confirmNewPassword do
  213. setupUI("Doggy OS Root Access", "Passwords do not match. Try again.")
  214. term.setCursorPos(3, 8)
  215. print("Enter new root password:")
  216. newPassword = readWithInputBox(3, 9, 20, true)
  217.  
  218. term.setCursorPos(3, 12)
  219. print("Confirm new root password:")
  220. confirmNewPassword = readWithInputBox(3, 13, 20, true)
  221. end
  222.  
  223. -- Save the new root password
  224. local rootPasswordFile = fs.open(rootPath .. "/password.txt", "w")
  225. rootPasswordFile.write(newPassword)
  226. rootPasswordFile.close()
  227.  
  228. setupUI("Doggy OS Root Access", "Root password reset successfully.")
  229. print("Root password has been reset.")
  230. os.sleep(2)
  231. else
  232. setupUI("Doggy OS Root Access", "Root password remains unchanged.")
  233. print("Root password remains unchanged.")
  234. os.sleep(2)
  235. end
  236. else
  237. setupUI("Doggy OS Root Access", "Root account remains disabled.")
  238. print("Root account is still disabled.")
  239. os.sleep(2)
  240. end
  241. else
  242. setupUI("Doggy OS Root Access", "Root account is already enabled.")
  243. print("Root account is already enabled.")
  244. os.sleep(2)
  245. end
  246. end
  247.  
  248. -- Function to label the computer
  249. local function labelComputer()
  250. setupUI("Doggy OS Setup", "Labeling your computer")
  251.  
  252. term.setCursorPos(3, 8)
  253. print("Enter a name for this computer:")
  254. local label = readWithInputBox(3, 9, 20, false)
  255.  
  256. -- Set the computer label
  257. os.setComputerLabel(label)
  258.  
  259. setupUI("Doggy OS Setup", "Finalizing setup")
  260. print("Computer labeled as \"" .. label .. "\".")
  261. os.sleep(2)
  262. end
  263.  
  264. -- Main program
  265. deleteDirectories()
  266. createUsersDirectory()
  267. generateRecoveryKey()
  268. setupFirstAdminAccount()
  269. enableRootAccount() -- Root access enabled before labeling the computer
  270. labelComputer()
  271.  
  272. -- Run /disk/boot/error instead of /disk/boot/BIOS
  273. setupUI("Running Doggy OS", "Please wait...")
  274. shell.run("/disk/boot/error")
  275.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement