-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetinstall.lua
More file actions
516 lines (474 loc) · 11.2 KB
/
netinstall.lua
File metadata and controls
516 lines (474 loc) · 11.2 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
-- CloverOS network installer
local ogTerm = term.current()
local termX, termY = term.getSize()
local bufferWindow = window.create(ogTerm, 1, 1, termX, termY)
function menuOptions(title, tChoices, tActions)
local check = true
local nSelection = 1
repeat
bufferWindow.setVisible(false)
term.redirect(bufferWindow)
term.clear()
local width, height = term.getSize()
paintutils.drawLine(1, 1, width, 1, colors.gray)
term.setCursorPos(1, 1)
term.setBackgroundColor(colors.gray)
print(title)
term.setBackgroundColor(colors.black)
print("")
for nLine = 1, #tChoices do
if nSelection == nLine then
term.setTextColor(colors.lightGray)
print("> " .. tChoices[nLine])
term.setTextColor(colors.white)
else
print(" " .. tChoices[nLine])
end
end
bufferWindow.setVisible(true)
local sEvent, nKey = os.pullEvent("key")
if nKey == keys.up or nKey == keys.w then
if tChoices[nSelection - 1] then
nSelection = nSelection - 1
end
elseif nKey == keys.down or nKey == keys.s then
if tChoices[nSelection + 1] then
nSelection = nSelection + 1
end
elseif nKey == keys.enter then
if tActions[nSelection] then
tActions[nSelection]()
check = false
end
end
until check == false
end
local dumpWindow = window.create(term.current(), 1, 1, 1, 1, false)
function disableoutput()
ogTerm = term.current()
term.redirect(dumpWindow)
return ogTerm
end
function enableoutput(ogTerm)
term.redirect(ogTerm)
end
local envType = nil
menuOptions("Select your OS environment", { "CC:Tweaked", "CraftOS" }, {
function()
envType = "cct"
end,
function()
envType = "craftos"
end,
})
if envType == "craftos" then
print("Setting up CraftOS environment...")
pcall(function()
shell.run("attach left drive")
shell.run("attach right speaker")
shell.run("attach back monitor")
if mounter and mounter.mount then
mounter.mount("/CloverOS_Disks/0", "C:\\CloverOS_Disks\\0")
end
if disk and disk.insertDisk then
disk.insertDisk("left", "C:\\CloverOS_Disks\\0")
end
end)
print("Environment setup complete.")
sleep(5)
end
settings.set("envType", envType)
local githubPagesBaseURL = "https://endpoint.palorderhosting.net/"
local rawBaseURL = "https://raw.githubusercontent.com/PalorderSoftWorksOfficial/CloverOS/main/"
local manifestURL_Pages = githubPagesBaseURL .. "files.manifest"
local manifestURL_Raw = "https://raw.githubusercontent.com/PalorderSoftWorksOfficial/CloverOS/main/files.manifest"
local function listMounts()
local mounts = {
{ name = "computer (root)", path = "/" },
}
for _, mount in ipairs(fs.list("/")) do
local path = "/" .. mount
if fs.isDir(path) and mount:match("^disk%d*$") and mount ~= "rom" then
table.insert(mounts, { name = mount, path = path })
end
end
return mounts
end
local disks = listMounts()
if #disks == 0 then
print("No disks detected! Insert one and reboot.")
return
end
local choices = {}
local actions = {}
local selectedDisk = nil
for i, d in ipairs(disks) do
table.insert(choices, d.name)
actions[i] = function()
selectedDisk = d
end
end
menuOptions("Select target disk", choices, actions)
if not selectedDisk then
print("No disk selected. Aborting.")
return
end
print("Selected disk: " .. selectedDisk.name .. " (" .. selectedDisk.path .. ")")
local sourceChoice = nil
local baseURL = nil
local manifestURL = nil
menuOptions("Select source server", { "CDN (recommended)", "Raw GitHub" }, {
function()
baseURL = githubPagesBaseURL
manifestURL = manifestURL_Pages
sourceChoice = "pages"
end,
function()
baseURL = rawBaseURL
manifestURL = manifestURL_Raw
sourceChoice = "raw"
end,
})
local edition = nil
menuOptions("Select CloverOS edition", {
"default (Recommended)",
"soft (Recommended for low storage installs or lightweight.)",
"turtle (Recommended for turtles)",
"emulator (Recommended edition for Emulated CC: Tweaked computers)",
}, {
function()
edition = "default"
end,
function()
edition = "soft"
end,
function()
edition = "turtle"
end,
function()
edition = "emulator"
end,
})
local installMode = nil
menuOptions("Installation Mode", { "Install", "Reinstall" }, {
function()
installMode = "install"
end,
function()
installMode = "reinstall"
end,
})
-- Advanced Settings
local theme = nil
menuOptions("Select Theme", { "Default (Black/White)", "Dark (Black/Gray)", "Light (White/Black)", "Colorful" }, {
function()
theme = "default"
end,
function()
theme = "dark"
end,
function()
theme = "light"
end,
function()
theme = "colorful"
end,
})
local autoLogin = nil
menuOptions("Enable Auto-Login?", { "Yes", "No" }, {
function()
autoLogin = true
end,
function()
autoLogin = false
end,
})
local soundEnabled = nil
menuOptions("Enable Sound Effects?", { "Yes", "No" }, {
function()
soundEnabled = true
end,
function()
soundEnabled = false
end,
})
local performanceMode = nil
menuOptions("Performance Mode", { "Standard", "Low (Reduced Animations)" }, {
function()
performanceMode = "standard"
end,
function()
performanceMode = "low"
end,
})
local fileList = {}
if edition == "default" then
local manifestPath = selectedDisk.path .. "/files.manifest"
shell.run("wget " .. manifestURL .. " " .. manifestPath)
if not fs.exists(manifestPath) then
print("Failed to download manifest. Aborting.")
return
end
local f = fs.open(manifestPath, "r")
if f then
local line = f.readLine()
while line do
table.insert(fileList, line)
line = f.readLine()
end
f.close()
for i, v in ipairs(fileList) do
if v == "netinstall.lua" then
table.remove(fileList, i)
break
end
end
settings.set("softinstall", false)
else
print("Failed to read manifest. Aborting.")
return
end
settings.set("default", true)
settings.set("emulator", false)
settings.set("turtle", false)
elseif edition == "soft" then
table.insert(fileList, "boot/kernel.lua")
table.insert(fileList, "CloverOS_OS.lua")
for i, v in ipairs(fileList) do
if v == "netinstall.lua" then
table.remove(fileList, i)
break
end
end
local basicCommands = {
"bin/run.exe",
"bin/cd.exe",
"bin/cls.exe",
"bin/dir.exe",
"bin/del.exe",
"bin/copy.exe",
"bin/move.exe",
"bin/ren.exe",
"bin/mkdir.exe",
"bin/rmdir.exe",
"bin/type.exe",
"bin/man.exe",
"bin/makeboot.exe",
"bin/peripherals.exe",
"bin/eject.exe",
"bin/label.exe",
"bin/edit.exe",
"bin/drive.exe",
"bin/apt.exe",
}
local components = {
"startup.lua",
"LICENSE",
"instructions.txt",
}
local manFiles = {
"etc/man/cd.man",
"etc/man/cls.man",
"etc/man/dir.man",
"etc/man/del.man",
"etc/man/copy.man",
"etc/man/move.man",
"etc/man/ren.man",
"etc/man/mkdir.man",
"etc/man/rmdir.man",
"etc/man/type.man",
"etc/man/man.man",
}
for _, file in ipairs(basicCommands) do
table.insert(fileList, file)
end
for _, man in ipairs(manFiles) do
table.insert(fileList, man)
end
for _, components in ipairs(components) do
table.insert(fileList, components)
end
settings.set("softinstall", true)
settings.set("emulator", false)
settings.set("default", false)
elseif edition == "turtle" then
table.insert(fileList, "CloverOS_OS.lua")
table.insert(fileList, "boot/kernel.lua")
for i, v in ipairs(fileList) do
if v == "netinstall.lua" then
table.remove(fileList, i)
break
end
end
local basicCommands = {
"bin/run.exe",
"bin/cd.exe",
"bin/cls.exe",
"bin/dir.exe",
"bin/del.exe",
"bin/copy.exe",
"bin/move.exe",
"bin/ren.exe",
"bin/mkdir.exe",
"bin/rmdir.exe",
"bin/type.exe",
"bin/man.exe",
"bin/makeboot.exe",
"bin/peripherals.exe",
"bin/eject.exe",
"bin/label.exe",
"bin/edit.exe",
"bin/drive.exe",
"bin/apt.exe",
}
local components = {
"startup.lua",
"LICENSE",
"instructions.txt",
"etc/apt/packages/rturtle/rturtle.exe",
"etc/apt/packages/rturtle/package.json",
"etc/apt/packages/rturtle/turtlelib.exe",
"etc/apt/packages/autominer/package.json",
"etc/apt/packages/autominer/autominer.exe",
}
local manFiles = {
"etc/man/cd.man",
"etc/man/cls.man",
"etc/man/dir.man",
"etc/man/del.man",
"etc/man/copy.man",
"etc/man/move.man",
"etc/man/ren.man",
"etc/man/mkdir.man",
"etc/man/rmdir.man",
"etc/man/type.man",
"etc/man/man.man",
}
for _, file in ipairs(basicCommands) do
table.insert(fileList, file)
end
for _, man in ipairs(manFiles) do
table.insert(fileList, man)
end
for _, components in ipairs(components) do
table.insert(fileList, components)
end
settings.set("turtle", true)
settings.set("default", false)
settings.set("softinstall", false)
elseif edition == "emulator" then
local manifestPath = selectedDisk.path .. "/files.manifest"
shell.run("wget " .. manifestURL .. " " .. manifestPath)
if not fs.exists(manifestPath) then
print("Failed to download manifest. Aborting.")
return
end
local f = fs.open(manifestPath, "r")
if f then
local line = f.readLine()
while line do
table.insert(fileList, line)
line = f.readLine()
end
f.close()
for i, v in ipairs(fileList) do
if v == "netinstall.lua" then
table.remove(fileList, i)
break
end
end
else
print("Failed to read manifest. Aborting.")
return
end
settings.set("softinstall", false)
settings.set("emulator", true)
settings.set("default", false)
end
local MAX_CONCURRENT = 16
local createdDirs = {}
local queue = {}
for _, file in ipairs(fileList) do
local target = selectedDisk.path .. "/" .. file
if not (fs.exists(target) and installMode == "install") then
table.insert(queue, file)
else
print("Skipping existing " .. file)
end
end
local active = {}
local running = 0
local function ensureDir(file)
local dir = file:match("(.*/)")
if dir and not createdDirs[dir] then
fs.makeDir(selectedDisk.path .. "/" .. dir)
createdDirs[dir] = true
end
end
local function startNext()
if #queue == 0 then
return
end
if running >= MAX_CONCURRENT then
return
end
local file = table.remove(queue, 1)
local url = baseURL .. file
print("Downloading " .. file)
http.request(url)
active[url] = file
running = running + 1
end
for i = 1, MAX_CONCURRENT do
startNext()
end
while running > 0 do
local event, url, handle = os.pullEvent()
if event == "http_success" and active[url] then
local file = active[url]
local target = selectedDisk.path .. "/" .. file
ensureDir(file)
local content = handle.readAll()
handle.close()
local f = fs.open(target, "wb")
f.write(content)
f.close()
active[url] = nil
running = running - 1
startNext()
elseif event == "http_failure" and active[url] then
print("Failed: " .. active[url])
active[url] = nil
running = running - 1
startNext()
end
end
print(
"CloverOS "
.. (installMode == "reinstall" and "reinstalled" or "installed")
.. " successfully to "
.. selectedDisk.path
)
sleep(1)
local minuxChoice = nil
menuOptions("Do you also want to install Minux OS? CloverOS is inspired by it.", { "Yes", "No" }, {
function()
minuxChoice = true
end,
function()
minuxChoice = false
end,
})
if minuxChoice then
print("Launching Minux OS installer...")
shell.run("wget https://minux.cc/netinstall /tmp/minux_netinstall.lua")
shell.run("/tmp/minux_netinstall.lua")
end
print("Installation complete. Applying patches now")
settings.set("theme", theme)
settings.set("autoLogin", autoLogin)
settings.set("soundEnabled", soundEnabled)
settings.set("performanceMode", performanceMode)
settings.save()
sleep(2)
os.reboot()