#!/opt/lnxall_app/bin/lua local invoker = require "invoker" local gfmt = string.format local function check_init() invoker.chdir("/tmp") invoker.setenv("LANG", nil) invoker.setenv("PATH", "/opt/lnxall_app/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin") local okay, output = invoker.invoke(invoker.OUTPUT, "uname", "-a") if okay ~= 0 or type(output) ~= "string" then io.stderr:write("Error, uname -a has failed.\n") io.stderr:flush() return false end if not (string.find(output, "4.19.232", 1, true) and string.find(output, "aarch64", 1, true)) then io.stderr:write("Error, not target system.\n") io.stderr:flush() return false end return true end local function check_upgraded() local okay, kdate = invoker.invoke(invoker.OUTPUT, "bash", "-c", "uname -v | sed -r -e 's/^#[0-9]+ SMP //g'") if okay == 0 and type(kdate) == "string" then okay, kdate = invoker.invoke(invoker.OUTPUT, "date", "+%s", "--date=" .. kdate) if okay == 0 and type(kdate) == "string" then kdate = tonumber(kdate) else kdate = nil end else kdate = nil end if type(kdate) ~= "number" then io.stderr:write("Error, cannot determine kernel build date.\n") io.stderr:flush() elseif kdate < 1769052680 then io.stderr:write(gfmt("Warning, kernel is old: %d\n", kdate)) io.stderr:flush() return false end local uboot, output = 'u-boot.img', nil invoker.unlink(uboot) invoker.invoke(invoker.NOSTDIO, "dd", "if=/dev/mmcblk0p1", "bs=524288", "count=8", "of=" .. uboot) _, output = invoker.invoke(invoker.OUTPUT, "md5sum", uboot) invoker.unlink(uboot) if type(output) ~= "string" then output = "" end if not string.find(output, "7364962dac1c2a9a691f129300c1e914", 1, true) then io.stderr:write(gfmt("Warning, u-boot is old: %d\n", output)) io.stderr:flush() return false end output = invoker.readfile("/opt/lnxall_app/lib/dyiot/bin/system-power-down.sh") if not output then output = "" end if not string.find(output, "setdodown.lua", 1, true) then io.stderr:write("Warning, system-power-down.sh is old.\n") io.stderr:flush() return false end return true end if not check_init() then os.exit(2) end if check_upgraded() then io.stdout:write("Kernel/Uboot/Powerdown.sh already upgraded.\n") io.stdout:flush() os.exit(0) end io.stdout:write("Warning, gateway needs to be upgraded.\n") io.stdout:flush() os.exit(1)