Advertisement
DOGGYWOOF

Untitled

May 18th, 2024
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. -- VA11-ILLA Bootloader
  2. local function clearScreen()
  3. term.clear()
  4. term.setCursorPos(1, 1)
  5. end
  6.  
  7. local function rebootDevice()
  8. os.reboot()
  9. end
  10.  
  11. local function recoverSystem()
  12. shell.run("/disk/boot/Recovery.lua")
  13. end
  14.  
  15. local function bootOptions()
  16. clearScreen()
  17. print("Select disk to boot from:")
  18. local disks = peripheral.find("drive")
  19. if disks then
  20. for i, disk in ipairs(disks) do
  21. print(i .. ". " .. disk)
  22. end
  23. local choice = read()
  24. if tonumber(choice) and disks[tonumber(choice)] then
  25. shell.run("/disk/" .. disks[tonumber(choice)] .. "/startup.lua")
  26. else
  27. print("Invalid choice!")
  28. end
  29. else
  30. print("No disks found.")
  31. end
  32. end
  33.  
  34. local function setPassword()
  35. clearScreen()
  36. if not fs.exists("/firmware") then
  37. fs.makeDir("/firmware")
  38. end
  39. print("Enter new admin password:")
  40. local password = read("*")
  41. local file = fs.open("/firmware/password.cfg", "w")
  42. file.write(password)
  43. file.close()
  44. print("Password set.")
  45. end
  46.  
  47. local function removePassword()
  48. if fs.exists("/firmware/password.cfg") then
  49. fs.delete("/firmware/password.cfg")
  50. print("Password removed.")
  51. else
  52. print("No password set.")
  53. end
  54. end
  55.  
  56. local function securityMenu()
  57. while true do
  58. clearScreen()
  59. print("Security Menu:")
  60. print("1. Lock with admin password")
  61. print("2. Remove Lock")
  62. print("3. Back to main menu")
  63. local choice = read()
  64. if choice == "1" then
  65. setPassword()
  66. elseif choice == "2" then
  67. removePassword()
  68. elseif choice == "3" then
  69. break
  70. else
  71. print("Invalid choice! Press any key to continue...")
  72. os.pullEvent("key")
  73. end
  74. end
  75. end
  76.  
  77. local function checkPassword()
  78. if fs.exists("/firmware/password.cfg") then
  79. clearScreen()
  80. print("Enter admin password:")
  81. local password = read("*")
  82. local file = fs.open("/firmware/password.cfg", "r")
  83. local savedPassword = file.readAll()
  84. file.close()
  85. if password == savedPassword then
  86. return true
  87. else
  88. print("Invalid password!")
  89. sleep(2)
  90. return false
  91. end
  92. end
  93. return true
  94. end
  95.  
  96. local function mainMenu()
  97. while true do
  98. clearScreen()
  99. print("VA11-ILLA Bootloader:")
  100. print("1. Boot Doggy OS")
  101. print("2. Recover system")
  102. print("3. Boot options")
  103. print("4. Security")
  104. print("5. Exit")
  105. local choice = read()
  106. if choice == "1" then
  107. rebootDevice()
  108. elseif choice == "2" then
  109. recoverSystem()
  110. elseif choice == "3" then
  111. bootOptions()
  112. elseif choice == "4" then
  113. securityMenu()
  114. elseif choice == "5" then
  115. break
  116. else
  117. print("Invalid choice! Press any key to continue...")
  118. os.pullEvent("key")
  119. end
  120. end
  121. end
  122.  
  123. -- Start Bootloader
  124. if checkPassword() then
  125. mainMenu()
  126. end
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement