Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local path = "/init.lua"
- ------------------------------------------------
- local eeprom = component.proxy(component.list("eeprom")())
- local write = function() end
- local gpu = false
- local function sleep(timeout)
- checkArg(1, timeout, "number", "nil")
- local deadline = computer.uptime() + (timeout or 0)
- repeat
- computer.pullSignal(deadline - computer.uptime())
- until computer.uptime() >= deadline
- end
- if component.list("gpu") then
- gpu = component.proxy(component.list("gpu")())
- local w, h = gpu.maxResolution()
- gpu.setResolution(w, h)
- gpu.setBackground(0xffffff)
- gpu.fill(1, 1, w, h, " ")
- write = function(text)
- local tag = "loading..."
- gpu.setBackground(0xffffff)
- gpu.setForeground(0x000000)
- gpu.set(w/2-string.len(tag)/2, h/2-1, tag)
- gpu.setForeground(0x646464)
- gpu.set(w/2-string.len(text)/2, h/2, text)
- sleep(0.5)
- end
- end
- write("Starting")
- if not component.list("filesystem") then error("No bootable medium found") end
- local fs = component.proxy(component.list("filesystem")())
- local internet = false
- if component.list("internet") then internet = component.proxy(component.list("internet")()) end
- computer.setBootAddress = function(address)
- return eeprom.setData(address)
- end
- computer.getBootAddress = function()
- return eeprom.getData()
- end
- local function l_loadfile(path, address)
- local drive
- if address then
- drive = component.proxy(address)
- else
- drive = component.proxy(computer.getBootAddress() or component.list("filesystem")())
- end
- if not drive.exists(path) then return nil, "file does not exists" end
- if drive.isDirectory(path) then return nil, "file is directory" end
- local handle, reason = drive.open(path, "r")
- if not handle then return nil, "handle error: " .. reason end
- local code = drive.read(handle, math.huge)
- return load(code)
- end
- local function hex(r, g, b)
- local color
- if r>=0 and r<=255 and g>=0 and g<=255 and b>=0 and g<=255 then color = (r *(256^2)) + (g * 256) + b end
- return color or 0
- end
- write("Searching bootable drive")
- local fss = component.list("filesystem")
- local fs_address
- for fs in pairs(fss) do
- local proxy = component.proxy(fs)
- if proxy.exists(path) and not proxy.isDirectory(path) then
- local handle = proxy.open(path, "r")
- local code = proxy.read(handle, math.huge)
- proxy.close(handle)
- if load(code) then fs_address = fs end
- end
- end
- if not fs_address then
- if gpu then
- gpu.setBackground(0x0000ff)
- local w, h = gpu.getResolution()
- gpu.fill(1, 1, 1, h, " ")
- for i = 1, w do
- gpu.copy(1, 1, w, h, 1, 0)
- sleep(0)
- end
- error("No bootable "..path.." found")
- else
- for i = 1, 3 do computer.beep(500, 0.1) end
- error("No bootable "..path.." found")
- end
- else
- write("Booting from " .. fs_address)
- computer.setBootAddress(fs_address)
- for i = 255, 1, -8 do
- local w, h = gpu.getResolution()
- gpu.setBackground(hex(i, i, i))
- gpu.fill(1, 1, w, h, " ")
- sleep(0)
- end
- local func, reason = l_loadfile(path, computer.getBootAddress())
- if func then func() else error("Error with loading boot file: " .. reason) end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement