Advertisement
DOGGYWOOF

BIOS with legacy boot

Jul 9th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. -- Function to draw a border
  2. local function drawBorder()
  3. term.clear()
  4. local w, h = term.getSize()
  5. for y = 1, h do
  6. term.setCursorPos(1, y)
  7. term.write("|")
  8. term.setCursorPos(w, y)
  9. term.write("|")
  10. end
  11. for x = 1, w do
  12. term.setCursorPos(x, 1)
  13. term.write("-")
  14. term.setCursorPos(x, h)
  15. term.write("-")
  16. end
  17. term.setCursorPos(1, 1)
  18. term.write("+")
  19. term.setCursorPos(w, 1)
  20. term.write("+")
  21. term.setCursorPos(1, h)
  22. term.write("+")
  23. term.setCursorPos(w, h)
  24. term.write("+")
  25. end
  26.  
  27. -- Function to center text on the screen
  28. local function centerText(text, y)
  29. local w, _ = term.getSize()
  30. local x = math.floor((w - #text) / 2) + 1
  31. term.setCursorPos(x, y)
  32. term.write(text)
  33. end
  34.  
  35. -- Function to show the UEFI message
  36. local function showUEFIMessage()
  37. drawBorder()
  38. local _, h = term.getSize()
  39. centerText("Doggy OS UEFI", math.floor(h / 2) - 1)
  40. centerText("Press Enter for boot options", math.floor(h / 2) + 1)
  41. end
  42.  
  43. -- Function to load the boot animation
  44. local function loadBootAnimation()
  45. if fs.exists("/disk/boot/boot-animation") then
  46. shell.run("/disk/boot/boot-animation")
  47. else
  48. print("Boot animation not found!")
  49. end
  50. end
  51.  
  52. -- Function to load the boot options
  53. local function loadBootOptions()
  54. if fs.exists("/disk/boot/boot-options") then
  55. shell.run("/disk/boot/boot-options")
  56. else
  57. print("Boot options not found!")
  58. end
  59. end
  60.  
  61. -- Function to check the password
  62. local function checkPassword()
  63. if fs.exists("/FW-Security/BIOS/Boot/poweron.pass") then
  64. local file = fs.open("/FW-Security/BIOS/Boot/poweron.pass", "r")
  65. local correctPassword = file.readAll()
  66. file.close()
  67.  
  68. while true do
  69. drawBorder()
  70. local _, h = term.getSize()
  71. centerText("Embedded Security Password", math.floor(h / 2) - 2)
  72. centerText("Enter Password:", math.floor(h / 2))
  73. term.setCursorPos(math.floor(term.getSize() / 2), math.floor(h / 2) + 1)
  74. local password = read("*") -- Read the password, hiding input
  75.  
  76. if password == correctPassword then
  77. return true
  78. else
  79. local timeoutFile = "/FW-Security/BIOS/Boot/TIMEOUT"
  80. local f = fs.open(timeoutFile, "w")
  81. f.close()
  82. return false
  83. end
  84. end
  85. end
  86. return true
  87. end
  88.  
  89. -- Function to handle timeout
  90. local function handleTimeout()
  91. local timeoutFile = "/FW-Security/BIOS/Boot/TIMEOUT"
  92. if fs.exists(timeoutFile) then
  93. local timeout = 30
  94. while timeout > 0 do
  95. drawBorder()
  96. local _, h = term.getSize()
  97. centerText("Incorrect password.", math.floor(h / 2) - 1)
  98. centerText("System locked for " .. timeout .. " seconds.", math.floor(h / 2))
  99. sleep(1)
  100. timeout = timeout - 1
  101. end
  102. fs.delete(timeoutFile)
  103. os.reboot()
  104. end
  105. end
  106.  
  107. -- Function to show the legacy message and ASCII art
  108. local function showLegacyMessage()
  109. term.clear()
  110. local ascii_art = [[
  111. _________________
  112. | | ___________ |o|
  113. | | ___________ | |
  114. | | ___________ | |
  115. | | ___________ | |
  116. | |_____________| |
  117. | _______ |
  118. | | | ||
  119. | DD | | V|
  120. |____|_______|____|
  121. ]]
  122. print(ascii_art)
  123. centerText("Please insert a Doggy OS Disk", select(2, term.getSize()) - 1)
  124. end
  125.  
  126. -- Function to rename directories if legacy.cfg exists
  127. local function handleLegacyConfig()
  128. if fs.exists("/legacy.cfg") then
  129. showLegacyMessage()
  130. if fs.exists("/disk/") then
  131. fs.move("/disk/", "/unused/")
  132. end
  133. if fs.exists("/recovery") then
  134. fs.move("/recovery", "/unused2/")
  135. end
  136. sleep(2) -- Display the message for 2 seconds
  137. end
  138. end
  139.  
  140. -- Function to run additional scripts if they exist
  141. local function runAdditionalScripts()
  142. local scripts = {"/disk/boot/error", "/disk/boot/startup", "/disk/boot/startup.lua"}
  143. for _, script in ipairs(scripts) do
  144. if fs.exists(script) then
  145. shell.run(script)
  146. end
  147. end
  148. end
  149.  
  150. -- Main function to handle UEFI message and timeout
  151. local function main()
  152. handleLegacyConfig()
  153.  
  154. handleTimeout()
  155.  
  156. if not checkPassword() then
  157. handleTimeout()
  158. return
  159. end
  160.  
  161. showUEFIMessage()
  162. local timer = os.startTimer(2) -- Set a timer for 2 seconds
  163.  
  164. while true do
  165. local event, param = os.pullEvent()
  166. if event == "key" and param == keys.enter then
  167. -- Load boot options if Enter is pressed
  168. loadBootOptions()
  169. return
  170. elseif event == "timer" and param == timer then
  171. -- Timer expired, load boot animation
  172. loadBootAnimation()
  173. runAdditionalScripts()
  174. return
  175. end
  176. end
  177. end
  178.  
  179. -- Start the main function
  180. main()
  181.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement