Forte40

Bee Breeding with OpenPeripherals

Mar 25th, 2014
2,988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.65 KB | None | 0 0
  1. --http://pastebin.com/Nq5jEJfM
  2.  
  3. if not http then
  4.   print("No access to web")
  5.   return
  6. end
  7.  
  8. local branch = "master"
  9.  
  10. local files = {
  11.   {
  12.     name = "openbee-install",
  13.     url = "https://raw.github.com/Forte40/openbee/"..branch.."/openbee-install.lua"
  14.   },
  15.   {
  16.     name = "openbee",
  17.     url = "https://raw.github.com/Forte40/openbee/"..branch.."/openbee.lua"
  18.   },
  19.   {
  20.     name = "matron",
  21.     url = "https://raw.github.com/Forte40/openbee/"..branch.."/matron.lua"
  22.   }
  23. }
  24.  
  25. for _, file in ipairs(files) do
  26.   local path
  27.   if file.folder then
  28.     if not fs.exists(file.folder) then
  29.       fs.makeDir(file.folder)
  30.     end
  31.     path = fs.combine(file.folder, file.name)
  32.   else
  33.     path = file.name
  34.   end
  35.   local currText = ""
  36.   if fs.exists(path) then
  37.     local f = fs.open(path, "r")
  38.     currText = f.readAll()
  39.     f.close()
  40.     io.write("update  ")
  41.   else
  42.     io.write("install ")
  43.   end
  44.   io.write("'"..file.name.."'"..string.rep(" ", math.max(0, 8 - #file.name)))
  45.   if file.folder then
  46.     io.write(" in '"..file.folder.."'"..string.rep(".", math.max(0, 8 - #file.folder)).."...")
  47.   else
  48.     io.write("    .............")
  49.   end
  50.   local request = http.get(file.url)
  51.   if request then
  52.     local response = request.getResponseCode()
  53.     if response == 200 then
  54.       local newText = request.readAll()
  55.       if newText == currText then
  56.         print("skip")
  57.       else
  58.         local f = fs.open(path, "w")
  59.         f.write(newText)
  60.         f.close()
  61.         print("done")
  62.       end
  63.     else
  64.       print(" bad HTTP response code " .. response)
  65.     end
  66.   else
  67.     print(" no request handle")
  68.   end
  69.   os.sleep(0.1)
  70. end
  71. print("Finished")
Advertisement
Add Comment
Please, Sign In to add comment