Advertisement
Good_Pudge

Uduntu Installer

Sep 5th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.93 KB | None | 0 0
  1. local gpu = require("component").gpu
  2. local internet = require("component").internet
  3. local fs = require("filesystem")
  4.  
  5. --Проверка компонентов--
  6. do
  7.     NeedCom = {}
  8.   NowW,NowH = gpu.maxResolution()
  9.  
  10.     if  NowW < 80 then
  11.         table.insert(NeedCom,"Your monitor is 1 tier. Upgrade it to 2 tier or upper...")
  12.     end
  13.  
  14.     if fs.get("bin/edit.lua") == nil or fs.get("bin/edit.lua").isReadOnly() then
  15.         table.insert(NeedCom,"You don't install OpenOS. Please intall it...")
  16.     end
  17.  
  18.     if NeedCom ~= nil then
  19.         local i = 1
  20.         for i = 1,#NeedCom do
  21.             print(NeedCom[i])
  22.         end
  23.     else
  24.         print("O'key! All components is ready!\nStart download...")
  25.     end
  26. end
  27.  
  28. --Скачивание необходимого--
  29. do
  30.     DownloadList =
  31.     {
  32.         GPAPI = "Good-Pudge/OpenComputers-OS/master/Uduntu/GPAPI.lua",
  33.     }
  34.  
  35.  
  36. local function request(url)
  37.   local success, response = pcall(component.internet.request, url)
  38.   if success then
  39.     local responseData = ""
  40.     while true do
  41.       local data, responseChunk = response.read()
  42.       if data then
  43.         responseData = responseData .. data
  44.       else
  45.         if responseChunk then
  46.           return false, responseChunk
  47.         else
  48.           return responseData
  49.         end
  50.       end
  51.     end
  52.   else
  53.     return false, reason
  54.   end
  55. end
  56.  
  57. --БЕЗОПАСНАЯ ЗАГРУЗОЧКА
  58. local function getFromGitHubSafely(url, path)
  59.   local success, reason = request(url)
  60.   if success then
  61.     fs.makeDirectory(fs.path(path) or "")
  62.     fs.remove(path)
  63.     local file = io.open(path, "w")
  64.     file:write(success)
  65.     file:close()
  66.     return success
  67.   else
  68.     io.stderr:write("Can't download \"" .. url .. "\"!\n")
  69.     return -1
  70.   end
  71. end
  72.  
  73.     local GitHubUserUrl = "https://raw.githubusercontent.com/"
  74.  
  75.   for k,v in pairs(DownloadList) do
  76.     print("Downloading \"" .. fs.name(DownloadList[k]) .. "\"")
  77.     getFromGitHubSafely(GitHubUserUrl..DownloadList[v], DownloadList[k])
  78.   end
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement