This commit is contained in:
Casey 2024-01-12 19:26:51 +03:00
parent fee1bd351e
commit f25755a684
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
3 changed files with 44 additions and 0 deletions

2
turtos/main.lua Normal file
View File

@ -0,0 +1,2 @@
turtle.up()
turtle.down()

35
turtos/startup.lua Normal file
View File

@ -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")

7
turtos/update.json Normal file
View File

@ -0,0 +1,7 @@
{
"ver": "0.0.1",
"files": [
{ "src": "startup.lua", "dst": "/startup.lua" },
{ "src": "main.lua", "dst": "/main.lua" }
]
}