This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
installer.lua
96 lines (78 loc) · 2.53 KB
/
installer.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
--[[
_ _ _ ____ ___ ____ _ _ ____ ____
| |\ | [__ | |__| | | |___ |__/
| | \| ___] | | | |___ |___ |___ | \
Github Repository: https://github.com/Commandcracker/YouCube
License: GPL-3.0
]]
-- OpenInstaller v1.0.0 (based on wget)
local BASE_URL = "https://raw.githubusercontent.com/Commandcracker/YouCube/main/client/"
local files = {
["./youcube.lua"] = BASE_URL .. "youcube.lua",
["./lib/youcubeapi.lua"] = BASE_URL .. "lib/youcubeapi.lua",
["./lib/numberformatter.lua"] = BASE_URL .. "lib/numberformatter.lua",
["./lib/semver.lua"] = BASE_URL .. "lib/semver.lua",
["./lib/argparse.lua"] = BASE_URL .. "lib/argparse.lua",
["./lib/string_pack.lua"] = BASE_URL .. "lib/string_pack.lua"
}
if not http then
printError("OpenInstaller requires the http API")
printError("Set http.enabled to true in the ComputerCraft config")
return
end
local function question(_question)
term.setTextColour(colors.orange)
term.write(_question .. "? [")
term.setTextColour(colors.lime)
term.write('Y')
term.setTextColour(colors.orange)
term.write('/')
term.setTextColour(colors.red)
term.write('n')
term.setTextColour(colors.orange)
term.write("] ")
term.setTextColour(colors.white)
local input = string.lower(string.sub(read(), 1, 1))
if input == 'y' or input == 'j' or input == '' then
return true
else
return false
end
end
local function get(sUrl)
-- Check if the URL is valid
local ok, err = http.checkURL(sUrl)
if not ok then
printError("\"" .. sUrl .. "\" ", err or "Invalid URL.")
return
end
--term.setTextColour(colors.lightGray)
--write("Connecting to " .. sUrl .. "... ")
local response, http_err = http.get(sUrl, nil, true)
if not response then
printError("Failed to download \"" .. sUrl .. "\" (" .. http_err .. ")")
return nil
end
local sResponse = response.readAll()
response.close()
return sResponse or ""
end
for path, dl_link in pairs(files) do
local sPath = shell.resolve(path)
if fs.exists(sPath) then
if not question("\"" .. path .. "\" already exists. Override") then
return
end
end
local res = get(dl_link)
if not res then return end
local file, err = fs.open(sPath, "wb")
if not file then
printError("Failed to save \"" .. path .. "\" (" .. err .. ")")
return
end
file.write(res)
file.close()
term.setTextColour(colors.lime)
print("Downloaded \"" .. path .. "\"")
end