Advertisement
DOGGYWOOF

Doggy OS setup

Sep 26th, 2024 (edited)
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 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 set up the first admin account
  100. local function setupFirstAdminAccount()
  101. setupUI("Doggy OS First Admin Setup", "Please provide Admin credentials")
  102.  
  103. -- Enter username
  104. term.setCursorPos(3, 8)
  105. print("Admin Username:")
  106. local username = readWithInputBox(3, 9, 20, false)
  107.  
  108. -- Enter password
  109. term.setCursorPos(3, 12)
  110. print("Admin Password:")
  111. local password = readWithInputBox(3, 13, 20, true)
  112.  
  113. -- Store the user details in the directory
  114. local userPath = "/disk/users/" .. username
  115.  
  116. -- Create user directory
  117. fs.makeDir(userPath)
  118.  
  119. -- Store password in a file
  120. local passwordFile = fs.open(userPath .. "/password.txt", "w")
  121. passwordFile.write(password)
  122. passwordFile.close()
  123.  
  124. -- Create admin.txt file
  125. local adminFile = fs.open(userPath .. "/admin.txt", "w")
  126. adminFile.close()
  127.  
  128. setupUI("Doggy OS Setup", "Configuring admin account")
  129. print("Admin account for '" .. username .. "' has been successfully created.")
  130. os.sleep(3)
  131. end
  132.  
  133. -- Function to label the computer
  134. local function labelComputer()
  135. setupUI("Doggy OS Setup", "Labeling your computer")
  136.  
  137. term.setCursorPos(3, 8)
  138. print("Enter a name for this computer:")
  139. local label = readWithInputBox(3, 9, 20, false)
  140.  
  141. -- Set the computer label
  142. os.setComputerLabel(label)
  143.  
  144. setupUI("Doggy OS Setup", "Finalizing setup")
  145. print("Computer labeled as \"" .. label .. "\".")
  146. os.sleep(2)
  147. end
  148.  
  149. -- Main program
  150. deleteDirectories()
  151. createUsersDirectory()
  152. setupFirstAdminAccount()
  153. labelComputer()
  154.  
  155. -- Run /disk/boot/error instead of /disk/boot/BIOS
  156. setupUI("Running Doggy OS", "Please wait...")
  157. shell.run("/disk/boot/error")
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement