Advertisement
DOGGYWOOF

Doggy OS embedded boot options

Feb 10th, 2025 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. -- Function to draw a border with a more refined style
  2. local function drawBorder()
  3. term.clear()
  4. local w, h = term.getSize()
  5. -- Draw top and bottom borders with a different style
  6. for y = 1, h do
  7. term.setCursorPos(1, y)
  8. if y == 1 or y == h then
  9. term.write("=")
  10. else
  11. term.write("|")
  12. end
  13. term.setCursorPos(w, y)
  14. if y == 1 or y == h then
  15. term.write("=")
  16. else
  17. term.write("|")
  18. end
  19. end
  20. -- Draw side borders
  21. for x = 1, w do
  22. if x == 1 or x == w then
  23. term.setCursorPos(x, 1)
  24. term.write("=")
  25. term.setCursorPos(x, h)
  26. term.write("=")
  27. end
  28. end
  29. end
  30.  
  31. -- Function to center text on the screen
  32. local function centerText(text, y)
  33. local w, _ = term.getSize()
  34. local x = math.floor((w - #text) / 2) + 1
  35. term.setCursorPos(x, y)
  36. term.write(text)
  37. end
  38.  
  39. -- Function to show bootable device options with the updated UI
  40. local function showBootOptions()
  41. drawBorder()
  42. local _, h = term.getSize()
  43. centerText("Bootable Device Options", math.floor(h / 2) - 2)
  44.  
  45. -- Prepare a list of devices to check for startup files
  46. local devices = {}
  47. local mountPaths = {
  48. "/disk", "/disk2", "/disk3", "/disk4", "/disk5"
  49. }
  50.  
  51. -- Iterate over mount paths and check for startup files
  52. for _, path in ipairs(mountPaths) do
  53. if fs.exists(path) then
  54. if fs.exists(path .. "/startup.lua") then
  55. table.insert(devices, path .. "/startup.lua")
  56. elseif fs.exists(path .. "/startup") then
  57. table.insert(devices, path .. "/startup")
  58. end
  59. end
  60. end
  61.  
  62. -- Display the list of bootable devices
  63. if #devices == 0 then
  64. centerText("No bootable devices found", math.floor(h / 2))
  65. else
  66. for i, device in ipairs(devices) do
  67. centerText(i .. ". " .. device, math.floor(h / 2) + i)
  68. end
  69.  
  70. -- Prompt for a choice from the user
  71. term.setCursorPos(1, math.floor(h / 2) + #devices + 1)
  72. term.write("Select a device number: ")
  73. local choice = tonumber(read())
  74. if choice and devices[choice] then
  75. shell.run(devices[choice])
  76. else
  77. showBootOptions() -- Retry if an invalid option is selected
  78. end
  79. end
  80. end
  81.  
  82. -- Function to show the main UEFI menu with branding
  83. local function showMenu()
  84. drawBorder()
  85. local _, h = term.getSize()
  86. centerText("Doggy OS Embedded ROM Setup", 3)
  87. centerText("UEFI Options", math.floor(h / 2) - 2)
  88. centerText("1. Recovery", math.floor(h / 2))
  89. centerText("2. Bootable devices", math.floor(h / 2) + 1)
  90. centerText("3. Shutdown", math.floor(h / 2) + 2)
  91. centerText("4. Command Line", math.floor(h / 2) + 3) -- New option added
  92. end
  93.  
  94. -- Function to handle menu selection
  95. local function handleSelection()
  96. while true do
  97. local event, key = os.pullEvent("key")
  98. if key == keys.one then
  99. shell.run("/disk/boot/Recovery.lua")
  100. elseif key == keys.two then
  101. showBootOptions() -- Updated boot option
  102. elseif key == keys.three then
  103. os.shutdown()
  104. elseif key == keys.four then
  105. shell.run("/disk/os/home.lua") -- Command Line option added
  106. end
  107. end
  108. end
  109.  
  110. -- Function to verify user credentials
  111. local function verifyCredentials(username, password)
  112. local userPath = "/disk/users/" .. username
  113. if fs.exists(userPath .. "/admin.txt") and fs.exists(userPath .. "/password.txt") then
  114. local file = fs.open(userPath .. "/password.txt", "r")
  115. local storedPassword = file.readAll()
  116. file.close()
  117. return storedPassword == password
  118. end
  119. return false
  120. end
  121.  
  122. -- Function to authenticate user with the updated UI
  123. local function authenticate()
  124. term.clear()
  125. drawBorder()
  126. local _, h = term.getSize()
  127. centerText("Doggy OS Embedded ROM Setup", 3)
  128. centerText("Please enter your credentials to proceed", 5)
  129.  
  130. local w, _ = term.getSize()
  131. local formWidth = 40
  132. local formX = math.floor(w / 2) - math.floor(formWidth / 2)
  133.  
  134. -- Username prompt and input field
  135. term.setCursorPos(formX, 7)
  136. term.write("Username: ")
  137. term.setCursorPos(formX + 10, 7)
  138. local username = read()
  139.  
  140. -- Password prompt and input field
  141. term.setCursorPos(formX, 9)
  142. term.write("Password: ")
  143. term.setCursorPos(formX + 10, 9)
  144. local password = read("*") -- Masked input for password
  145.  
  146. -- Verify credentials
  147. if verifyCredentials(username, password) then
  148. centerText("Authentication successful", 12)
  149. os.sleep(1)
  150. showMenu()
  151. handleSelection()
  152. else
  153. centerText("Invalid credentials. Access denied.", 12)
  154. os.sleep(2)
  155. os.reboot()
  156. end
  157. end
  158.  
  159. -- Start authentication process
  160. authenticate()
  161.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement