Advertisement
DOGGYWOOF

Untitled

Jul 22nd, 2024
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. -- BIOS environment for Open OS Recovery
  2.  
  3. -- Function to print a message to the screen
  4. local function printMessage(message)
  5. local gpu = component.list("gpu")() -- Get the GPU component
  6. local screen = component.list("screen")() -- Get the screen component
  7. if gpu and screen then
  8. component.invoke(gpu, "bind", screen) -- Bind GPU to screen
  9. component.invoke(gpu, "set", 1, 1, message) -- Print message on screen
  10. end
  11. end
  12.  
  13. -- Function to clear the screen
  14. local function clearScreen()
  15. local gpu = component.list("gpu")()
  16. if gpu then
  17. component.invoke(gpu, "setBackground", 0x000000)
  18. component.invoke(gpu, "setForeground", 0xFFFFFF)
  19. component.invoke(gpu, "fill", 1, 1, 80, 25, " ")
  20. end
  21. end
  22.  
  23. -- Function to display the menu
  24. local function showMenu()
  25. clearScreen()
  26. printMessage("Open OS Recovery Environment\n")
  27. printMessage("1. Boot Open OS disk - run boot code\n")
  28. printMessage("2. Backup User data - copy /home/ data of Open OS labeled disk to the Unnamed drive\n")
  29. printMessage("3. Restore - restore the /home/ dir of unnamed drive to Open OS disk\n")
  30. printMessage("Select an option (1/2/3): ")
  31. end
  32.  
  33. -- Function to read user input
  34. local function readInput()
  35. local input = ""
  36. local address = component.list("keyboard")()
  37. if address then
  38. local keyboard = component.proxy(address)
  39. repeat
  40. local event, char = computer.pullSignal()
  41. if event == "key_down" then
  42. input = input .. char
  43. if char == 13 then -- Enter key
  44. break
  45. end
  46. end
  47. until false
  48. end
  49. return input
  50. end
  51.  
  52. -- Function to boot Open OS disk
  53. local function bootOpenOS()
  54. printMessage("Booting Open OS disk...\n")
  55. local eeprom = component.list("eeprom")()
  56. if eeprom then
  57. local address = component.invoke(eeprom, "getData")
  58. if address then
  59. printMessage("Boot address found: " .. address .. "\n")
  60. -- Simulate booting from the address
  61. computer.beep(1000, 0.1)
  62. else
  63. printMessage("No boot address found.\n")
  64. end
  65. else
  66. printMessage("EEPROM component not found.\n")
  67. end
  68. end
  69.  
  70. -- Function to backup user data
  71. local function backupUserData()
  72. printMessage("Backing up user data...\n")
  73. local openOSDisk = component.list("filesystem")() -- Replace with actual disk component
  74. local backupDrive = component.list("filesystem")() -- Replace with actual backup drive component
  75.  
  76. if openOSDisk and backupDrive then
  77. local sourceDir = "/home/"
  78. local destDir = "/backup/"
  79. -- Simulate file copy
  80. printMessage("Copying data from " .. sourceDir .. " to " .. destDir .. "...\n")
  81. -- Implement actual file copy logic here
  82. else
  83. printMessage("Required components for backup not found.\n")
  84. end
  85. end
  86.  
  87. -- Function to restore user data
  88. local function restoreUserData()
  89. printMessage("Restoring user data...\n")
  90. local openOSDisk = component.list("filesystem")() -- Replace with actual disk component
  91. local backupDrive = component.list("filesystem")() -- Replace with actual backup drive component
  92.  
  93. if openOSDisk and backupDrive then
  94. local sourceDir = "/backup/"
  95. local destDir = "/home/"
  96. -- Simulate file copy
  97. printMessage("Restoring data from " .. sourceDir .. " to " .. destDir .. "...\n")
  98. -- Implement actual file restore logic here
  99. else
  100. printMessage("Required components for restore not found.\n")
  101. end
  102. end
  103.  
  104. -- Main program loop
  105. while true do
  106. showMenu()
  107. local choice = readInput()
  108.  
  109. if choice == "1" then
  110. bootOpenOS()
  111. elseif choice == "2" then
  112. backupUserData()
  113. elseif choice == "3" then
  114. restoreUserData()
  115. else
  116. printMessage("Invalid option, please try again.\n")
  117. end
  118.  
  119. printMessage("Press Enter to return to the menu.\n")
  120. readInput()
  121. end
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement