This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
FREAX/boot/freax/initrd.img
2022-07-18 19:33:40 +02:00

169 lines
5.8 KiB
Text

kernel.isBooting = true
settings.load("/boot/freax/boot.conf")
if not fs.exists(settings.get("logo")) then
print("logo is not a valid image")
sleep(3)
os.reboot()
end
if not fs.exists(settings.get("logo_small")) then
print("logo_small is not a valid image")
sleep(3)
os.reboot()
end
local logo = paintutils.loadImage(settings.get("logo"))
local slogo = paintutils.loadImage(settings.get("logo_small"))
local enableBootScreen = settings.get("enableBootScreen")
local doSystemSetup = settings.get("doSystemSetup")
if enableBootScreen == "false" then
enableBootScreen = false
elseif enableBootScreen == "true" then
enableBootScreen = true
else
print("enableBootScreen is a boolean.")
sleep(3)
kernel.reboot(true)
end
if doSystemSetup == "false" then
doSystemSetup = false
elseif doSystemSetup == "true" then
doSystemSetup = true
else
print("doSystemSetup is a boolean.")
sleep(3)
kernel.reboot(true)
end
kernel.printLog = not enableBootScreen
kernel.writeBootLog("Initializing " .. kernel.getName())
kerneldraw.bootScreen(enableBootScreen,0,logo,slogo,"Initializing " .. kernel.getName())
kerneldraw.bootDelay(1)
kerneldraw.bootScreen(enableBootScreen,0,logo,slogo,"Loading system libraries")
kernel.loadSysLibs()
local oldReadOnly = _G["fs"]["isReadOnly"]
local oldMove = _G["fs"]["move"]
local oldDelete = _G["fs"]["delete"]
local oldHttpGet = _G["http"]["get"]
local oldError = _G["error"]
kerneldraw.bootDelay(1)
kerneldraw.bootScreen(enableBootScreen,10,logo,slogo,"Initializing logs")
kerneldraw.bootDelay(0.5)
kernel.writeBootLog("Initialized system boot log")
kernel.writeSyslog("Initialized primary system log")
kernel.writeMessage("Initialized secondary system log")
kerneldraw.bootScreen(enableBootScreen,13,logo,slogo,"Initializing logs")
kernel.writeSecurity("Initialized security/access log")
kernel.writeShutdown("Initialized shutdown log")
kernel.writeAuth("Initialized authorization log")
kerneldraw.bootDelay(0.25)
kerneldraw.bootScreen(enableBootScreen,15,logo,slogo,"Initializing HTTP")
if http then
kernel.writeBootLog("HTTP detection succeeded")
else
kernel.writeBootLog("HTTP detection failed")
end
kerneldraw.bootDelay(2.1)
kerneldraw.bootScreen(enableBootScreen,27,logo,slogo,"Executing autorun")
shell.run("/etc/autorun")
kerneldraw.bootScreen(enableBootScreen,36,logo,slogo,"Loading user libraries")
kernel.loadUsrLibs()
kerneldraw.bootDelay(0.25)
kerneldraw.bootScreen(enableBootScreen,44,logo,slogo,"Initializing security")
kernel.writeBootLog("Initializing security")
_G["fs"]["isReadOnly"] = function(path)
local find1 = shell.resolve(path)
if string.find(find1, "boot") or string.find(find1, "etc") or string.find(find1, "bin") or string.find(find1, "sbin") then
kernel.writeSecurity("Attempt to access system files!")
if security.getSU() or _IDENTIFIER then
kernel.writeSecurity("Superuser access verified.")
return false
else
kernel.writeSecurity("Attempt blocked.")
return true
end
elseif find1 == "initrd" or find1 == "/boot/kernel" then
kernel.writeSecurity("Attempt to access bootloader!")
kernel.writeSecurity("Attempt blocked.")
return true
end
return oldReadOnly(path)
end
_G["fs"]["move"] = function(path1, path2)
local find2 = shell.resolve(path1)
if string.find(find2, "boot") or string.find(find2, "etc") or string.find(find2, "bin") or string.find(find2, "sbin") then
kernel.writeSecurity("Attempt to access system files!")
if security.getSU() or _IDENTIFIER then
kernel.writeSecurity("Superuser access verified.")
else
kernel.writeSecurity("Attempt blocked.")
exception.throw("RestrictedOpsException")
return nil
end
elseif find2 == "initrd" or find2 == "/boot/kernel" then
kernel.writeSecurity("Attempt to access bootloader!")
kernel.writeSecurity("Attempt blocked.")
exception.throw("RestrictedOpsException")
return nil
end
return oldMove(path1, path2)
end
_G["fs"]["delete"] = function(path)
local find3 = shell.resolve(path)
if string.find(find3, "boot") or string.find(find3, "etc") or string.find(find3, "bin") or string.find(find3, "sbin") then
kernel.writeSecurity("Attempt to access system files!")
if security.getSU() or _IDENTIFIER then
kernel.writeSecurity("Superuser access verified.")
else
kernel.writeSecurity("Attempt blocked.")
exception.throw("RestrictedOpsException")
return nil
end
elseif find3 == "initrd" or find3 == "/boot/kernel" then
kernel.writeSecurity("Attempt to access bootloader!")
kernel.writeSecurity("Attempt blocked.")
exception.throw("RestrictedOpsException")
return nil
end
return oldDelete(path)
end
_G["http"]["get"] = function(url, headers)
kernel.writeSecurity("Downloaded contents of "..url)
return oldHttpGet(url, headers)
end
_G["error"] = function(text, lvl)
local x = lvl or 2
local logger = fs.open("/etc/errorLog", "a")
logger.writeLine(tostring(os.day()).."d:"..textutils.formatTime(os.time(), true).." | "..text)
logger.close()
oldError(text, x or 1)
end
rawset(fs, "_native", {})
rawset(fs, "_native.check", oldReadOnly)
rawset(fs, "_native.move", oldMove)
rawset(fs, "_native.delete", oldDelete)
rawset(http, "_synchronise", oldHttpGet)
rawset(os, "_exception", oldError)
kerneldraw.bootDelay(3.6)
kernel.writeBootLog("Boot sequence stage 2 complete")
kerneldraw.bootScreen(enableBootScreen,86,logo,slogo,"Finishing")
kerneldraw.bootDelay(3)
if doSystemSetup then
if enableBootScreen then
kerneldraw.clearScreen(colors.black)
end
local isLogsEnabled = kernel.printLog
kernel.printLog = true
if kernel.setupSystem() then
settings.set("doSystemSetup","false")
settings.save("/boot/freax/boot.conf")
else
kernel.printLog = isLogsEnabled
kernel.poweroff(true)
end
kernel.printLog = isLogsEnabled
end
kerneldraw.bootScreen(enableBootScreen,100,logo,slogo,"Starting login")
kerneldraw.bootDelay(0.5)
kernel.printLog = true
if enableBootScreen then
kerneldraw.clearScreen(colors.black)
end
shell.run("/sbin/login")