local component = require("component") local computer = require("computer") local args = {...} local force = false local forceArgIdx = table.find(args,"-f") or table.find(args,"--force") if forceArgIdx then table.remove(args,forceArgIdx) force = true end local function getComponentID(str) local function fromSlot(slot) for i,v in component.list() do if component.slot(i)==slot then return i end end end if str=="hdd1" or str=="#1" then return fromSlot(5) end if str=="hdd2" or str=="#2" then return fromSlot(6) end if str=="floppy" or str=="#3" then return fromSlot(7) end if #str<3 then return nil,"Abbreviated ID must atleast have 3 characters" end return component.get(str) end local function fileExists(compID,file) return component.invoke(compID,"exists",file) and not component.invoke(compID,"isDirectory",file) end if type(args[1])=="string" then local compID,err = getComponentID(args[1]) if not compID then print("\x1b[91mCould not get component ID from '"..args[1].."'.") if type(err)=="string" then print("\x1b[91m"..err.."\x1b[0m") end return end if not force then if component.virtual.check(compID) then return print("\x1b[91mThis component is virtual and cannot be booted from directly.\nID: "..compID.."\x1b[0m") end local type = component.type(compID) if type~="filesystem" and type~="drive" then return print("\x1b[91mThis component is not a storage medium.\nID: "..compID.."\x1b[0m") end if type=="filesystem" and not fileExists(compID,"/init.lua") then return print("\x1b[91mThis storage medium doesn't have an \"init.lua\" file.\nID: "..compID.."\x1b[0m") end end computer.setBootAddress(compID) if computer.getBootAddress()~=compID then return print("\x1b[91mFailed to set the boot address.\x1b[0m") end computer.shutdown(true) else require("shell").run("help boot") end