jille_Jr

CC: Github download

Nov 23rd, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1.  
  2. -- You can also find the program here:
  3. -- http://pastebin.com/bKJZMvey
  4. -- pastebin get bKJZMvey get
  5.  
  6. --(( Variables ))--
  7.  
  8. local url = "https://raw.github.com/jilleJr/ShopProg/master/"
  9. local filename = ""
  10. local extension = ".lua"
  11. local savepath = ""
  12. local args = {...}
  13.  
  14. --(( Functions ))--
  15.  
  16. local function color(fg,bg)
  17.     if term.isColor() then
  18.         if fg then term.setTextColor(fg) end
  19.         if bg then term.setBackgroundColor(bg) end
  20.     end
  21. end
  22.  
  23. local function usage(text)
  24.     color(colors.red)
  25.     if text then print(text) end
  26.     local file = fs.getName(shell.getRunningProgram())
  27.     print("Usage: "..file.." <file> [save name]")
  28. end
  29.  
  30. local function get(url)
  31.     local site = http.get(url)
  32.     if site then return site.readAll() end
  33. end
  34.  
  35. local function save(content,path)
  36.     local file = fs.open(path,"w")
  37.     file.write(content)
  38.     file.close()
  39. end
  40.  
  41. --(( Error handling ))--
  42.  
  43. if #args < 1 then
  44.     usage("Missing file")
  45.     return
  46. end
  47.  
  48. filename = args[1]
  49. savepath = args[2] or filename
  50.  
  51. --(( Main program ))--
  52.  
  53. color(colors.yellow)
  54. write("Getting file ")
  55. color(colors.orange)
  56. write("'"..filename.."'")
  57. color(colors.yellow)
  58. print(" from github!")
  59. print("Downloading...")
  60. local content = get(url..filename..extension)
  61. if content == nil then error("Failed!",0) end
  62. color(colors.lime)
  63. print("Success!")
  64.  
  65. color(colors.yellow)
  66. write("Saving to file ")
  67. color(colors.orange)
  68. write("'"..savepath.."'")
  69. color(colors.yellow)
  70. print("...")
  71. save(content,savepath)
  72. color(colors.lime)
  73. print("Done!")
  74.  
  75. --(( EOF ))--
Add Comment
Please, Sign In to add comment