Advertisement
DOGGYWOOF

Untitled

Jan 10th, 2025 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 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 Workstation Admin 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 ask if anyone else is going to use the workstation
  69. local function askIfAnyoneElseWillUse()
  70. setupUI("Doggy OS Workstation Admin Setup", "Will anyone else use this workstation?")
  71.  
  72. term.setCursorPos(3, 8)
  73. print("Will anyone else use this workstation? (y/n)")
  74. local response = readWithInputBox(3, 9, 20, false)
  75.  
  76. if response:lower() == "y" then
  77. -- Ask for their credentials and whether they should be standard or admin
  78. setupUI("Doggy OS Workstation Setup", "Enter the new user's credentials")
  79.  
  80. term.setCursorPos(3, 8)
  81. print("Username for new user:")
  82. local username = readWithInputBox(3, 9, 20, false)
  83.  
  84. term.setCursorPos(3, 12)
  85. print("Password for " .. username .. ":")
  86. local password = readWithInputBox(3, 13, 20, true)
  87.  
  88. -- Ask if the user is going to be standard or admin
  89. term.setCursorPos(3, 16)
  90. print("Is " .. username .. " an admin? (y/n)")
  91. local isAdmin = readWithInputBox(3, 17, 20, false)
  92.  
  93. -- Store the new user's details in the directory
  94. local userPath = "/disk/users/" .. username
  95. fs.makeDir(userPath)
  96. local passwordFile = fs.open(userPath .. "/password.txt", "w")
  97. passwordFile.write(password)
  98. passwordFile.close()
  99.  
  100. -- If user is admin, create admin.txt file
  101. if isAdmin:lower() == "y" then
  102. local adminFile = fs.open(userPath .. "/admin.txt", "w")
  103. adminFile.close()
  104. end
  105.  
  106. setupUI("Doggy OS Setup", "New user created")
  107. print("User '" .. username .. "' has been successfully created.")
  108. os.sleep(3)
  109. else
  110. setupUI("Doggy OS Setup", "No additional user")
  111. print("No additional user will be created.")
  112. os.sleep(2)
  113. end
  114. end
  115.  
  116. -- Function to delete all directories in /disk/users/ except "root"
  117. local function deleteDirectories()
  118. local usersPath = "/disk/users/"
  119.  
  120. -- Get a list of all directories
  121. local directories = fs.list(usersPath)
  122.  
  123. setupUI("Doggy OS Setup", "Cleaning up old user directories")
  124.  
  125. for _, dir in pairs(directories) do
  126. if dir ~= "root" then
  127. fs.delete(usersPath .. dir)
  128. end
  129. end
  130.  
  131. print("\nUnnecessary directories deleted.")
  132. os.sleep(2)
  133. end
  134.  
  135. -- Function to create /disk/users/ directory
  136. local function createUsersDirectory()
  137. local usersPath = "/disk/users/"
  138.  
  139. -- Recreate /disk/users/ directory
  140. fs.makeDir(usersPath)
  141.  
  142. setupUI("Doggy OS Setup", "Setting up the users directory")
  143. print("\nCreated /disk/users/ directory.")
  144. os.sleep(2)
  145. end
  146.  
  147. -- Function to set up the first admin account for the workstation
  148. local function setupAdminAccountForWorkstation()
  149. setupUI("Doggy OS Workstation Admin Setup", "Please provide Admin credentials")
  150.  
  151. -- Enter admin username
  152. term.setCursorPos(3, 8)
  153. print("Admin Username:")
  154. local username = readWithInputBox(3, 9, 20, false)
  155.  
  156. -- Enter admin password
  157. term.setCursorPos(3, 12)
  158. print("Admin Password:")
  159. local password = readWithInputBox(3, 13, 20, true)
  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 for admin privileges
  173. local adminFile = fs.open(userPath .. "/admin.txt", "w")
  174. adminFile.close()
  175.  
  176. setupUI("Doggy OS Setup", "Configuring admin account for workstation")
  177. print("Admin account for '" .. username .. "' has been successfully created for this workstation.")
  178. os.sleep(3)
  179. end
  180.  
  181. -- Function to label the workstation
  182. local function labelWorkstation()
  183. setupUI("Doggy OS Setup", "Labeling your workstation")
  184.  
  185. term.setCursorPos(3, 8)
  186. print("Enter a name for this workstation:")
  187. local label = readWithInputBox(3, 9, 20, false)
  188.  
  189. -- Set the workstation label
  190. os.setComputerLabel(label)
  191.  
  192. setupUI("Doggy OS Setup", "Finalizing setup")
  193. print("Workstation labeled as \"" .. label .. "\".")
  194. os.sleep(2)
  195. end
  196.  
  197. -- Main program
  198. deleteDirectories()
  199. createUsersDirectory()
  200. setupAdminAccountForWorkstation()
  201. askIfAnyoneElseWillUse()
  202. labelWorkstation()
  203.  
  204. -- Run /disk/boot/error instead of /disk/boot/BIOS
  205. setupUI("Running Doggy OS", "Please wait...")
  206. shell.run("/disk/boot/error")
  207.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement