Skip to content

Instantly share code, notes, and snippets.

@zaze06
Last active June 16, 2021 17:57
Show Gist options
  • Save zaze06/475bb7955048fb18080ec11dd91d9e3d to your computer and use it in GitHub Desktop.
Save zaze06/475bb7955048fb18080ec11dd91d9e3d to your computer and use it in GitHub Desktop.
a program to update a harvest program
local FILENAME = '/harvest.lua'
local cacheBreak = tostring(math.random(0, 99999))
res, err = http.get('https://gist.githubusercontent.com/zaze06/f940993cf2d8434da98456dd693fe50b/raw/5ebc81b1b6a7796df2e2bc2e29b7862d12141e69/harvest.lua?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