forked from hkc/cc-stuff
turtl
This commit is contained in:
parent
fee1bd351e
commit
f25755a684
|
@ -0,0 +1,2 @@
|
|||
turtle.up()
|
||||
turtle.down()
|
|
@ -0,0 +1,35 @@
|
|||
_G._TOS_VER = "N/A"
|
||||
local tos_ver_fp = io.open("/.tos-ver", "r")
|
||||
if tos_ver_fp then
|
||||
_G._TOS_VER = tos_ver_fp:read("l")
|
||||
tos_ver_fp:close()
|
||||
end
|
||||
|
||||
if fs.exists("/disk/update.json") then
|
||||
local info_fp = io.open("/disk/update.json", "r")
|
||||
local info = textutils.unserializeJSON(info_fp:read())
|
||||
info_fp:close()
|
||||
print("OTP version: " .. info.ver)
|
||||
print("H/W version: " .. _TOS_VER)
|
||||
if info.ver == _TOS_VER then
|
||||
print("Running on latest firmware")
|
||||
else
|
||||
print("Performing an update...")
|
||||
for i = 1, #info.files do
|
||||
local file = info.files[i]
|
||||
term.write(file.dst, "...")
|
||||
if fs.exists(file.dst) then
|
||||
term.write(" [DEL] ...")
|
||||
fs.delete(file.dst)
|
||||
end
|
||||
fs.copy("/disk" .. file.src, file.dst)
|
||||
print(" OK, copied from", file.src)
|
||||
end
|
||||
print("Writing new version info")
|
||||
io.open("/.tos-ver", "w"):write(info.ver):close()
|
||||
print("Rebooting")
|
||||
return os.reboot()
|
||||
end
|
||||
end
|
||||
|
||||
shell.run("fg", "main.lua")
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"ver": "0.0.1",
|
||||
"files": [
|
||||
{ "src": "startup.lua", "dst": "/startup.lua" },
|
||||
{ "src": "main.lua", "dst": "/main.lua" }
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue