This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
/
installer.lua
72 lines (61 loc) · 2.11 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
local component = require("component")
local serialization = require("serialization")
local unicode = require("unicode")
local eeprom = component.eeprom
if not component.isAvailable("internet") then
io.stderr:write("This program requires an internet card to run.")
end
local config = ""
local function read()
return io.read() or os.exit()
end
local function QA(text, yesByDefault)
io.write(("%s %s "):format(text, yesByDefault and "[Y/n]" or "[y/N]"))
local data = read()
if unicode.lower(data) == "y" or yesByDefault and data == "" then
return true
end
end
if QA("Create a whitelist?") then
while true do
io.write('Whitelist example: hohserg, fingercomp, Saghetti\nWhitelist: ')
local rawWhitelist, parsedWhitelist, n = read(), "", 0
for substring in rawWhitelist:gmatch("[^%,%s]+") do
parsedWhitelist = parsedWhitelist .. substring .. "|"
n = n + 1
end
if #rawWhitelist > 0 and n > 0 then
config = 'cyan="' .. parsedWhitelist .. (QA("Require user input to boot?") and "+" or "") .. '"'
print(config, #config)
if #config > 64 then
io.stderr:write("Config is too big.\n")
else
break
end
else
io.stderr:write("Malformed string.\n")
end
end
end
local readOnly = QA("Make EEPROM read only?")
os.execute("wget -f https://github.com/BrightYC/Cyan/blob/master/stuff/cyan.bin?raw=true /tmp/cyan.bin")
local file = io.open("/tmp/cyan.bin", "r")
local data = file:read("*a")
file:close()
io.write("Flashing...")
local success, reason = eeprom.set(config .. data)
if not reason then
eeprom.setLabel("Cyan BIOS")
eeprom.setData(require("computer").getBootAddress())
if readOnly then
eeprom.makeReadonly(eeprom.getChecksum())
end
io.write(" success.\n")
if QA("Reboot?", true) then
os.execute("reboot")
end
elseif reason == "storage is readonly" then
io.stderr:write("EEPROM is read only. Please insert a not read-only EEPROM.")
else
io.stderr:write(reason or "Unknown error.")
end