1
0
Fork 0
cc-stuff/turtos/startup.lua

41 lines
1.1 KiB
Lua

if not turtle then
printError("not a turtle")
return
end
_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")