Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function drawProgBar(done, max)
- local value = done / max
- local _, y = term.getCursorPos()
- local wide, _ = term.getSize()
- term.setCursorPos(1,y)
- term.clearLine()
- term.write(("="):rep(math.floor(value * (wide - 6))))
- term.setCursorPos(math.floor(value * (wide - 6)), y)
- term.write(">")
- term.setCursorPos(wide - 6, y)
- term.write("]")
- term.setCursorPos(1, y)
- term.write("[")
- term.setCursorPos(wide - 5, y)
- term.write(" ")
- local percent = math.floor(value * 100) .. "%"
- term.setCursorPos(wide - percent:len(),y)
- term.write(percent)
- end
- local function extractRepository(cpfDir, destDir)
- print("Constructing project...")
- local file = io.open(cpfDir, "r")
- local cFile = nil
- local lc = 0
- local total = 0
- local ox,oy = term.getCursorPos()
- for line in file:lines() do
- if lc > 0 then
- cFile:write(line.."\n")
- lc = lc-1
- term.clearLine()
- term.setCursorPos(ox,oy)
- if lc == 0 then
- cFile:close()
- drawProgBar(total-lc, total)
- print()
- print("File write complete.")
- else
- drawProgBar(total-lc, total)
- end
- elseif string.find(line, "MKDIR") == 1 then
- local newDirPath = destDir.."/"..string.sub(line, 7)
- if fs.exists(newDirPath) then fs.delete(newDirPath) end
- fs.makeDir(newDirPath)
- print("Created dir "..newDirPath)
- elseif string.find(line, "MKFIL") == 1 then
- local newFilPath = destDir.."/"..string.sub(line, 7)
- if fs.exists(newFilPath) then fs.delete(newFilPath) end
- cFile = io.open(newFilPath, "w")
- print("Created file "..newFilPath)
- ox,oy = term.getCursorPos()
- elseif string.find(line, "WRITE") == 1 then
- lc = tonumber(string.sub(line, 7))
- total = lc
- end
- sleep(0)
- end
- print("Project constructed.")
- end
- local lpath = "/"
- local repoCode = "Pht0fFEU"
- if fs.exists(lpath .. "startup.lua") then
- print(lpath.." already exists. Rename or use another directory to install.")
- return
- end
- print("iGP OS Installer")
- print("Beta version 1.x.x")
- print("\nInstalling to the following directory:")
- term.setTextColour(colours.yellow)
- print(" "..lpath.."\n")
- term.setTextColour(colours.white)
- term.write("Ready to install? Y/N: ")
- while true do
- local _,p1 = os.pullEvent("key")
- if p1 == keys.y then
- term.setTextColour(colours.lime)
- print("Y\n")
- break
- elseif p1 == keys.n then
- term.setTextColour(colours.red)
- print("N\n")
- os.pullEvent()
- return
- end
- end
- term.setTextColour(colours.white)
- print("Downloading "..repoCode.."... ")
- if not shell.run("pastebin", "get", repoCode, "glrepo") then
- term.setTextColour(colours.red)
- print("failed!")
- return
- end
- extractRepository(shell.resolve(".").."/glrepo", shell.resolve("."))
- print("Deleting archive...")
- fs.delete(shell.resolve(".").."/glrepo")
- print("Installation complete!")
Add Comment
Please, Sign In to add comment