This repository was archived by the owner on Dec 19, 2020. It is now read-only.
forked from Forte40/openbee
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopenbee-install.lua
81 lines (71 loc) · 2.46 KB
/
openbee-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
71
72
73
74
75
76
77
78
79
80
81
--- Second_Fry's openbee modular fork (v2.0.0)
--- Original code and idea by Forte40 @ GitHub (forked at v2.2.1)
--- Hosted at http://pastebin.com/XxjND24H
local branch = 'master'
local url = 'https://raw.github.com/secondfry/openbee/' .. branch .. '/'
local filenames = {'openbee-install.lua', 'openbee.lua', 'matron.lua', 'openbee/BreederApiary.lua', 'openbee/StorageAE.lua', 'README.md'}
local folders = {'openbee'}
term.setTextColor(colors.green)
io.write('> Installing openbee\n')
term.setTextColor(colors.white)
if not http then error('No access to web') end
term.setTextColor(colors.lightBlue)
io.write(' Installing folders\n')
term.setTextColor(colors.white)
for _, folder in ipairs(folders) do
io.write(' ' .. folder .. '\n')
fs.makeDir(folder)
end
term.setTextColor(colors.lightBlue)
io.write(' Installing files\n')
term.setTextColor(colors.white)
for _, filename in ipairs(filenames) do
io.write(' ' .. filename .. ': ')
local data, dataCurrent = '', ''
if fs.exists(filename) then
local file = fs.open(filename, "r")
dataCurrent = file.readAll()
file.close()
io.write('updating')
else
io.write('installing')
end
local request = http.get(url .. filename)
if request == nil then error(' Request failed') end
if request.getResponseCode() == 200 then
data = request.readAll()
if data == dataCurrent then
term.setTextColor(colors.gray)
io.write(' same file\n')
term.setTextColor(colors.white)
elseif dataCurrent == '' then
local file = fs.open(filename, "w")
file.write(data)
file.close()
term.setTextColor(colors.gray)
io.write(' success\n')
term.setTextColor(colors.white)
else
-- TODO implement coroutines
if filename == 'openbee-install.lua' then
filename = '.' .. filename
end
local file = fs.open(filename, "w")
file.write(data)
file.close()
term.setTextColor(colors.gray)
io.write(' success\n')
term.setTextColor(colors.white)
if filename == '.openbee-install.lua' then
term.setTextColor(colors.yellow)
io.write(' Install file updated, manual user console inputs required:\nmove .openbee-install.lua openbee-install.lua\nopenbee-install.lua\n')
term.setTextColor(colors.white)
return
end
end
else error(' Bad HTTP response code') end
os.sleep(0.1)
end
term.setTextColor(colors.green)
io.write('> Installation successful\n')
term.setTextColor(colors.white)