Advertisement
FFGFlash

manager-client_installer.lua

Oct 2nd, 2022 (edited)
1,256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.57 KB | None | 0 0
  1. if http then
  2.   local function download(user, repo, dpath, rpath, branch, extract)
  3.     if repo == nil or user == nil then return false,"User and Repo required" end
  4.     if rpath == nil then rpath = "" end
  5.     if dpath == nil then dpath = "/downloads/" end
  6.     if branch == nil then branch = "main" end
  7.     if extract == nil then extract = false end
  8.  
  9.     local function downloadManager(path, files, dirs)
  10.       if not files then files = {} end
  11.       if not dirs then dirs = {} end
  12.       local fType,fPath,fName,cPath = {},{},{},{}
  13.       local res = http.get("https://api.github.com/repos/"..user.."/"..repo.."/contents/"..path.."?ref="..branch)
  14.       if not res then return false,"Can't resolve URL" end
  15.       res = res.readAll()
  16.       if res ~= nil then
  17.         for str in res:gmatch('"type":"(%w+)"') do table.insert(fType, str) end
  18.         for str in res:gmatch('"path":"([^\"]+)"') do table.insert(fPath, str) end
  19.         for str in res:gmatch('"name":"([^\"]+)"') do table.insert(fName, str) end
  20.       end
  21.       for i,data in pairs(fType) do
  22.         local path = dpath.."/"
  23.         if not extract then
  24.           path = path..repo.."/"
  25.         end
  26.         if data == "file" then
  27.           cPath = http.get("https://raw.github.com/"..user.."/"..repo.."/"..branch.."/"..fPath[i])
  28.           if cPath == nil then fPath[i] = fPath[i].."/"..fName[i] end
  29.           path = path..fPath[i]
  30.           if not files[path] then
  31.             files[path] = { "https://raw.github.com/"..user.."/"..repo.."/"..branch.."/"..fPath[i], fName[i] }
  32.           end
  33.         elseif data == "dir" then
  34.           path = path..fPath[i]
  35.           if not dirs[path] then
  36.             dirs[path] = { "https://raw.github.com/"..user.."/"..repo.."/"..branch.."/"..fPath[i], fName[i] }
  37.             downloadManager(fPath[i], files, dirs)
  38.           end
  39.         end
  40.       end
  41.       return {files=files, dirs=dirs}
  42.     end
  43.  
  44.     local function downloadFile(path, url, name)
  45.       local dirPath = path:gmatch('([%w%_%.% %-%+%,%;%:%*%#%=%/]+)/'..name..'$')()
  46.       if dirPath ~= nil and not fs.isDir(dirPath) then fs.makeDir(dirPath) end
  47.       local content = http.get(url)
  48.       local file = fs.open(path,"w")
  49.       file.write(content.readAll())
  50.       file.close()
  51.     end
  52.  
  53.     local res,err = downloadManager(rpath)
  54.     for i,data in pairs(res.files) do downloadFile(i, table.unpack(data)) end
  55.  
  56.     return true
  57.   end
  58.  
  59.   local res,err = download("FFGFlash", "ReactorOS", "/", nil, "manager-client", true)
  60.   if not res then return print(err) end
  61.   os.reboot()
  62. else
  63.   print("You need to enable the HTTP API!")
  64. end
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement