Merge pull request #3431 from stangri/master-luci-app-advanced-reboot

luci-app-advanced-reboot: bugfix: compatible with new luci
This commit is contained in:
Jo-Philipp Wich 2019-12-25 17:56:49 +01:00 committed by GitHub
commit 49b0be214b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 110 additions and 92 deletions

View file

@ -13,7 +13,7 @@ LUCI_DESCRIPTION:=Provides Web UI (found under System/Advanced Reboot) to reboot
LUCI_DEPENDS:=+luci-compat +luci-mod-admin-full LUCI_DEPENDS:=+luci-compat +luci-mod-admin-full
LUCI_PKGARCH:=all LUCI_PKGARCH:=all
PKG_RELEASE:=46 PKG_RELEASE:=47
include ../../luci.mk include ../../luci.mk

View file

@ -34,7 +34,7 @@ function is_alt_mountable(p1_mtd, p2_mtd)
end end
function get_partition_os_info(op_ubi) function get_partition_os_info(op_ubi)
local cp_info, ap_info local cp_info, op_info
if fs.access("/etc/os-release") then if fs.access("/etc/os-release") then
cp_info = util.trim(util.exec('. /etc/os-release && echo "$PRETTY_NAME"')) cp_info = util.trim(util.exec('. /etc/os-release && echo "$PRETTY_NAME"'))
if cp_info:find("SNAPSHOT") then if cp_info:find("SNAPSHOT") then
@ -45,14 +45,14 @@ function get_partition_os_info(op_ubi)
alt_partition_unmount(op_ubi) alt_partition_unmount(op_ubi)
alt_partition_mount(op_ubi) alt_partition_mount(op_ubi)
if fs.access("/alt/rom/etc/os-release") then if fs.access("/alt/rom/etc/os-release") then
ap_info = util.trim(util.exec('. /alt/rom/etc/os-release && echo "$PRETTY_NAME"')) op_info = util.trim(util.exec('. /alt/rom/etc/os-release && echo "$PRETTY_NAME"'))
if ap_info:find("SNAPSHOT") then if op_info:find("SNAPSHOT") then
ap_info = util.trim(util.exec('. /alt/rom/etc/os-release && echo "$OPENWRT_RELEASE"')) op_info = util.trim(util.exec('. /alt/rom/etc/os-release && echo "$OPENWRT_RELEASE"'))
end end
end end
logger(i18n.translate("attempting to unmount alternative partition") .. " (mtd" .. tostring(op_ubi) .. ")") logger(i18n.translate("attempting to unmount alternative partition") .. " (mtd" .. tostring(op_ubi) .. ")")
alt_partition_unmount(op_ubi) alt_partition_unmount(op_ubi)
return cp_info, ap_info return cp_info, op_info
end end
function alt_partition_mount(op_ubi) function alt_partition_mount(op_ubi)
@ -87,107 +87,124 @@ function alt_partition_unmount(op_ubi)
end end
end end
devices = { function obtain_device_info()
-- deviceName, boardName, part1MTD, part2MTD, offset, envVar1, envVar1Value1, envVar1Value2, envVar2, envVar2Value1, envVar2Value2 local i, d, p1_mtd, p2_mtd, offset, bev1, bev1p1, bev1p2, bev2, bev2p1, n
{"Linksys EA3500", "linksys-audi", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, local p1_label, p1_version, p2_label, p2_version, p1_os, p2_os
{"Linksys E4200v2/EA4500", "linksys-viper", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, local errorMessage, current_partition, other_partition
{"Linksys EA6350v3", "linksys-ea6350v3", "mtd10", "mtd12", 192, "boot_part", 1, 2}, local op_ubi, cp_info, op_info
{"Linksys EA8300", "linksys-ea8300", "mtd10", "mtd12", 192, "boot_part", 1, 2}, local zyxelFlagPartition
{"Linksys EA8500", "ea8500", "mtd13", "mtd15", 32, "boot_part", 1, 2}, local devices = {
-- {"Linksys EA9500", "linksys-panamera", "mtd3", "mtd6", 28, "boot_part", 1, 2}, -- deviceName, boardName, part1MTD, part2MTD, offset, envVar1, envVar1Value1, envVar1Value2, envVar2, envVar2Value1, envVar2Value2
{"Linksys WRT1200AC", "linksys-caiman", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, {"Linksys EA3500", "linksys-audi", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
{"Linksys WRT1900AC", "linksys-mamba", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, {"Linksys E4200v2/EA4500", "linksys-viper", "mtd3", "mtd5", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
{"Linksys WRT1900ACv2", "linksys-cobra", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, {"Linksys EA6350v3", "linksys-ea6350v3", "mtd10", "mtd12", 192, "boot_part", 1, 2},
{"Linksys WRT1900ACS", "linksys-shelby", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, {"Linksys EA8300", "linksys-ea8300", "mtd10", "mtd12", 192, "boot_part", 1, 2},
{"Linksys WRT3200ACM", "linksys-rango", "mtd5", "mtd7", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, {"Linksys EA8500", "ea8500", "mtd13", "mtd15", 32, "boot_part", 1, 2},
{"Linksys WRT32X", "linksys-venom", "mtd5", "mtd7", nil, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"}, -- {"Linksys EA9500", "linksys-panamera", "mtd3", "mtd6", 28, "boot_part", 1, 2},
{"ZyXEL NBG6817", "nbg6817", "mmcblk0p4", "mmcblk0p7", 32, nil, 255, 1} {"Linksys WRT1200AC", "linksys-caiman", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
} {"Linksys WRT1900AC", "linksys-mamba", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
{"Linksys WRT1900ACv2", "linksys-cobra", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
-- local errorMessage, d {"Linksys WRT1900ACS", "linksys-shelby", "mtd4", "mtd6", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
-- local device_name, p1_mtd, p2_mtd, offset, bev1, bev1p1, bev1p2, bev2, bev2p1, bev2p2 {"Linksys WRT3200ACM", "linksys-rango", "mtd5", "mtd7", 32, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
romBoardName = util.trim(util.exec("cat /tmp/sysinfo/board_name")) {"Linksys WRT32X", "linksys-venom", "mtd5", "mtd7", nil, "boot_part", 1, 2, "bootcmd", "run nandboot", "run altnandboot"},
{"ZyXEL NBG6817", "nbg6817", "mmcblk0p4", "mmcblk0p7", 32, nil, 255, 1}
for i=1, #devices do }
d = devices[i][2]:gsub('%p','') local romBoardName = util.trim(util.exec("cat /tmp/sysinfo/board_name"))
if romBoardName and romBoardName:gsub('%p',''):match(d) then for i=1, #devices do
device_name = devices[i][1] d = devices[i][2]:gsub('%p','')
p1_mtd = devices[i][3] or nil if romBoardName and romBoardName:gsub('%p',''):match(d) then
p2_mtd = devices[i][4] or nil device_name = devices[i][1]
offset = devices[i][5] or nil p1_mtd = devices[i][3] or nil
bev1 = devices[i][6] or nil p2_mtd = devices[i][4] or nil
bev1p1 = tonumber(devices[i][7]) or nil offset = devices[i][5] or nil
bev1p2 = tonumber(devices[i][8]) or nil bev1 = devices[i][6] or nil
bev2 = devices[i][9] or nil bev1p1 = tonumber(devices[i][7]) or nil
bev2p1 = devices[i][10] or nil bev1p2 = tonumber(devices[i][8]) or nil
bev2p2 = devices[i][11] or nil bev2 = devices[i][9] or nil
if p1_mtd and offset then bev2p1 = devices[i][10] or nil
p1_label = util.trim(util.exec("dd if=/dev/" .. p1_mtd .. " bs=1 skip=" .. offset .. " count=128" .. " 2>/dev/null")) bev2p2 = devices[i][11] or nil
n, p1_version = p1_label:match('(Linux)-([%d|.]+)') if p1_mtd and offset then
end p1_label = util.trim(util.exec("dd if=/dev/" .. p1_mtd .. " bs=1 skip=" .. offset .. " count=128" .. " 2>/dev/null"))
if p2_mtd and offset then n, p1_version = p1_label:match('(Linux)-([%d|.]+)')
p2_label = util.trim(util.exec("dd if=/dev/" .. p2_mtd .. " bs=1 skip=" .. offset .. " count=128" .. " 2>/dev/null"))
n, p2_version = p2_label:match('(Linux)-([%d|.]+)')
end
if p1_label and p1_label:find("LEDE") then p1_os = "LEDE" end
if p1_label and p1_label:find("OpenWrt") then p1_os = "OpenWrt" end
if p1_label and p1_label:find("Linksys") then p1_os = "Linksys" end
if p2_label and p2_label:find("LEDE") then p2_os = "LEDE" end
if p2_label and p2_label:find("OpenWrt") then p2_os = "OpenWrt" end
if p2_label and p2_label:find("Linksys") then p2_os = "Linksys" end
if device_name == "ZyXEL NBG6817" then
if not p1_os then p1_os = "ZyXEL" end
if not p2_os then p2_os = "ZyXEL" end
end
if device_name == "Linksys WRT32X" then
if not p1_os then p1_os = "Unknown/Compressed" end
if not p2_os then p2_os = "Unknown/Compressed" end
end
if not p1_os then p1_os = "Unknown" end
if not p2_os then p2_os = "Unknown" end
if p1_os and p1_version then p1_os = p1_os .. " (Linux " .. p1_version .. ")" end
if p2_os and p2_version then p2_os = p2_os .. " (Linux " .. p2_version .. ")" end
if device_name == "ZyXEL NBG6817" then
if not zyxelFlagPartition then zyxelFlagPartition = util.trim(util.exec(". /lib/functions.sh; find_mtd_part 0:DUAL_FLAG")) end
if not zyxelFlagPartition then
errorMessage = errorMessage or "" .. i18n.translate("Unable to find Dual Boot Flag Partition." .. " ")
util.perror(i18n.translate("Unable to find Dual Boot Flag Partition."))
else
current_partition = tonumber(util.exec("dd if=" .. zyxelFlagPartition .. " bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 \"%d\"'"))
end end
else if p2_mtd and offset then
if fs.access("/usr/sbin/fw_printenv") and fs.access("/usr/sbin/fw_setenv") then p2_label = util.trim(util.exec("dd if=/dev/" .. p2_mtd .. " bs=1 skip=" .. offset .. " count=128" .. " 2>/dev/null"))
current_partition = tonumber(util.trim(util.exec("fw_printenv -n " .. bev1))) n, p2_version = p2_label:match('(Linux)-([%d|.]+)')
end end
end if p1_label and p1_label:find("LEDE") then p1_os = "LEDE" end
other_partition = current_partition == bev1p2 and bev1p1 or bev1p2 if p1_label and p1_label:find("OpenWrt") then p1_os = "OpenWrt" end
if p1_label and p1_label:find("Linksys") then p1_os = "Linksys" end
if is_alt_mountable(p1_mtd, p2_mtd) then if p2_label and p2_label:find("LEDE") then p2_os = "LEDE" end
if current_partition == bev1p1 then if p2_label and p2_label:find("OpenWrt") then p2_os = "OpenWrt" end
op_ubi = tonumber(p2_mtd:sub(4)) + 1 if p2_label and p2_label:find("Linksys") then p2_os = "Linksys" end
else if device_name == "ZyXEL NBG6817" then
op_ubi = tonumber(p1_mtd:sub(4)) + 1 if not p1_os then p1_os = "ZyXEL" end
if not p2_os then p2_os = "ZyXEL" end
end end
local cp_info, ap_info = get_partition_os_info(op_ubi) if device_name == "Linksys WRT32X" then
if current_partition == bev1p1 then if not p1_os then p1_os = "Unknown/Compressed" end
p1_os = cp_info or p1_os if not p2_os then p2_os = "Unknown/Compressed" end
p2_os = ap_info or p2_os end
if not p1_os then p1_os = "Unknown" end
if not p2_os then p2_os = "Unknown" end
if p1_os and p1_version then p1_os = p1_os .. " (Linux " .. p1_version .. ")" end
if p2_os and p2_version then p2_os = p2_os .. " (Linux " .. p2_version .. ")" end
if device_name == "ZyXEL NBG6817" then
if not zyxelFlagPartition then zyxelFlagPartition = util.trim(util.exec(". /lib/functions.sh; find_mtd_part 0:DUAL_FLAG")) end
if not zyxelFlagPartition then
errorMessage = errorMessage or "" .. i18n.translate("Unable to find Dual Boot Flag Partition." .. " ")
util.perror(i18n.translate("Unable to find Dual Boot Flag Partition."))
else
current_partition = tonumber(util.exec("dd if=" .. zyxelFlagPartition .. " bs=1 count=1 2>/dev/null | hexdump -n 1 -e '1/1 \"%d\"'"))
end
else else
p1_os = ap_info or p1_os if fs.access("/usr/sbin/fw_printenv") and fs.access("/usr/sbin/fw_setenv") then
p2_os = cp_info or p2_os current_partition = tonumber(util.trim(util.exec("fw_printenv -n " .. bev1)))
end
end
other_partition = current_partition == bev1p2 and bev1p1 or bev1p2
if is_alt_mountable(p1_mtd, p2_mtd) then
if current_partition == bev1p1 then
op_ubi = tonumber(p2_mtd:sub(4)) + 1
else
op_ubi = tonumber(p1_mtd:sub(4)) + 1
end
local cp_info, op_info = get_partition_os_info(op_ubi)
if current_partition == bev1p1 then
p1_os = cp_info or p1_os
p2_os = op_info or p2_os
else
p1_os = op_info or p1_os
p2_os = cp_info or p2_os
end
end end
end end
end end
return romBoardName, device_name, bev1, bev1p1, p1_os, bev1p2, p2_os, bev2, bev2p1, bev2p2, current_partition
end end
function index() function index()
entry({"admin", "system", "advanced_reboot"}, template("advanced_reboot/advanced_reboot"), _("Advanced Reboot"), 90) entry({"admin", "system", "advanced_reboot"}, call("action_template"), _("Advanced Reboot"), 90)
entry({"admin", "system", "advanced_reboot", "reboot"}, post("action_reboot")) entry({"admin", "system", "advanced_reboot", "reboot"}, post("action_reboot"))
entry({"admin", "system", "advanced_reboot", "alternative_reboot"}, post("action_altreboot")) entry({"admin", "system", "advanced_reboot", "alternative_reboot"}, post("action_altreboot"))
entry({"admin", "system", "advanced_reboot", "power_off"}, post("action_poweroff")) entry({"admin", "system", "advanced_reboot", "power_off"}, post("action_poweroff"))
end end
function action_template()
local romBoardName, device_name, bev1, bev1p1, p1_os, bev1p2, p2_os, bev2, bev2p1, bev2p2, current_partition = obtain_device_info()
ltemplate.render("advanced_reboot/advanced_reboot",{
romBoardName=romBoardName,
device_name=device_name,
bev1p1=bev1p1,
p1_os=p1_os,
bev1p2=bev1p2,
p2_os=p2_os,
current_partition=current_partition,
errorMessage = errorMessage})
end
function action_reboot() function action_reboot()
ltemplate.render("advanced_reboot/applyreboot", { ltemplate.render("advanced_reboot/applyreboot", {
title = i18n.translate("Rebooting..."), title = i18n.translate("Rebooting..."),
@ -198,6 +215,7 @@ function action_reboot()
end end
function action_altreboot() function action_altreboot()
local romBoardName, device_name, bev1, bev1p1, p1_os, bev1p2, p2_os, bev2, bev2p1, bev2p2, current_partition = obtain_device_info()
local zyxelFlagPartition, zyxelBootFlag, zyxelNewBootFlag, errorCode, curEnvSetting, newEnvSetting local zyxelFlagPartition, zyxelBootFlag, zyxelNewBootFlag, errorCode, curEnvSetting, newEnvSetting
errorMessage = nil errorMessage = nil
errorCode = 0 errorCode = 0