optimussnorr

gitsnorr downloader

Nov 21st, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. --[[
  2. GitSnorr GitHub Downloader
  3. (c) 2013 Snorrful Systems
  4. --]]
  5.  
  6. local version = "1.2"
  7.  
  8. local function clear()
  9. term.clear()
  10. term.setCursorPos(1,1)
  11. end
  12.  
  13. local function bar()
  14. term.clear()
  15. term.setCursorPos(1,1)
  16. term.setBackgroundColor(colors.green)
  17. term.clearLine()
  18. print("GitSnorr GitHub Downloader")
  19. term.setBackgroundColor(colors.black)
  20. end
  21.  
  22. clear()
  23. print("Loaded GitSnorr GitHub Downloader "..version)
  24. print("(c) 2013 Snorrful Systems")
  25. sleep(1)
  26.  
  27. if not http then
  28. clear()
  29. print("HTTP API not enabled!")
  30. print("GitSnorr downloader requires")
  31. print("for your HTTP API to be")
  32. print("enabled! Enable it in your config.")
  33. sleep(5)
  34. clear()
  35. shell.run("shell")
  36. end
  37.  
  38. bar()
  39. print("GitHub username")
  40. write("https://raw.github.com/")
  41. local user = read()
  42.  
  43. bar()
  44. print("Repository on "..user)
  45. write(user.."/")
  46. local repo = read()
  47.  
  48. bar()
  49. print("File to get from "..repo)
  50. print("Remember to include folders if it's in one")
  51. write(repo.."/")
  52. local repoFile = read()
  53.  
  54. bar()
  55. print("Connecting and downloading...")
  56. local get = http.get("https://raw.github.com/"..user.."/"..repo.."/"..repoFile)
  57.  
  58. if get then
  59. bar()
  60. print("Successfully downloaded "..repoFile)
  61. write("Save as: ")
  62. local saveAs = read()
  63.  
  64. if fs.exists(saveAs) then
  65. bar()
  66. print("File already exists!")
  67. sleep(2)
  68. clear()
  69. shell.run("shell")
  70. else
  71. bar()
  72. print("Saving...")
  73. sleep(1)
  74. bar()
  75. local data = get.readAll()
  76. get.close()
  77. local file = fs.open(saveAs,"w")
  78. file.write(data)
  79. file.close()
  80. print("Saved as "..saveAs)
  81. sleep(2)
  82. clear()
  83. shell.run("shell")
  84. end
  85.  
  86. else
  87.  
  88. bar()
  89. print("Could not download!")
  90. print("Are you sure that repository exists?")
  91. print("Make sure you also have an internet connection.")
  92. sleep(4)
  93. clear()
  94. shell.run("shell")
  95. end
Add Comment
Please, Sign In to add comment