update_lift.lua

41 lines · 924 B

Open raw

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/BigBaemingGamers/update/update_lift.lua
1local FILENAME = '/lift.lua'
2
3local cacheBreak = tostring(math.random(0, 99999))
4
5res, err = http.get('https://gist.github.com/Michael-Reeves808/e2e3be2a8301df4ed96fac5834a4e334/raw/lift.lua?breaker=' .. cacheBreak)
6if not res then error(err) end
7
8local code = res.readAll()
9
10
11if not(fs.exists(FILENAME))
12then
13 local newHarvest = fs.open(FILENAME, 'w')
14 newHarvest.close()
15end
16
17local readFile = fs.open(FILENAME, 'r')
18local oldCode = readFile.readAll()
19readFile.close()
20
21local file = fs.open(FILENAME, 'w')
22
23if oldCode == code
24then
25 file.write(oldCode)
26 print('NO CHANGES MADE - Same Code')
27else
28 file.write(code)
29 print('WRITING UPDATE')
30 byteDiff = string.len(code) - string.len(oldCode)
31
32 if byteDiff >= 0
33 then
34 print(tostring(math.abs(byteDiff)) .. ' bytes added')
35 else
36 print(tostring(math.abs(byteDiff)) .. ' bytes removed')
37 end
38end
39
40file.close()
41res.close()