Advertisement
Guest User

u

a guest
Oct 15th, 2017
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. -- Program to update devRant
  2. -- Essentially a "git pull git@github.com:olback/devRant-computercraft"
  3.  
  4. local downloadMain = "https://raw.githubusercontent.com/olback/devRant-computercraft/master/devRant.lua"
  5. local downloadJSON = "https://raw.githubusercontent.com/olback/devRant-computercraft/master/json.lua"
  6. local downloadInstaller = "https://raw.githubusercontent.com/olback/devRant-computercraft/master/Installer.lua"
  7. local version = "1.0d"
  8. local headers = {["User-Agent"] = "ComputerCraft devRant Updater" .. version}
  9.  
  10. local main = http.get(downloadMain, headers)
  11. local json = http.get(downloadJSON, headers)
  12. local installer = http.get(downloadInstaller, headers)
  13.  
  14. ----- Failed function -----
  15.  
  16. function failed(file)
  17.   if term.isColor() then
  18.     term.setTextColor(colors.red)
  19.   end
  20.   print("Failed to update ".. file)
  21.   term.setTextColor(colors.white)
  22. end
  23.  
  24.  
  25. ----- Udate devRant -----
  26.  
  27. if main ~= nil then
  28.        
  29.   -- Don't bother removing old file since f.write() will write over it anyways.
  30.   print("Updating devRant...")
  31.   f = fs.open("devRant", "w")
  32.   f.write(main.readAll())
  33.   f.close()
  34.  
  35. else
  36.  
  37.   failed("devRant")
  38.  
  39. end
  40.  
  41.  
  42. ----- Update json API -----
  43.  
  44. if json ~= nil then
  45.  
  46.   print("Updating JSON API...")
  47.   f = fs.open("json", "w")
  48.   f.write(json.readAll())
  49.   f.close()
  50.  
  51. else
  52.  
  53.   failed("json")
  54.  
  55. end
  56.  
  57.  
  58. ----- Update installer -----
  59.  
  60. if installer ~= nil then
  61.  
  62.   print("Updating installer...")
  63.   f = fs.open("devRantInstaller", "w")
  64.   f.write(installer.readAll())
  65.   f.close()
  66.  
  67. else
  68.  
  69.   failed("installer")
  70.  
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement