Cozza38

bee-installer

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