Parg60

updater-client

Jun 7th, 2021 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. local gistID = 'f404711feaaa8328f7f7110f40c6136b'
  2.  
  3. local FILENAME = '/test.lua'
  4.  
  5. local cacheBreak = tostring(math.random(0, 99999))
  6.  
  7. local link = 'https://gist.githubusercontent.com/PatrickScharberg/' .. gistID .. '/raw/' .. cacheBreak
  8.  
  9.  
  10. res, err = http.get(link)
  11. if not res then error(err) end
  12.  
  13. local code = res.readAll()
  14.  
  15.  
  16. if not(fs.exists(FILENAME))
  17. then
  18.     local newHarvest = fs.open(FILENAME, 'w')
  19.     newHarvest.close()
  20. end
  21.  
  22. local readFile = fs.open(FILENAME, 'r')
  23. local oldCode = readFile.readAll()
  24. readFile.close()
  25.  
  26. local file = fs.open(FILENAME, 'w')
  27.  
  28. if oldCode == code
  29. then
  30.     file.write(oldCode)
  31.     print('NO CHANGES MADE - Same Code')
  32. else
  33.     file.write(code)
  34.     print('WRITING UPDATE')
  35.     byteDiff = string.len(code) - string.len(oldCode)
  36.  
  37.     if byteDiff >= 0
  38.     then
  39.         print(tostring(math.abs(byteDiff)) .. ' bytes added')
  40.     else
  41.         print(tostring(math.abs(byteDiff)) .. ' bytes removed')
  42.     end
  43. end
  44.  
  45. file.close()
  46. res.close()
  47.  
  48. shell.run(FILENAME)
Add Comment
Please, Sign In to add comment