Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local stream = tArgs[1]
- local function GitHubGet(branch)
- local branch = branch or nil
- local URL = "https://api.github.com/repos/Chickenbreadlp/ReboOSt/contents/" .. (branch and "?ref=" or "") .. (branch or "")
- local removeLuaExtention = true
- function getFileDownloadURLs(url, gatheredFiles, gatheredDirectories)
- assert(url, "url invalid")
- local handle = assert(http.get(url), "Getting " .. url .. " failed")
- local json = assert(handle.readAll(), "Reading failed for url " .. url)
- json = json:gsub("%s*\n%s*", "") --removes white space around '\n' and '\n'
- json = json:gsub("\"([^\"]*)\"%s*:%s*", "%1 = ") --turns '"hi": ' into 'hi = '
- json = json:sub(2, #json - 1) --removes brackets around the almostJSON
- json = "{" .. json .. "}" --adds curly brackets
- local jsonTable = assert(textutils.unserialize(json), "Failed to unserialize:\n" .. json)
- local files = gatheredFiles or {}
- local directories = gatheredDirectories or {}
- for k, v in ipairs(jsonTable) do
- if v.type == "file" then
- files[#files + 1] = {url = v.download_url, path = v.path}
- elseif v.type == "dir" then
- directories[#directories + 1] = v.url
- end
- end
- local recursiveURL = directories[1]
- if not recursiveURL then
- return files
- end
- if recursiveURL then
- table.remove(directories, 1)
- return getFileDownloadURLs(recursiveURL, files, directories)
- end
- end
- for k, v in ipairs(getFileDownloadURLs(URL)) do
- if (v.path:sub(#v.path - 3) == ".lua") and removeLuaExtention then
- v.path = v.path:sub(1, #v.path - 4)
- end
- local writeFile = fs.open("/" .. v.path, "w")
- local webHandle = assert(http.get(v.url), "Getting " .. v.url .. " failed")
- local webContents = assert(webHandle.readAll(), "Reading " .. v.url .. " failed")
- writeFile.write(webContents)
- writeFile.close()
- end
- end
- local function Set (list)
- local set = {}
- for _, l in ipairs(list) do set[l] = true end
- return set
- end
- local builds = Set { "0011", "0012", "0030", "0031", "0032", "1033", "1010", "1011", "2034", "2035", "3036" }
- if term.isColor() then
- if stream == nil then
- GitHubGet("installer")
- fs.delete("README.md")
- if fs.exists("/ReboOSt") then
- fs.delete("/Setup")
- shell.run("/Uninst/contrll")
- else
- fs.delete("/Uninst")
- shell.run("/Setup/contrll")
- end
- elseif stream == "Dev" then
- print("Formatting Harddrive...")
- shell.run("rm", "*")
- print("Downloading OS...")
- GitHubGet("development")
- print("Cleaning up...")
- fs.delete("/README.md")
- fs.delete("version")
- fs.delete("updat")
- print("Rebooting...")
- os.reboot()
- elseif builds[stream] then
- print(" Formatting Harddrive...")
- shell.run("rm", "*")
- print("Downloading OS...")
- GitHubGet("build-"..stream)
- print("Cleaning up...")
- fs.delete("/README.md")
- fs.delete("/version")
- fs.delete("/updat")
- print("Rebooting...")
- os.reboot()
- end
- else
- print("ReboOSt is only available for Computers with a colored Interface!")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement