Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --#--
- dev = false
- defaultPath = nil
- WaitTime = 0
- ID = nil
- profanity = false
- --==--==--==--==--==--==--==--==--==--
- function cp(str) --FBI, its not what you think it is
- local x, y = term.getSize()
- local cx, cy = term.getCursorPos()
- local l = #str
- term.setCursorPos((x/2)-(l/2), cy)
- print(str)
- end
- function halt()
- os.pullEvent("HALT")
- end
- function fuck(err, act)
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.black)
- if profanity then cp("Fuck, it broke") else cp("It broke") end
- print("\r\n")
- if err == nil then cp("Thats all I know") end
- if err ~= nil then print(err) end
- if act == "reboot" then os.reboot() else halt() end
- end
- function debug(txt)
- if dev == 'true' or dev then print(txt) end
- end
- function cfill(c)
- if term.isColor() ~= true then c = colors.black end
- term.setCursorPos(1, 1)
- term.setBackgroundColor(c)
- term.setTextColor(c)
- for i = 1, 24 do
- print("=========================================================")
- end
- term.setCursorPos(1, 1)
- end
- function kt()
- r = 'Continue'
- return r
- end
- function exec(file)
- local f = fs.open(file, 'r')
- local r = f.readAll()
- f.close()
- local c = loadstring(r)
- setfenv(c, getfenv())
- if term then
- term.clear()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- cfill(colors.black)
- term.setTextColor(colors.white)
- else
- error("NO TERM API")
- end
- c()
- end
- function boot()
- local r = "Continue"
- if ID ~= nil then function os.getComputerID() return ID end end
- if fs.exists("/boot/os") ~= true then
- term.setTextColor(colors.red)
- fuck('No Bootable Medium Found')
- term.setTextColor(colors.white)
- sleep(2)
- r = false
- else
- local chosen = '/boot/os'
- debug('')
- local k = kt()
- if k == "Continue" then
- exec(chosen)
- elseif k == "Menu" then
- r = "Menu"
- elseif k == "Setup" then
- r = "Setup"
- else
- term.setTextColor(colors.red)
- print("WARNING: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING VERY NASTY, PLEASE REBOOT AND MAKE SURE THAT", string.upper(chosen), "HAS NOT BEEN TAMPERED WITH.")
- os.pullEvent("HALT")
- end
- end
- return r
- end
- function menu()
- term.clear()
- cfill(colors.blue)
- if term.isColor then term.setBackgroundColor(colors.blue) end
- term.setTextColor(colors.white)
- local x, y = term.getSize()
- term.setCursorPos((x/2)-8, 1)
- print('Select a boot file')
- local x, y = term.getSize()
- term.setCursorPos(1,4)
- dev = false
- local f = find()
- dev = true
- for i, v in pairs(f) do
- print(i .. '. ' .. v)
- end
- print('0. Other')
- print('')
- print('')
- write('#> ')
- local n = read()
- if tonumber(n) == 0 then
- write('Path> ')
- local o = read()
- if fs.exists(o) then
- exec(o)
- else
- print('file does not exist')
- sleep(2)
- menu()
- end
- elseif tonumber(n) == nil or tonumber(n)>#f or tonumber(n)<1 then
- print('Invalid boot file')
- menu()
- else
- local s = f[tonumber(n)]
- print('Selecting ' .. s)
- sleep(1)
- exec(s)
- end
- end
- argv = {...}
- function main()
- if #argv > 0 then
- --Someones trying to configure via commandline
- local cfg = {}
- if fs.exists('.bcfg') then
- local cfgb = fs.open('.bcfg', 'r')
- cfg = cfgb.readAll()
- cfgb.close()
- cfg = textutils.unserialise(cfg)
- end
- --f, s = string.match(v, "(%w+)=(%w+)")
- local f = argv[1]
- local t = argv[2]
- cfg[f] = t
- print("Inserted ", t, " into ", f)
- local cfgb = fs.open('.bcfg', 'w')
- cfgb.write(textutils.serialize(cfg))
- cfgb.close()
- elseif shell.getRunningProgram() ~= nil then
- local b = boot()
- if b == "Continue" then
- --booted successfully
- elseif b == "Menu" then
- --launch menu(
- elseif b == "Setup" then
- --start setup
- end
- else
- --launch a shell
- os.loadAPI('/rom/programs/lua')
- end
- end
- local stat, err = pcall(main)
- if not stat then fuck(err) end
Advertisement
Add Comment
Please, Sign In to add comment