-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.lua
101 lines (84 loc) · 2.73 KB
/
startup.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
os.pullEvent = os.pullEventRaw
function kernelPanic(reason, log)
if fs.exists("CrashLOG.txt") then
local file = io.open("CrashLOG.txt", "r")
print("The system has encountered another kernelPanic.")
print("kernelPanic loop detected, booting into craftOS...")
print("\nIf the problem persists, you may have to reinstall LinuCraft")
sleep(5)
shell.run("rm CrashLOG.txt")
shell.run("shell")
else
--local file = io.open("CrashLOG.txt", "r")
local file = fs.open("CrashLOG.txt", "w")
file.write("CRASH_DETECTED")
file.close()
end
term.clear()
term.setCursorPos(1,1)
term.setBackgroundColour(colors.black)
term.setTextColor(colors.white)
print("A fatal error made LinuCraft crash!")
term.setTextColor(colors.red)
print(log, "<--")
term.setTextColor(colors.white)
print("Kernel panic - " .. reason)
print("\nPlease reboot LinuCraft or press any key to continue.")
os.pullEvent("key")
print("\nShutting down...")
sleep(3)
os.shutdown()
end
shell.setPath(shell.path() .. ":/OS/programs")
local label = os.getComputerLabel()
local userPath = "OS/user.txt"
local file = io.open(userPath, "r")
if file then
username = file.read(file)
file.close(file)
else
print("Error: Unable to retrieve Username")
end
-- Load settings from the file
local settingsFile = "OS/settings.txt"
local settings = {}
if fs.exists(settingsFile) then
local file = fs.open(settingsFile, "r")
settings = textutils.unserialize(file.readAll())
file.close()
else
print("Settings file not found. Creating default settings.")
end
-- Function to get a setting value by its key
local function getSettingValue(settingKey)
return settings[settingKey]
end
if getSettingValue("update_startup") then
shell.run("OS/programs/update.lua")
end
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
print("LinuCraft 0.2")
while true do
term.setTextColor(colors.green)
if label ~= nil and username ~= nil then
term.write(username.. "@" .. label)
else
kernelPanic("001 | NO LABEL/USERNAME", "term.write(username.. \"@\" .. label)")
end
term.setTextColor(colors.white)
term.write(":")
term.setTextColor(colors.blue)
local pathSeparator = (shell.dir() == "") and "" or "/"
term.write("~" .. pathSeparator..shell.dir() .. " " .. "$ ")
term.setTextColor(colors.white)
local input = read()
if input == "help" then
shell.run("OS/programs/help")
elseif input == "about" then
shell.run("OS/programs/about")
else
shell.run(input)
end
end