-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.lua
More file actions
101 lines (90 loc) · 2.4 KB
/
Copy pathinstaller.lua
File metadata and controls
101 lines (90 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
local files = {
}
local githubUser = ""
local githubRepo = ""
local githubBranch = ""
local installerName = nil -- if you need one, this will replace "Installer for user/repo, branch branch"
local function clear()
term.clear()
term.setCursorPos(1, 1)
end
local function httpGet(url, save)
if not url then
error("not enough arguments, expected 1 or 2", 2)
end
local remote = http.get(url)
if not remote then
return false
end
local text = remote.readAll()
remote.close()
if save then
local file = fs.open(save, "w")
file.write(text)
file.close()
return true
end
return text
end
local function get(user, repo, bran, path, save)
if not user or not repo or not bran or not path then
error("not enough arguments, expected 4 or 5", 2)
end
local url = "https://raw.github.com/"..user.."/"..repo.."/"..bran.."/"..path
local remote = http.get(url)
if not remote then
return false
end
local text = remote.readAll()
remote.close()
if save then
local file = fs.open(save, "w")
file.write(text)
file.close()
return true
end
return text
end
local function getFile(file, target)
return get(githubUser, githubRepo, githubBranch, file, target)
end
shell.setDir("")
clear()
print(installerName or ("Installer for " .. githubUser .. "/" .. githubRepo .. ", branch " .. githubBranch))
print("Getting files...")
local fileCount = 0
for _ in pairs(files) do
fileCount = fileCount + 1
end
local filesDownloaded = 0
local w, h = term.getSize()
for k, v in pairs(files) do
term.setTextColor(colors.black)
term.setBackgroundColor(colors.white)
clear()
term.setCursorPos(2, 2)
print(installerName or ("Installer for " .. githubUser .. "/" .. githubRepo .. ", branch " .. githubBranch))
term.setCursorPos(2, 4)
print("File: "..v)
term.setCursorPos(2, h - 1)
print(tostring(math.floor(filesDownloaded / fileCount * 100)).."% - "..tostring(filesDownloaded + 1).."/"..tostring(fileCount))
local ok = k:sub(1, 4) == "ext:" and httpGet(k:sub(5), v) or getFile(k, v)
if not ok then
if term.isColor() then
term.setTextColor(colors.red)
end
term.setCursorPos(2, 6)
print("Error getting file:")
term.setCursorPos(2, 7)
print(k)
sleep(1)
end
filesDownloaded = filesDownloaded + 1
end
clear()
term.setCursorPos(2, 2)
print("Press any key to continue.")
local w, h = term.getSize()
term.setCursorPos(2, h-1)
print("100% - "..tostring(filesDownloaded).."/"..tostring(fileCount))
os.pullEvent("key")