Advertisement
Rodmastercraft

MMTP Installer

Mar 10th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local function get(file)
  2.   if not silent then
  3.     write("Fetching "..file)
  4.   end
  5.   local response = http.get("https://raw.github.com/rodsn/mmtp/master/"..file)
  6.   if response then
  7.    local content = response.readAll()
  8.    response.close()
  9.    local f = fs.open("mmtp_files/"..file,"w")
  10.    f.write(content)
  11.    f.close()
  12.    print(" [ok]")
  13.   else
  14.     if not silent then
  15.       print(" [ERROR]")
  16.     end
  17.   end
  18. end
  19.  
  20. function usage()
  21.   prog = shell.getRunningProgram()
  22.   print("Usage:")
  23.   print(prog.." full <silent>")
  24.   print(prog.." api <silent>")
  25. end
  26.  
  27. function download( mode )
  28.   if not silent then
  29.     print("Download mode: "..mode)
  30.   end
  31.   if fs.exists("mmtp_files") and fs.isDir("mmtp_files") then
  32.     if not silent then
  33.       print("mmtp_files already exists, please delete it and try again.")
  34.     end
  35.     return
  36.   else
  37.     fs.makeDir("mmtp_files")
  38.     if not silent then
  39.       print("Downloading files to: mmtp_files")
  40.     end
  41.   end
  42.  
  43.   if mode == "full" then
  44.     get("server")
  45.     get("gui")
  46.     get("client")
  47.   elseif mode == "api" then
  48.     get("server")
  49.   end
  50.   if not silent then
  51.     print("Done!")
  52.     if mode == "full" then
  53.        print("Type 'mmtp_files/client' to start the client")
  54.     end
  55.   end
  56. end
  57.  
  58. arg = { ... }
  59.  
  60. if arg[2] == "true" then
  61.   silent = true
  62. else
  63.   silent = false
  64. end
  65.  
  66. if #arg < 1 or #arg > 2 then
  67.   usage()
  68. elseif arg[1] == "full" then
  69.   download("full")
  70. elseif arg[1] == "api" then
  71.   download("api")
  72. else
  73.   usage()
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement