-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.lua
70 lines (60 loc) · 1.55 KB
/
install.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
local v = require("cc.expect")
local ghBase = "https://raw.githubusercontent.com/"
local coreRepo = "AngellusMortis/cc-updater"
local ref = "v3"
local baseUrl = ghBase .. coreRepo .. "/" .. ref .. "/src/"
local requiredFiles = {
"apis/am/core.lua",
"apis/ghu.lua",
"programs/ghuupdate.lua"
}
local function getAndCheck(url)
v.expect(1, url, "string")
url = url .. "?ts=" .. os.time(os.date("!*t"))
local r = http.get(url)
if r == nil then
error(string.format("Bad HTTP Response: %s", url))
end
local rc, _ = r.getResponseCode()
if rc ~= 200 then
error(string.format("Bad HTTP code: %d", rc))
end
return r
end
local function download(url, path)
v.expect(1, url, "string")
v.expect(2, path, "string")
if (fs.exists(path)) then
fs.delete(path)
end
local r = getAndCheck(url)
local f = fs.open(path, 'w')
f.write(r.readAll())
f.close()
end
local function main(root)
if root == nil then
root = "/"
end
v.expect(1, root, "string")
local basePath = root .. "ghu/"
for _, file in ipairs(requiredFiles) do
download(
baseUrl .. file,
basePath .. "core/" .. file
)
end
settings.set("ghu.base", basePath)
settings.set("ghu.coreRepo", coreRepo .. "@" .. ref)
settings.save()
if shell.run(basePath .. "core/programs/ghuupdate.lua") then
print("Install complete")
else
error("Error installing")
end
end
local root = arg[1]
if root == "run" then
root = arg[3]
end
main(root)