Advertisement
Guest User

binit_test

a guest
Sep 21st, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. local filesystem = require("filesystem")
  2. local component = require("component")
  3. local term = require("term")
  4. local internet = require("internet")
  5. local gpu = component.gpu
  6. local shell = require("shell")
  7. local os = require("os")
  8.  
  9. local function download(_file)
  10.   if component.isAvailable("internet") then
  11.     if _file == "bcore_api" then
  12.       local f1, _ = io.open("/bAPIS/bcore.lua","w")
  13.       local result, response = pcall(internet.request, "http://pastebin.com/raw.php?i=8czw0qSx")
  14.       if result then
  15.         for chunk in response do
  16.           f1:write(chunk)
  17.         end
  18.         f1:close()
  19.       else
  20.         io.stderr:write("Error downloading bcore")
  21.         return
  22.       end
  23.     elseif _file == "bcolor_api" then
  24.       local f2, _ = io.open("/bAPIS/bcolor.lua","w")
  25.       local result2, response2 = pcall(internet.request, "http://pastebin.com/raw.php?i=ayxkDdwg")
  26.       if result2 then
  27.         for chunk in response2 do
  28.           f2:write(chunk)
  29.         end
  30.         f2:close()
  31.       else
  32.         io.stderr:write("Error downloading bcolor")
  33.         return
  34.       end
  35.     elseif _file == "package_new" then
  36.       filesystem.remove("/lib/package.lua")
  37.       local f3, _ = io.open("/lib/package.lua", "w")
  38.       local result3, response3 = pcall(internet.request, "http://pastebin.com/raw.php?i=sPKxWynf")
  39.       if result3 then
  40.         for chunk in response3 do
  41.           f3:write(chunk)
  42.         end
  43.         f3:close()
  44.       else
  45.         io.stderr:write("Error downloading new package file")
  46.         return
  47.       end
  48.     end
  49.   else
  50.     io.stderr:write("No internet connection: component internet missing\nYou have to download the bAPIS manually.")
  51.     return
  52.   end
  53. end
  54.  
  55. local function status(msg)
  56.   local w,h = gpu.getResolution
  57.   term.write(msg)
  58.   xt, yt = term.getCursor()
  59.   term.setCursor(1,yt+1)
  60. end
  61.  
  62. term.clear()
  63. status("Checking APIS...")
  64. if not filesystem.exists("/bAPIS/") then
  65.   status("Creating API-Folder")
  66.   filesystem.makeDirectory("/bAPIS/")
  67. else
  68.   status("API-Folder existing - skipping")
  69.   os.sleep(0.2)
  70. end
  71. if not filesystem.exists("/bAPIS/bcore.lua") then
  72.   status("downloading API bcore")
  73.   download("bcore_api")
  74. else
  75.   status("bcore existing - skipping")
  76.   os.sleep(0.2)
  77. end
  78. if not filesystem.exists("/bAPIS/bcolor.lua") then
  79.   status("downloading API bcolor")
  80.   download("bcolor_api")
  81. else
  82.   status("bcolor existing - skipping")
  83.   os.sleep(0.2)
  84. end
  85. status("Finished checking apis")
  86. status("Replacing systemfile: package.lua")
  87. download("package_new")
  88. status("Finished replacing package.lua")
  89. term.clear()
  90. shell.execute("shell")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement