-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.lua
More file actions
116 lines (96 loc) · 2.74 KB
/
install.lua
File metadata and controls
116 lines (96 loc) · 2.74 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
local width, height = term.getSize()
local function update(text)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.setCursorPos(1, 9)
term.clearLine()
term.setCursorPos(math.floor(width / 2 - string.len(text) / 2), 9)
write(text)
end
local function bar(ratio)
term.setBackgroundColor(colors.gray)
term.setTextColor(colors.lime)
term.setCursorPos(1, 11)
for i = 1, width do
if (i / width < ratio) then
write("]")
else
write(" ")
end
end
end
local function download(path)
update("Downloading " .. path .. "...")
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.setCursorPos(1, 13)
term.clearLine()
term.setCursorPos(1, 14)
term.clearLine()
term.setCursorPos(1, 15)
term.clearLine()
term.setCursorPos(1, 16)
term.clearLine()
term.setCursorPos(1, 17)
term.clearLine()
term.setCursorPos(1, 13)
print("Accessing https://raw.githubusercontent.com/WhyKickAmooCow/luamqtt-computercraft/main/" .. path)
local rawData = http.get("https://raw.githubusercontent.com/WhyKickAmooCow/luamqtt-computercraft/main/" .. path)
local data = rawData.readAll()
local file = fs.open(path, "w")
file.write(data)
file.close()
end
function install()
term.setBackgroundColor(colors.black)
term.setTextColor(colors.yellow)
term.clear()
local str = "LuaMQTT:ComputerCraft Installer"
term.setCursorPos(math.floor(width / 2 - #str / 2), 2)
write(str)
local total = 13
update("Installing...")
bar(0)
download("LICENSE")
bar(1 / total)
download("README.md")
bar(2 / total)
update("Creating mqtt folder...")
fs.makeDir("mqtt")
download("mqtt/bitwrap.lua")
bar(3 / total)
download("mqtt/cc_websocket.lua")
bar(4 / total)
download("mqtt/client.lua")
bar(5 / total)
download("mqtt/const.lua")
bar(6 / total)
download("mqtt/init.lua")
bar(7 / total)
download("mqtt/ioloop.lua")
bar(8 / total)
download("mqtt/luasocket.lua")
bar(9 / total)
download("mqtt/protocol.lua")
bar(10 / total)
download("mqtt/protocol4.lua")
bar(11 / total)
download("mqtt/protocol5.lua")
bar(12 / total)
download("mqtt/tools.lua")
bar(13 / total)
update("Creating examples folder...")
fs.makeDir("examples")
download("examples/cc_websocket.lua")
update("Installation finished!")
sleep(1)
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1, 1)
write("Finished installation!\nPress any key to close...")
os.pullEventRaw()
term.clear()
term.setCursorPos(1, 1)
end
install()