Advertisement
Bjornir90

Server installer

Dec 5th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. --This need http API enabled
  2.  
  3. local urlD = "http://pastebin.com/raw.php?i="
  4.  
  5. local function clear()
  6.  term.clear()
  7.  term.setCursorPos(1, 1)
  8. end
  9.  
  10. local function askForDownload()
  11.  clear()
  12.  print("You are going to install CCP server side, wich is a rednet protocol for computercraft.")
  13.  print("Are you sure you want to download and install it ?")
  14.  term.setCursorPos(20, 10)
  15.  print("yes|no")
  16.  local input = string.lower(read())
  17.  if input == "yes" then
  18.   return "true"
  19.  elseif input == "no" then
  20.   return "false"
  21.  else
  22.   print("Bad response")
  23.  end
  24. end
  25. local function download()
  26.  clear()
  27.  print("Downloading encryption API...")
  28.  local response = http.request(urlD.."7tpk7XnW")
  29.  local event, url, encryptResp =  os.pullEvent()
  30.  if event == "http_success" then
  31.   encryptAPI = encryptResp.readAll()
  32.   encryptResp.close()
  33.  elseif event == "http_failure" then
  34.   error("Can not connect to pastebin")
  35.  end
  36.  clear()
  37.  print("Downloading coreplugin...")
  38.   local response = http.request(urlD.."h8e0CRUh")
  39.  local event, url, coreResp =  os.pullEvent()
  40.  if event == "http_success" then
  41.   coreplugin = coreResp.readAll()
  42.   coreResp.close()
  43.  elseif event == "http_failure" then
  44.   error("Can not connect to pastebin")
  45.  end
  46.  clear()
  47.  print("Downloading main program...")
  48.   local response = http.request(urlD.."a6PAyTwh")
  49.  local event, url, mainResp =  os.pullEvent()
  50.  if event == "http_success" then
  51.   mainP = mainResp.readAll()
  52.   mainResp.close()
  53.  elseif event == "http_failure" then
  54.   error("Can not connect to pastebin")
  55.  end
  56.  clear()
  57.  print("Downloading GUI API...")
  58.   local response = http.request(urlD.."RZYPqxCp")
  59.  local event, url, GUIResp =  os.pullEvent()
  60.  if event == "http_success" then
  61.   GUIAPI = GUIResp.readAll()
  62.   GUIResp.close()
  63.  elseif event == "http_failure" then
  64.   error("Can not connect to pastebin")
  65.  end
  66.  clear()
  67.  print("Installing files...")
  68.  term.setTextColor(colors.red)
  69.  print("WARNING : do not shutdown computer !")
  70.  print(" ")
  71.  term.setTextColor(colors.black)
  72.  fs.makeDir("serverFolder")
  73.  fs.makeDir("/serverFolder/Plugins")
  74.  fs.makeDir("usermade")
  75.  fs.makeDir("/serverFolder/API")
  76.  write(".")
  77.  local mainF = fs.open("Server", "w")
  78.   mainF.write(mainP)
  79.   mainF.close()
  80.  write(".")
  81.  local GUIF = fs.open("/serverFolder/API/gui", "w")
  82.   GUIF.write(GUI   API)
  83.   GUIF.close()
  84.  write(".")
  85.  local coreF = fs.open("/serverFolder/Plugins/coreplugin", "w")
  86.   coreF.write(coreplugin)
  87.   coreF.close()
  88.  write(".")
  89.  local encryptF = fs.open("/serverFolder/API/enc", "w")
  90.   encryptF.write(encryptAPI)
  91.   encryptF.close()
  92.  write(".")
  93.  term.setTextColor(colors.green)
  94.  print("Installation done !")
  95.  term.setTextColor(colors.black)
  96.  sleep(2)
  97.  clear()
  98. end
  99.  
  100. if askForDownload() == "true" then
  101.  download()
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement