Advertisement
HangMan23

SGL installer

Aug 12th, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. --Simple Graphic Library installer--
  2.  
  3. local component = require ("component")
  4. local computer = require ("computer")
  5. local io = require ("io")
  6.  
  7. local internet
  8.  
  9. ---------------------------------------------
  10.  
  11. local SGL_URL = "https://raw.githubusercontent.com/Smok1e/SGL/master/SGL.lua"
  12. local SGL_VERSION_URL = "https://raw.githubusercontent.com/Smok1e/SGL/master/SGL_Version.lua"
  13. local SGL_TEST_URL = "https://raw.githubusercontent.com/Smok1e/SGL/master/SGL_Test.lua"
  14. local SGL_AUTOUPDATE_URL = "https://raw.githubusercontent.com/Smok1e/SGL/master/SGL_AutoUpdate.lua"
  15.  
  16. local SGL_INSTALL_PATH = "/lib/SGL.lua"
  17. local SGL_VERSION_INSTALL_PATH = "/lib/SGL_Version.lua"
  18. local SGL_TEST_INSTALL_PATH = "/home/SGL_Test.lua"
  19. local SGL_AUTOUPDATE_INSTALL_PATH = "/boot/100_SGL_Update.lua"
  20.  
  21. ---------------------------------------------
  22.  
  23. local function download (url, path)
  24.  
  25. local request = internet.request (url)
  26.  
  27. if not request or request.response () then return nil, "Failed to get data from " .. url end
  28.  
  29. local file, reason = io.open (path, "w")
  30.  
  31. if not file then return nil, reason end
  32.  
  33. while true do
  34.  
  35. local chunk = request.read ()
  36.  
  37. if not chunk then break end
  38.  
  39. file:write (chunk)
  40.  
  41. end
  42.  
  43. file:close ()
  44.  
  45. return true
  46.  
  47. end
  48.  
  49. local function info_download (url, path)
  50.  
  51. print ("Downloading from '" .. url .. "' to '" .. path .. "'...")
  52.  
  53. local result, reason = download (url, path)
  54.  
  55. if not result then print (reason) return false end
  56.  
  57. return true
  58.  
  59. end
  60.  
  61. ---------------------------------------------
  62.  
  63. do
  64.  
  65. if component.list ("internet") () then
  66.  
  67. internet = component.internet
  68.  
  69. else
  70.  
  71. print ("Failed to load SGL: You do not have internet card")
  72.  
  73. end
  74.  
  75. if not info_download (SGL_URL, SGL_INSTALL_PATH) then return end
  76. --if not info_download (SGL_VERSION_URL, SGL_VERSION_INSTALL_PATH) then return end
  77. if not info_download (SGL_TEST_URL, SGL_TEST_INSTALL_PATH) then return end
  78. --if not info_download (SGL_AUTOUPDATE_URL, SGL_AUTOUPDATE_INSTALL_PATH) then return end
  79.  
  80. print ("Done")
  81. print ("Your computer will reboot in 3 seconds...")
  82.  
  83. os.sleep (3)
  84.  
  85. computer.shutdown (true)
  86.  
  87. end
  88.  
  89. ---------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement