-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstartup.lua
More file actions
229 lines (219 loc) · 6.09 KB
/
startup.lua
File metadata and controls
229 lines (219 loc) · 6.09 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
if not term.isColor() then
printError("Please use a color terminal.")
return false
end
term.clear()
term.setCursorPos(1, 1)
--Install to PC if inserted into disk drive.
if fs.exists("disk/startup.lua") and fs.exists("disk/sys/ver.txt") then
if fs.exists("startup.lua") then
term.setTextColor(colors.red)
print("NodeOS cannot be installed on this system. A Startup file already exists!")
term.setTextColor(colors.lightGray)
print("Press enter to reboot.")
read("")
peripheral.find("drive", function(_, drive) drive.ejectDisk() end)
os.reboot()
else
fs.copy("disk/startup.lua", "startup.lua")
fs.copy("disk/bin", "bin")
fs.copy("disk/sys", "sys")
fs.copy("disk/lib", "lib")
term.setTextColor(colors.green)
print("NodeOS succesfully installed from disk!")
os.sleep(2)
peripheral.find("drive", function(_, drive) drive.ejectDisk() end)
os.reboot()
end
end
term.clear()
term.setCursorPos(1, 1)
if fs.exists("/disk/startup") or fs.exists("/disk/startup.lua") then
write("Press any key to boot from disk")
parallel.waitForAny(function()
os.pullEvent("char")
if fs.exists("/disk/startup") then
shell.run('/disk/startup')
elseif fs.exists("/disk/startup.lua") then
shell.run('/disk/startup')
else
print("\nFailed to boot to disk. Is the disk still inserted?")
sleep(1)
end
end, function()
for i = 1, 3 do
write(".")
sleep(1)
end
end)
end
if fs.exists("tmp") then
fs.delete("tmp")
end
fs.makeDir("tmp")
if not fs.exists("home") then
fs.makeDir("home")
end
if not fs.exists("home/bin") then
fs.makeDir("home/bin")
end
if not fs.exists("/home/services") then
fs.makeDir("/home/services")
end
if not fs.exists("/home/drivers") then
fs.makeDir("/home/drivers")
end
if not fs.exists("/home/startup") then
fs.makeDir("/home/startup")
end
if not fs.exists("home/Documents") then
fs.makeDir("home/Documents")
end
if not fs.exists("home/Downloads") then
fs.makeDir("home/Downloads")
end
if not fs.exists("home/Pictures") then
fs.makeDir("home/Pictures")
end
if not fs.exists("home/Music") then
fs.makeDir("home/Music")
end
if not fs.exists("home/Public") then
fs.makeDir("home/Public")
end
if not fs.exists("/etc/menu/pinned.cfg") then
local file = fs.open("/etc/menu/pinned.cfg", "w")
file.write(textutils.serialize({
{
path = "/bin/map.lua",
title = "Map",
insettings = {
height = 17,
title = "Map",
width = 40,
},
},
{
path = "bin/logs.lua",
title = "Logs",
insettings = {
height = 17,
title = "Logs",
width = 40,
},
},
{
path = "sys/shell.lua",
title = "Shell",
insettings = {
height = 17,
title = "Logs",
width = 40,
},
}
}))
file.close()
end
if not fs.exists("/etc/paths.cfg") then
local file = fs.open("/etc/paths.cfg", "w")
file.write(textutils.serialize({
"/home/bin",
"/bin"
}))
file.close()
end
if not fs.exists("/etc/libs.cfg") then
local file = fs.open("/etc/libs.cfg", "w")
file.write(textutils.serialize({
"/lib/?.lua",
"/lib/?/init.lua"
}))
file.close()
end
if not fs.exists("/etc/theme.cfg") then
local file = fs.open("/etc/theme.cfg", "w")
file.write(textutils.serialize({
currentTheme = "/sys/themes/dark.theme",
}))
file.close()
end
local fakenodeos = {}
local smodule = require("/sys/modules/settings")
smodule.init(fakenodeos) -- Initialize settings module outside of kernel
local settings = fakenodeos.settings
term.clear()
local completeSetupPassword = false
while not completeSetupPassword do
if not settings.settings.password then
print("Please input a password:")
print("Typing nothing will not set a password.")
local sha256 = require("/lib/sha256")
settings.settings.password = read("*")
if settings.settings.password ~= "" then
print("Please confirm your password:")
local pass2 = read("*")
if pass2 == settings.settings.password then
settings.settings.password = sha256(settings.settings.password)
completeSetupPassword = true
else
print("Passwords do not match!")
settings.settings.password = nil
end
end
else
completeSetupPassword = true
end
end
while not os.getComputerLabel() do
print("Please input a computer name:")
os.setComputerLabel(read())
end
while not settings.settings.pin do
print("Please input a SECURE pairing pin:")
settings.settings.pin = read("*")
end
while settings.settings.consoleOnly == nil do
print("Will this computer be console only? (y/n)")
instr = string.lower(read())
if instr == "y" then
settings.settings.consoleOnly = true
elseif instr == "n" then
settings.settings.consoleOnly = false
end
end
term.clear()
settings.saveSettings(settings.settings)
local w, h = term.getSize()
local fail = false
function yield()
os.queueEvent("randomEvent")
os.pullEvent("randomEvent")
end
term.setBackgroundColor(colors.black)
term.clear()
-- Function DeviceDetect
function detectDevice(DeviceName)
local DeviceSide = nil
for k, v in pairs(redstone.getSides()) do
if peripheral.getType(v) == DeviceName then
DeviceSide = v
break
end
end
return DeviceSide
end
-- Usage:
local MonitorSide = detectDevice("monitor")
if MonitorSide then
local monitor = peripheral.wrap(MonitorSide)
monitor.setTextScale(0.5)
term.clear()
print("Please use this console for input:")
shell.run(
"monitor " .. MonitorSide .. " /sys/kernel.lua"
)
else
shell.run(
"/sys/kernel.lua"
)
end