Advertisement
Chickenbreadlp

Installer [ReboOSt]

Mar 25th, 2014
2,196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.22 KB | None | 0 0
  1. local tArgs = {...}
  2. local stream = tArgs[1]
  3.  
  4. local function GitHubGet(branch)
  5.     local branch = branch or nil
  6.     local URL = "https://api.github.com/repos/Chickenbreadlp/ReboOSt/contents/" .. (branch and "?ref=" or "") .. (branch or "")
  7.     local removeLuaExtention = true
  8.    
  9.     function getFileDownloadURLs(url, gatheredFiles, gatheredDirectories)
  10.         assert(url, "url invalid")
  11.         local handle = assert(http.get(url), "Getting " .. url .. " failed")
  12.         local json = assert(handle.readAll(), "Reading failed for url " .. url)
  13.         json = json:gsub("%s*\n%s*", "") --removes white space around '\n' and '\n'
  14.         json = json:gsub("\"([^\"]*)\"%s*:%s*", "%1 = ") --turns '"hi": ' into 'hi = '
  15.         json = json:sub(2, #json - 1) --removes brackets around the almostJSON
  16.         json = "{" .. json .. "}" --adds curly brackets
  17.         local jsonTable = assert(textutils.unserialize(json), "Failed to unserialize:\n" .. json)
  18.         local files = gatheredFiles or {}
  19.         local directories = gatheredDirectories or {}
  20.         for k, v in ipairs(jsonTable) do
  21.             if v.type == "file" then
  22.                 files[#files + 1] = {url = v.download_url, path = v.path}
  23.             elseif v.type == "dir" then
  24.                 directories[#directories + 1] = v.url
  25.             end
  26.         end
  27.         local recursiveURL = directories[1]
  28.         if not recursiveURL then
  29.             return files
  30.         end
  31.         if recursiveURL then
  32.             table.remove(directories, 1)
  33.             return getFileDownloadURLs(recursiveURL, files, directories)
  34.         end
  35.     end
  36.  
  37.     for k, v in ipairs(getFileDownloadURLs(URL)) do
  38.         if (v.path:sub(#v.path - 3) == ".lua") and removeLuaExtention then
  39.             v.path = v.path:sub(1, #v.path - 4)
  40.         end
  41.         local writeFile = fs.open("/" .. v.path, "w")
  42.         local webHandle = assert(http.get(v.url), "Getting " .. v.url .. " failed")
  43.         local webContents = assert(webHandle.readAll(), "Reading " .. v.url .. " failed")
  44.         writeFile.write(webContents)
  45.         writeFile.close()
  46.     end
  47. end
  48.  
  49. local function Set (list)
  50.   local set = {}
  51.   for _, l in ipairs(list) do set[l] = true end
  52.   return set
  53. end
  54.  
  55. local builds = Set { "0011", "0012", "0030", "0031", "0032", "1033", "1010", "1011", "2034", "2035", "3036" }
  56.  
  57. if term.isColor() then
  58.  if stream == nil then
  59.   GitHubGet("installer")
  60.   fs.delete("README.md")
  61.   if fs.exists("/ReboOSt") then
  62.    fs.delete("/Setup")
  63.    shell.run("/Uninst/contrll")
  64.   else
  65.    fs.delete("/Uninst")
  66.    shell.run("/Setup/contrll")
  67.   end
  68.  elseif stream == "Dev" then
  69.   print("Formatting Harddrive...")
  70.   shell.run("rm", "*")
  71.   print("Downloading OS...")
  72.   GitHubGet("development")
  73.   print("Cleaning up...")
  74.   fs.delete("/README.md")
  75.   fs.delete("version")
  76.   fs.delete("updat")
  77.   print("Rebooting...")
  78.   os.reboot()
  79.  elseif builds[stream] then
  80.   print(" Formatting Harddrive...")
  81.   shell.run("rm", "*")
  82.   print("Downloading OS...")
  83.   GitHubGet("build-"..stream)
  84.   print("Cleaning up...")
  85.   fs.delete("/README.md")
  86.   fs.delete("/version")
  87.   fs.delete("/updat")
  88.   print("Rebooting...")
  89.   os.reboot()
  90.  end
  91. else
  92.  print("ReboOSt is only available for Computers with a colored Interface!")
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement