Skip to content

Instantly share code, notes, and snippets.

@JonesiBlitz
Created May 2, 2022 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonesiBlitz/9bd69539ff6fcff51e6bbd79d2fb8be5 to your computer and use it in GitHub Desktop.
Save JonesiBlitz/9bd69539ff6fcff51e6bbd79d2fb8be5 to your computer and use it in GitHub Desktop.
gitRepo.lua
args = {...} -- [1] = URL to raw gist
-- example URL https://gist.githubusercontent.com/Havoc925/b04b28d3396ef6d2d95b94cf2f0884b4/raw/potato.lua
startstr, endstr = string.find( args[1], "/raw/" )
local FILENAME = "/" ..string.sub( args[1], endstr+1 )
local URL = args[1]
local cacheBreak = tostring(math.random(0, 99999))
res, err = http.get(URL .. '?breaker=' .. cacheBreak)
if not res then error(err) end
local code = res.readAll()
if not(fs.exists(FILENAME))
then
local newHarvest = fs.open(FILENAME, 'w')
newHarvest.close()
end
local readFile = fs.open(FILENAME, 'r')
local oldCode = readFile.readAll()
readFile.close()
local file = fs.open(FILENAME, 'w')
if oldCode == code
then
file.write(oldCode)
print('NO CHANGES MADE - Same Code')
else
file.write(code)
print('WRITING UPDATE')
byteDiff = string.len(code) - string.len(oldCode)
if byteDiff >= 0
then
print(tostring(math.abs(byteDiff)) .. ' bytes added')
else
print(tostring(math.abs(byteDiff)) .. ' bytes removed')
end
end
file.close()
res.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment