Advertisement
DOGGYWOOF

System Bootloader startup

Dec 6th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. -- Doggy OS UEFI
  2.  
  3. -- Function to draw a border
  4. local function drawBorder()
  5. term.clear()
  6. local w, h = term.getSize()
  7. for y = 1, h do
  8. term.setCursorPos(1, y)
  9. term.write("|")
  10. term.setCursorPos(w, y)
  11. term.write("|")
  12. end
  13. for x = 1, w do
  14. term.setCursorPos(x, 1)
  15. term.write("-")
  16. term.setCursorPos(x, h)
  17. term.write("-")
  18. end
  19. term.setCursorPos(1, 1)
  20. term.write("+")
  21. term.setCursorPos(w, 1)
  22. term.write("+")
  23. term.setCursorPos(1, h)
  24. term.write("+")
  25. term.setCursorPos(w, h)
  26. term.write("+")
  27. end
  28.  
  29. -- Function to center text on the screen
  30. local function centerText(text, y)
  31. local w, _ = term.getSize()
  32. local x = math.floor((w - #text) / 2) + 1
  33. term.setCursorPos(x, y)
  34. term.write(text)
  35. end
  36.  
  37. -- Function to show the UEFI message
  38. local function showUEFIMessage()
  39. drawBorder()
  40. local _, h = term.getSize()
  41. centerText("Doggy OS UEFI", math.floor(h / 2))
  42. end
  43.  
  44. -- Function to display an error screen
  45. local function showErrorScreen(message)
  46. term.setBackgroundColor(colors.red)
  47. term.setTextColor(colors.white)
  48. term.clear()
  49. drawBorder()
  50. local _, h = term.getSize()
  51. centerText("Doggy OS Internal Bootloader Error:", math.floor(h / 2) - 2)
  52. centerText(message, math.floor(h / 2))
  53. centerText("Press any key to restart...", math.floor(h / 2) + 2)
  54. os.pullEvent("key") -- Wait for a key press
  55. os.reboot() -- Reboot the system
  56. end
  57.  
  58. -- Function to load the boot animation
  59. local function loadBootAnimation()
  60. if fs.exists("/disk/boot/boot-animation") then
  61. shell.run("/disk/.BL")
  62. else
  63. print("Boot animation not found!")
  64. end
  65. end
  66.  
  67. -- Function to load the boot options
  68. local function loadBootOptions()
  69. if fs.exists("/disk/boot/boot-options") then
  70. shell.run("/disk/boot/boot-options")
  71. else
  72. print("Boot options not found!")
  73. end
  74. end
  75.  
  76. -- Function to check the password
  77. local function checkPassword()
  78. if fs.exists("/FW-Security/BIOS/Boot/poweron.pass") then
  79. local file = fs.open("/FW-Security/BIOS/Boot/poweron.pass", "r")
  80. local correctPassword = file.readAll()
  81. file.close()
  82.  
  83. while true do
  84. drawBorder()
  85. local _, h = term.getSize()
  86. centerText("Doggy OS Boot Authentication", math.floor(h / 2) - 2)
  87. centerText("Enter Password:", math.floor(h / 2))
  88. term.setCursorPos(math.floor(term.getSize() / 2), math.floor(h / 2) + 1)
  89. local password = read("*") -- Read the password, hiding input
  90.  
  91. if password == correctPassword then
  92. return true
  93. else
  94. local timeoutFile = "/FW-Security/BIOS/Boot/TIMEOUT"
  95. local f = fs.open(timeoutFile, "w")
  96. f.close()
  97. return false
  98. end
  99. end
  100. end
  101. return true
  102. end
  103.  
  104. -- Function to handle timeout
  105. local function handleTimeout()
  106. local timeoutFile = "/FW-Security/BIOS/Boot/TIMEOUT"
  107. if fs.exists(timeoutFile) then
  108. local timeout = 30
  109. while timeout > 0 do
  110. drawBorder()
  111. local _, h = term.getSize()
  112. centerText("Incorrect password.", math.floor(h / 2) - 1)
  113. centerText("System locked for " .. timeout .. " seconds.", math.floor(h / 2))
  114. sleep(1)
  115. timeout = timeout - 1
  116. end
  117. fs.delete(timeoutFile)
  118. os.reboot()
  119. end
  120. end
  121.  
  122. -- Main function to handle UEFI message, shutdown screen, and timeout
  123. local function main()
  124. -- Check if multishell is supported
  125. if not multishell then
  126. showErrorScreen("Multishell is not supported on this system.")
  127. return
  128. end
  129.  
  130. handleTimeout()
  131.  
  132. if not checkPassword() then
  133. handleTimeout()
  134. return
  135. end
  136.  
  137. -- Show UEFI message and wait for 2 seconds
  138. showUEFIMessage()
  139. local timer = os.startTimer(2) -- Set a timer for 2 seconds
  140.  
  141. -- Run the boot animation after the UEFI screen
  142. while true do
  143. local event, param = os.pullEvent()
  144. if event == "timer" and param == timer then
  145. -- After 2 seconds, run the boot animation
  146. loadBootAnimation() -- Run the animation
  147. shell.run("/disk/boot-options") -- Load boot options
  148. return
  149. end
  150. end
  151. end
  152.  
  153. -- Start the main function
  154. main()
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement