forked from Kolpa/cc-update-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magnificant auto updater.lua
104 lines (82 loc) · 2.17 KB
/
magnificant auto updater.lua
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
102
103
104
function loadscreen(parts,done,text)
clearscreen()
print(text.."\n")
local size = 48 / parts
write("[")
local steps = size * done
local rest = 48 - steps
for x=1,steps do
write("-")
end
for y=1,rest do
write(" ")
end
write("]\n")
end
function tblc(st,tb)
if tb == nil then
return false
else
for x=1,#tb do
if tb[x] == st then return true end
end
return false
end
end
function clearscreen()
term.clear()
term.setCursorPos(1,1)
end
loadscreen(2,0,"Welcome to the CommuteOS Installer loading now ... \n\n")
local dec = http.get("http://regex.info/code/JSON.lua")
local JSON = loadstring(dec:readAll())()
loadscreen(2,1,"Welcome to the CommuteOS Installer loading now ... \n\n")
local repo = http.get("https://api.github.com/repos/CommuteOS/CommuteOS/contents")
local raw = JSON:decode(repo:readAll())
loadscreen(2,2,"Welcome to the CommuteOS Installer loading now ... \n\n")
clearscreen()
loadscreen(3,0,"Prepearing Data ... \n\n")
local dirs = {}
local y = 1
local files = {}
local filename = {}
for x=1,#raw do
if raw[x].type == "dir" then
table.insert(dirs,raw[x]._links.self)
end
end
loadscreen(3,1,"Prepearing Data ... \n\n")
while y <= #dirs do
local teme = http.get(dirs[y])
local data = JSON:decode(teme:readAll())
for z=1,#data do
if data[z].type == "dir" then
table.insert(dirs,data[z]._links.self)
end
end
y=y+1
end
table.insert(dirs,"https://api.github.com/repos/CommuteOS/CommuteOS/contents")
loadscreen(3,2,"Prepearing Data ... \n\n")
for w=1,#dirs do
local teme2 = http.get(dirs[w])
local data2 = JSON:decode(teme2:readAll())
for v=1,#data2 do
if data2[v].type == "file" then
local url = data2[v]._links.html:gsub("blob","raw")
table.insert(files,url)
table.insert(filename,data2[v].name)
end
end
end
fs.makeDir("Download")
loadscreen(3,3,"Prepearing Data ... \n\n")
loadscreen(#files,0,"Downloading files ... \n\n")
for u=1,#files do
local fname = filename[u]
local filex = http.get(files[u]):readAll()
local file = fs.open("Download/"..fname,"w")
file.write(filex)
file.close()
loadscreen(#files,u,"Downloading files ... \n\n")
end