gaga2023

Untitled

Nov 24th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. -- Add your configuration settings here
  2. local config = {
  3. GitHubUsername = 'oeed',
  4. GitHubRepoName = 'OneOS',
  5. InstallPath = '/',
  6. }
  7.  
  8. -- Function to handle HTTP requests with error handling
  9. local function download(url)
  10. local response = http.get(url)
  11. if not response then
  12. error('Failed to download: ' .. url)
  13. end
  14. return response.readAll()
  15. end
  16.  
  17. -- Function to download JSON from GitHub API
  18. local function downloadJSON(path)
  19. local url = 'https://api.github.com/repos/' .. config.GitHubUsername .. '/' .. config.GitHubRepoName .. path
  20. return textutils.unserialiseJSON(download(url))
  21. end
  22.  
  23. -- Function to download a file and handle retries
  24. local function downloadFile(url, destination)
  25. local tries, file
  26. repeat
  27. file = download(url)
  28. tries = tries + 1
  29. until tries > 5 or file
  30.  
  31. if not file then
  32. error('Downloading failed, try again. ' .. url)
  33. end
  34.  
  35. local handle = fs.open(destination, 'w')
  36. handle.write(file)
  37. handle.close()
  38. end
  39.  
  40. -- Function to update OneOS
  41. local function updateOneOS()
  42. -- Add update logic here
  43. -- Use the functions defined above to download JSON, files, etc.
  44. end
  45.  
  46. -- Main function
  47. local function main()
  48. print('OneOS Update Script')
  49.  
  50. -- Check if HTTP is enabled
  51. if not http then
  52. printError('HTTP is required for updating.')
  53. return
  54. end
  55.  
  56. -- Update OneOS
  57. updateOneOS()
  58.  
  59. print('Installation complete! Rebooting in 1 second...')
  60. sleep(1)
  61. os.reboot()
  62. end
  63.  
  64. -- Run the main function
  65. main()
  66.  
Tags: nothing
Advertisement
Add Comment
Please, Sign In to add comment