Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local repoUrl = "https://raw.githubusercontent.com/eniallator/L-system-Computercraft/master/"
- local filesToInstall = {}
- local fileListUrl = "install/filesToInstall"
- if not http then
- printError("http needs to be enabled.")
- return
- end
- local fileListHandle = http.get(repoUrl .. fileListUrl)
- local line = fileListHandle.readLine()
- local existingFiles = {}
- local installPaths = {}
- while line do
- local pathString = ""
- local finalPath = ""
- for word in line:gmatch("[^/]+") do
- pathString = pathString == "" and word or pathString .. "/" .. word
- table.insert(installPaths, {pathString, pathString == line and "file" or "folder"})
- if fs.exists(pathString) then
- finalPath = pathString
- end
- end
- if #finalPath > 0 then
- table.insert(existingFiles, finalPath)
- end
- table.insert(filesToInstall, line)
- line = fileListHandle.readLine()
- end
- fileListHandle.close()
- print("Found install files.")
- if existingFiles[1] then
- print("The following paths already exist:")
- for i=1, #existingFiles do
- print(existingFiles[i])
- end
- print("Force install?")
- local ans
- repeat
- term.write("(y/n): ")
- ans = read():lower()
- until ans == "y" or ans == "n"
- if ans == "n" then
- print("Exiting installer.")
- return
- end
- end
- for i=1, #installPaths do
- if not fs.exists(installPaths[i][1]) and installPaths[i][2] == "folder" then
- fs.makeDir(installPaths[i][1])
- end
- end
- for i=1, #filesToInstall do
- local currFile = filesToInstall[i]
- local githubHandle = http.get(repoUrl .. currFile)
- if not githubHandle then
- printError("Stuck at " .. currFile .. " please report to https://github.com/eniallator/L-system-Computercraft/issues")
- return
- end
- local currFileContents = githubHandle.readAll()
- githubHandle.close()
- local locFileHandle = fs.open(currFile, "w")
- locFileHandle.write(currFileContents)
- locFileHandle.close()
- print("Got: " .. currFile)
- end
Advertisement
Add Comment
Please, Sign In to add comment