doublequestionmark

FreeLDR

Apr 25th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --#--
  2. dev = false
  3. defaultPath = nil
  4. WaitTime = 0
  5. ID = nil
  6. profanity = false
  7.  
  8. --==--==--==--==--==--==--==--==--==--
  9. function cp(str) --FBI, its not what you think it is
  10.   local x, y = term.getSize()
  11.   local cx, cy = term.getCursorPos()
  12.   local l = #str
  13.   term.setCursorPos((x/2)-(l/2), cy)
  14.   print(str)
  15. end
  16.  
  17. function halt()
  18.   os.pullEvent("HALT")
  19. end
  20.  
  21. function fuck(err, act)
  22.   term.setCursorPos(1,1)
  23.   term.setBackgroundColor(colors.white)
  24.   term.clear()
  25.   term.setTextColor(colors.black)
  26.   if profanity then cp("Fuck, it broke") else cp("It broke") end
  27.   print("\r\n")
  28.   if err == nil then cp("Thats all I know") end
  29.   if err ~= nil then print(err) end
  30.   if act == "reboot" then os.reboot() else halt() end
  31. end
  32.  
  33. function debug(txt)
  34.   if dev == 'true' or dev then print(txt) end
  35. end
  36.  
  37. function cfill(c)
  38.   if term.isColor() ~= true then c = colors.black end
  39.   term.setCursorPos(1, 1)
  40.   term.setBackgroundColor(c)
  41.   term.setTextColor(c)
  42.   for i = 1, 24 do
  43.     print("=========================================================")
  44.   end
  45.   term.setCursorPos(1, 1)  
  46. end
  47.  
  48. function kt()
  49.   r = 'Continue'
  50.   return r
  51. end
  52.  
  53. function exec(file)
  54.   local f = fs.open(file, 'r')
  55.   local r = f.readAll()
  56.   f.close()
  57.   local c = loadstring(r)
  58.   setfenv(c, getfenv())
  59.   if term then
  60.     term.clear()
  61.     term.setCursorPos(1, 1)
  62.     term.setBackgroundColor(colors.black)
  63.     cfill(colors.black)
  64.     term.setTextColor(colors.white)
  65.   else
  66.     error("NO TERM API")
  67.   end
  68.   c()
  69. end
  70.  
  71.  
  72. function boot()
  73.   local r = "Continue"
  74.   if ID ~= nil then function os.getComputerID() return ID end end
  75.  
  76.  
  77.   if fs.exists("/boot/os") ~= true then
  78.     term.setTextColor(colors.red)
  79.     fuck('No Bootable Medium Found')
  80.     term.setTextColor(colors.white)
  81.     sleep(2)
  82.     r = false
  83.   else
  84.     local chosen = '/boot/os'
  85.     debug('')
  86.     local k = kt()
  87.     if k == "Continue" then
  88.       exec(chosen)
  89.     elseif k == "Menu" then
  90.       r = "Menu"
  91.     elseif k == "Setup" then
  92.       r = "Setup"
  93.     else
  94.       term.setTextColor(colors.red)
  95.       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.")
  96.       os.pullEvent("HALT")
  97.     end
  98.   end
  99.   return r
  100. end
  101.  
  102.  
  103.  
  104. function menu()
  105.   term.clear()
  106.   cfill(colors.blue)
  107.   if term.isColor then term.setBackgroundColor(colors.blue) end
  108.   term.setTextColor(colors.white)
  109.   local x, y = term.getSize()
  110.   term.setCursorPos((x/2)-8, 1)
  111.   print('Select a boot file')
  112.   local x, y = term.getSize()
  113.   term.setCursorPos(1,4)
  114.   dev = false
  115.   local f = find()
  116.   dev = true
  117.   for i, v in pairs(f) do
  118.     print(i .. '. ' .. v)
  119.   end
  120.   print('0. Other')
  121.  
  122.   print('')
  123.   print('')
  124.   write('#> ')
  125.   local n = read()
  126.   if tonumber(n) == 0 then
  127.     write('Path> ')
  128.     local o = read()
  129.     if fs.exists(o) then
  130.       exec(o)
  131.     else
  132.       print('file does not exist')
  133.       sleep(2)
  134.       menu()
  135.     end
  136.   elseif tonumber(n) == nil or tonumber(n)>#f or tonumber(n)<1 then
  137.     print('Invalid boot file')
  138.     menu()
  139.   else
  140.     local s = f[tonumber(n)]
  141.     print('Selecting ' .. s)
  142.     sleep(1)
  143.     exec(s)
  144.   end
  145. end
  146.  
  147. argv = {...}
  148.  
  149. function main()
  150.  
  151. if #argv > 0 then
  152. --Someones trying to configure via commandline
  153.   local cfg = {}
  154.   if fs.exists('.bcfg') then
  155.     local cfgb = fs.open('.bcfg', 'r')
  156.     cfg = cfgb.readAll()
  157.     cfgb.close()
  158.     cfg = textutils.unserialise(cfg)
  159.   end
  160.     --f, s = string.match(v, "(%w+)=(%w+)")
  161.     local f = argv[1]
  162.     local t = argv[2]
  163.     cfg[f] = t
  164.     print("Inserted ", t, " into ", f)
  165.  
  166.   local cfgb = fs.open('.bcfg', 'w')
  167.   cfgb.write(textutils.serialize(cfg))
  168.   cfgb.close()
  169.  
  170. elseif shell.getRunningProgram() ~= nil then
  171.  
  172.     local b = boot()
  173.     if b == "Continue" then
  174.       --booted successfully
  175.     elseif b == "Menu" then
  176.       --launch menu(
  177.     elseif b == "Setup" then
  178.       --start setup
  179.  
  180.     end
  181. else
  182. --launch a shell
  183. os.loadAPI('/rom/programs/lua')
  184. end
  185. end
  186.  
  187. local stat, err = pcall(main)
  188. if not stat then fuck(err) end
Advertisement
Add Comment
Please, Sign In to add comment