Last active
August 2, 2016 21:29
-
-
Save mightystoosh/2b62c39644f9bd1c18128a12688c6386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--auto_updater | |
gist_id = "2b62c39644f9bd1c18128a12688c6386" | |
current_name = "auto_update" | |
check_counter = 100 | |
--small change | |
print("small change") | |
os.sleep(1) | |
function readAll(file) | |
local f = io.lines(file) | |
local content = "" | |
for y in f do | |
content = content .. y | |
end | |
return content | |
end | |
function my_print(message) | |
print(message) | |
rednet.open("right") | |
rednet.send(61,message) | |
end | |
count = 1 | |
while(true) do | |
count = count + 1 | |
my_print("check for updates") | |
if count % check_counter == count - math.floor(count/check_counter)*check_counter then | |
print("checking for differences") | |
if(fs.exists("new_file")) then | |
shell.run("rm new_file") | |
end | |
shell.run("turtlegist get " .. gist_id .. " new_file") | |
old_file = readAll(current_name) | |
new_file = readAll("new_file") | |
if old_file == new_file then | |
print(new_file) | |
print ("files match no need to update. will try again later.") | |
os.sleep(5) | |
else | |
print ("differences found... will update and restart automatically") | |
file = io.open("rewriter", "w") | |
file:write("os.sleep(10)\nshell.run('rm auto_update')\nshell.run('cp new_file " .. current_name .. "')\nshell.run('bg " .. current_name .."')\n") | |
io.close(file) | |
shell.run("bg rewriter") | |
return | |
end | |
end | |
--os.sleep(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment