diff --git a/turtos/main.lua b/turtos/main.lua new file mode 100644 index 0000000..8ea1b07 --- /dev/null +++ b/turtos/main.lua @@ -0,0 +1,2 @@ +turtle.up() +turtle.down() diff --git a/turtos/startup.lua b/turtos/startup.lua new file mode 100644 index 0000000..64046ab --- /dev/null +++ b/turtos/startup.lua @@ -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") diff --git a/turtos/update.json b/turtos/update.json new file mode 100644 index 0000000..cab6a97 --- /dev/null +++ b/turtos/update.json @@ -0,0 +1,7 @@ +{ + "ver": "0.0.1", + "files": [ + { "src": "startup.lua", "dst": "/startup.lua" }, + { "src": "main.lua", "dst": "/main.lua" } + ] +}