Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- oldPull=os.pullEvent
- os.pullEvent=os.pullEventRaw
- function bboot(p)
- if chroot then
- chroot.chroot(p)
- end
- end
- function run(p)
- os.pullEvent=oldPull
- print("Running "..p)
- dofile(p)
- end
- os.loadAPI("/chroot")
- bootd={"/boot","/disk/boot","/net/","/sxwos"}
- function clear()
- x,y=term.getSize()
- term.clear()
- term.setCursorPos(1,1)
- write("+")
- for i=1,x-3 do
- write("-")
- end
- write("+")
- term.setCursorPos(1,2)
- for i=1,y-2 do
- print("|")
- end
- write("+")
- for i=1,x-3 do
- write("-")
- end
- write("+")
- for i=1,y-2 do
- term.setCursorPos(x-1,i+1)
- write("|")
- end
- term.setCursorPos(2,2)
- end
- function l()
- x,y=term.getCursorPos()
- term.setCursorPos(2,y+1)
- end
- function menu()
- clear()
- write("Hello! Welcome to SxwGRUB! Please wait...")
- sleep(1)
- l()
- write("Scanning for boot files...")
- bf,bd=scanboot()
- if not bd then
- l()
- write("Oh noe! No boot file detected.")
- l()
- write("Please insert a boot disk and install an os.")
- sleep(5)
- os.shutdown()
- else
- clear()
- if #bf==1 then
- write(bf[1].." selected. Booting...")
- sleep(1)
- bboot(bf[1])
- if chroot then
- run("/boot.lua")
- else
- run(bf[1].."/boot.lua")
- end
- clear()
- write("SxwGrub Unloaded. Goodbye!")
- sleep(1)
- end
- write("Detected boot files, press the number to boot:")
- local i=1
- for k,v in ipairs(bf) do
- l()
- write("["..i.."] "..v)
- i=1+1
- end
- while true do
- ev,t=os.pullEvent("char")
- if bf[tonumber(t)] then
- l()
- write(bf[tonumber(t)].." selected. Booting...")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- sleep(1)
- bboot(bf[tonumber(t)])
- if chroot then
- run("boot.lua")
- else
- run(bf[tonumber(t)].."/boot.lua")
- end
- clear()
- write("SxwGrub Unloaded. Goodbye!")
- sleep(1)
- os.shutdown()
- end
- end
- end
- end
- function scanboot()
- local bf={}
- local i=1
- for k,v in ipairs(bootd) do
- if scan(v) then
- l()
- bd=true
- write("["..i.."] Boot file detected at "..v.."bios.lua")
- bf[i]=v
- i=i+1
- end
- end
- return bf,bd
- end
- function scan(dir)
- l()
- write("Scanning "..dir)
- r=fs.open(dir.."/boot.lua","r")
- if r then
- r.close()
- return true
- end
- end
- if os.loadAPI("/cmdx") then
- nosdk="sxwbootKILL"
- parallel.waitForAny(menu,cmdx.nosd)
- else
- menu()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement