From 04e415eeade102c6f876453d1125036d3eb63d40 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:41:20 +0800 Subject: [PATCH] update 2024-03-06 17:41:20 --- luci-app-amlogic/Makefile | 2 +- .../luasrc/controller/amlogic.lua | 42 +++++++++++++++-- .../model/cbi/amlogic/amlogic_check.lua | 14 +++++- .../luasrc/view/amlogic/other_check.htm | 2 +- .../luasrc/view/amlogic/other_rescue.htm | 46 +++++++++++++++++++ luci-app-amlogic/po/zh-cn/amlogic.po | 12 +++++ luci-app-amlogic/root/usr/sbin/openwrt-kernel | 32 +++++-------- 7 files changed, 122 insertions(+), 28 deletions(-) create mode 100644 luci-app-amlogic/luasrc/view/amlogic/other_rescue.htm diff --git a/luci-app-amlogic/Makefile b/luci-app-amlogic/Makefile index 7c308011a..bca512119 100644 --- a/luci-app-amlogic/Makefile +++ b/luci-app-amlogic/Makefile @@ -16,7 +16,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-amlogic -PKG_VERSION:=3.1.221 +PKG_VERSION:=3.1.222 PKG_RELEASE:=1 PKG_LICENSE:=GPL-2.0 License diff --git a/luci-app-amlogic/luasrc/controller/amlogic.lua b/luci-app-amlogic/luasrc/controller/amlogic.lua index 8a8eda2e4..f83202495 100644 --- a/luci-app-amlogic/luasrc/controller/amlogic.lua +++ b/luci-app-amlogic/luasrc/controller/amlogic.lua @@ -36,11 +36,13 @@ function index() entry({ "admin", "system", "amlogic", "start_check_firmware" }, call("action_start_check_firmware")).leaf = true entry({ "admin", "system", "amlogic", "start_check_plugin" }, call("action_start_check_plugin")).leaf = true entry({ "admin", "system", "amlogic", "start_check_kernel" }, call("action_start_check_kernel")).leaf = true + entry({ "admin", "system", "amlogic", "start_check_rescue" }, call("action_start_check_rescue")).leaf = true entry({ "admin", "system", "amlogic", "start_check_upfiles" }, call("action_start_check_upfiles")).leaf = true entry({ "admin", "system", "amlogic", "start_amlogic_install" }, call("action_start_amlogic_install")).leaf = true entry({ "admin", "system", "amlogic", "start_amlogic_update" }, call("action_start_amlogic_update")).leaf = true entry({ "admin", "system", "amlogic", "start_amlogic_kernel" }, call("action_start_amlogic_kernel")).leaf = true entry({ "admin", "system", "amlogic", "start_amlogic_plugin" }, call("action_start_amlogic_plugin")).leaf = true + entry({ "admin", "system", "amlogic", "start_amlogic_rescue" }, call("action_start_amlogic_rescue")).leaf = true entry({ "admin", "system", "amlogic", "start_snapshot_delete" }, call("action_start_snapshot_delete")).leaf = true entry({ "admin", "system", "amlogic", "start_snapshot_restore" }, call("action_start_snapshot_restore")).leaf = true entry({ "admin", "system", "amlogic", "start_snapshot_list" }, call("action_check_snapshot")).leaf = true @@ -129,6 +131,7 @@ function action_refresh_log() luci.sys.exec("echo '' > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") luci.sys.exec("echo '' > /tmp/amlogic/amlogic_check_kernel.log && sync >/dev/null 2>&1") luci.sys.exec("echo '' > /tmp/amlogic/amlogic_check_firmware.log && sync >/dev/null 2>&1") + luci.sys.exec("echo '' > /tmp/amlogic/amlogic_check_rescue.log && sync >/dev/null 2>&1") luci.sys.exec("echo '' > /tmp/amlogic/amlogic_running_script.log && sync >/dev/null 2>&1") end luci.http.prepare_content("text/plain; charset=utf-8") @@ -147,16 +150,17 @@ function action_del_log() luci.sys.exec(": > /tmp/amlogic/amlogic_check_plugin.log") luci.sys.exec(": > /tmp/amlogic/amlogic_check_kernel.log") luci.sys.exec(": > /tmp/amlogic/amlogic_check_firmware.log") + luci.sys.exec(": > /tmp/amlogic/amlogic_check_rescue.log") luci.sys.exec(": > /tmp/amlogic/amlogic_running_script.log") end --Upgrade luci-app-amlogic plugin function start_amlogic_plugin() luci.sys.call("echo '1@Plugin update in progress, try again later!' > /tmp/amlogic/amlogic_running_script.log && sync >/dev/null 2>&1") - local ipk_state = luci.sys.call("[ -f /etc/config/amlogic ] && cp -vf /etc/config/amlogic /etc/config/amlogic_bak > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") - local ipk_state = luci.sys.call("opkg --force-reinstall install /tmp/amlogic/*.ipk > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") - local ipk_state = luci.sys.call("[ -f /etc/config/amlogic_bak ] && cp -vf /etc/config/amlogic_bak /etc/config/amlogic > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") - local ipk_state = luci.sys.call("rm -rf /tmp/luci-indexcache /tmp/luci-modulecache/* /etc/config/amlogic_bak >/dev/null 2>&1") + luci.sys.call("[ -f /etc/config/amlogic ] && cp -vf /etc/config/amlogic /etc/config/amlogic_bak > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") + luci.sys.call("opkg --force-reinstall install /tmp/amlogic/*.ipk > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") + luci.sys.call("[ -f /etc/config/amlogic_bak ] && cp -vf /etc/config/amlogic_bak /etc/config/amlogic > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") + luci.sys.call("rm -rf /tmp/luci-indexcache /tmp/luci-modulecache/* /etc/config/amlogic_bak >/dev/null 2>&1") luci.sys.call("echo '' > /tmp/amlogic/amlogic_running_script.log && sync >/dev/null 2>&1") local state = luci.sys.call("echo 'Successful Update' > /tmp/amlogic/amlogic_check_plugin.log && sync >/dev/null 2>&1") return state @@ -184,6 +188,15 @@ function start_amlogic_update() return state end +--Read rescue kernel log +local function start_amlogic_rescue() + luci.sys.call("echo '4@Kernel rescue in progress, try again later!' > /tmp/amlogic/amlogic_running_script.log && sync >/dev/null 2>&1") + luci.sys.call("chmod +x /usr/sbin/" .. device_kernel_script .. " >/dev/null 2>&1") + local state = luci.sys.call("/usr/sbin/" .. device_kernel_script .. " -s > /tmp/amlogic/amlogic_check_rescue.log && sync >/dev/null 2>&1") + luci.sys.call("echo '' > /tmp/amlogic/amlogic_running_script.log && sync >/dev/null 2>&1") + return state +end + --Install amlogic openwrt firmware function start_amlogic_install() luci.sys.exec("chmod +x /usr/sbin/" .. device_install_script .. " >/dev/null 2>&1") @@ -280,6 +293,11 @@ local function start_check_firmware() return luci.sys.exec("sed -n '$p' /tmp/amlogic/amlogic_check_firmware.log 2>/dev/null") end +--Read rescue kernel log +local function start_check_rescue() + return luci.sys.exec("sed -n '$p' /tmp/amlogic/amlogic_check_rescue.log 2>/dev/null") +end + --Read openwrt install log local function start_check_install() return luci.sys.exec("sed -n '$p' /tmp/amlogic/amlogic_check_install.log 2>/dev/null") @@ -309,6 +327,14 @@ function action_start_check_firmware() }) end +--Return online check rescue kernel result +function action_start_check_rescue() + luci.http.prepare_content("application/json") + luci.http.write_json({ + start_check_rescue = start_check_rescue(); + }) +end + --Return online install openwrt result function action_start_check_install() luci.http.prepare_content("application/json") @@ -365,6 +391,14 @@ function action_start_amlogic_plugin() }) end +--Return rescue kernel result +function action_start_amlogic_rescue() + luci.http.prepare_content("application/json") + luci.http.write_json({ + start_amlogic_rescue = start_amlogic_rescue(); + }) +end + --Return files upload result function action_start_check_upfiles() luci.http.prepare_content("application/json") diff --git a/luci-app-amlogic/luasrc/model/cbi/amlogic/amlogic_check.lua b/luci-app-amlogic/luasrc/model/cbi/amlogic/amlogic_check.lua index 35b5d0ffc..2a3c2c3dc 100644 --- a/luci-app-amlogic/luasrc/model/cbi/amlogic/amlogic_check.lua +++ b/luci-app-amlogic/luasrc/model/cbi/amlogic/amlogic_check.lua @@ -1,4 +1,4 @@ -local b +local b, c --SimpleForm for Check b = SimpleForm("amlogic", nil) @@ -9,4 +9,14 @@ b.submit = false b:section(SimpleSection).template = "amlogic/other_check" -return b + +--SimpleForm for Rescue Kernel +c = SimpleForm("rescue", nil) +c.title = translate("Rescue Kernel") +c.description = translate("When a kernel update fails and causes the OpenWrt system to be unbootable, the kernel can be restored by mutual recovery from eMMC/NVMe/sdX.") +c.reset = false +c.submit = false + +c:section(SimpleSection).template = "amlogic/other_rescue" + +return b, c \ No newline at end of file diff --git a/luci-app-amlogic/luasrc/view/amlogic/other_check.htm b/luci-app-amlogic/luasrc/view/amlogic/other_check.htm index c6fbaf470..9d404a2b5 100644 --- a/luci-app-amlogic/luasrc/view/amlogic/other_check.htm +++ b/luci-app-amlogic/luasrc/view/amlogic/other_check.htm @@ -215,7 +215,7 @@ _current_firmware_version.innerHTML = status.current_firmware_version ? "<%:Current Version%> [ "+status.current_firmware_version+" ] " : ""+"<%:Invalid value.%>"+""; _current_plugin_version.innerHTML = status.current_plugin_version ? "<%:Current Version%> [ "+status.current_plugin_version+" ] " : ""+"<%:Invalid value.%>"+""; _current_kernel_version.innerHTML = status.current_kernel_version ? "<%:Current Version%> [ "+status.current_kernel_version+" ] " : ""+"<%:Invalid value.%>"+""; - _openwrt_mainline_version.innerHTML = status.current_kernel_branch ? " [ "+status.current_kernel_branch+".*** ] " : "[ "+"<%:Invalid value.%>"+" ]"; + _openwrt_mainline_version.innerHTML = status.current_kernel_branch ? " [ "+status.current_kernel_branch+".y ] " : "[ "+"<%:Invalid value.%>"+" ]"; } }); diff --git a/luci-app-amlogic/luasrc/view/amlogic/other_rescue.htm b/luci-app-amlogic/luasrc/view/amlogic/other_rescue.htm new file mode 100644 index 000000000..239710aae --- /dev/null +++ b/luci-app-amlogic/luasrc/view/amlogic/other_rescue.htm @@ -0,0 +1,46 @@ + +
+ + +
<%:Collecting data...%> 
+
+ diff --git a/luci-app-amlogic/po/zh-cn/amlogic.po b/luci-app-amlogic/po/zh-cn/amlogic.po index aeb9f7509..64f379520 100644 --- a/luci-app-amlogic/po/zh-cn/amlogic.po +++ b/luci-app-amlogic/po/zh-cn/amlogic.po @@ -449,6 +449,18 @@ msgstr "当前版本" msgid "Latest Version" msgstr "最新版本" +msgid "Rescue Kernel" +msgstr "救援内核" + +msgid "When a kernel update fails and causes the OpenWrt system to be unbootable, the kernel can be restored by mutual recovery from eMMC/NVMe/sdX." +msgstr "当内核更新失败造成 OpenWrt 系统无法启动时,可以从 eMMC/NVME/sdX 相互恢复内核。" + +msgid "Rescue the original system kernel" +msgstr "救援原系统内核" + +msgid "Rescuing..." +msgstr "正在救援..." + msgid "Current Device:" msgstr "当前设备:" diff --git a/luci-app-amlogic/root/usr/sbin/openwrt-kernel b/luci-app-amlogic/root/usr/sbin/openwrt-kernel index 347e5d1e1..3f12ea20e 100755 --- a/luci-app-amlogic/root/usr/sbin/openwrt-kernel +++ b/luci-app-amlogic/root/usr/sbin/openwrt-kernel @@ -29,19 +29,11 @@ AUTO_MAINLINE_UBOOT="no" # Set the release check file release_file="/etc/flippy-openwrt-release" # -# Set font color -STEPS="[\033[95m STEPS \033[0m]" -INFO="[\033[94m INFO \033[0m]" -SUCCESS="[\033[92m SUCCESS \033[0m]" -FINISH="[\033[93m FINISH \033[0m]" -PROMPT="[\033[93m PROMPT \033[0m]" -ERROR="[\033[91m ERROR \033[0m]" -# #==================================================================================== # Encountered a serious error, abort the script execution error_msg() { - echo -e "[\033[1;91m Error \033[0m] ${1}" + echo -e "[Error] ${1}" exit 1 } @@ -121,7 +113,7 @@ init_var() { # Current device model MYDEVICE_NAME="$(cat /proc/device-tree/model | tr -d '\000')" [[ "${PLATFORM}" == "qemu-aarch64" ]] && MYDEVICE_NAME="KVM Virtual Machine" - echo -e "${INFO} Current device: ${MYDEVICE_NAME} [ ${PLATFORM} ], Use in [ ${EMMC_NAME} ]" + echo -e "Current device: ${MYDEVICE_NAME} [ ${PLATFORM} ], Use in [ ${EMMC_NAME} ]" sync && echo "" } @@ -354,7 +346,7 @@ update_uboot() { # Rescue the kernel sos_kernel() { - echo -e "${STEPS} Start rescuing kernel..." + echo -e "Start rescuing kernel..." # Supports specifying disks, such as: [ openwrt-kernel -s mmcblk1 ] box_disk="${2}" @@ -369,7 +361,7 @@ sos_kernel() { # Check if the disk is the same as the current system disk [[ "${box_disk}" == "${EMMC_NAME}" ]] && error_msg "The specified disk [ ${box_disk} ] is the same as the current system disk [ ${EMMC_NAME} ]." - echo -e "${INFO} The device name of the specified disk: [ ${box_disk} ]" + echo -e "The device name of the specified disk: [ ${box_disk} ]" else # Find emmc disk, first find emmc containing boot0 partition box_disk="$(lsblk -l -o NAME | grep -oE '(mmcblk[0-9]?|nvme[0-9]?n[0-9]?|[hsv]d[a-z])' | grep -vE ^${EMMC_NAME} | sort -u | head -n 1)" @@ -377,11 +369,11 @@ sos_kernel() { # Check if disk exists [[ -z "${box_disk}" ]] && error_msg "Unable to locate the storage requiring rescue." - echo -e "${INFO} The device name of the target disk: [ ${box_disk} ]" + echo -e "The device name of the target disk: [ ${box_disk} ]" fi rescue_disk="/dev/${box_disk}" - echo -e "${INFO} The current OpenWrt is running on [ /dev/${EMMC_NAME} ], and the target disk for restoration is [ ${rescue_disk} ]." + echo -e "The current OpenWrt is running on [ /dev/${EMMC_NAME} ], and the target disk for restoration is [ ${rescue_disk} ]." # Create a temporary mount directory umount ${P4_PATH}/bootfs 2>/dev/null @@ -394,7 +386,7 @@ sos_kernel() { [[ "${box_disk}" =~ ^([hsv]d[a-z]) ]] && rescue_disk_partition_name="" || rescue_disk_partition_name="p" mount ${rescue_disk}${rescue_disk_partition_name}1 ${P4_PATH}/bootfs [[ "${?}" -ne "0" ]] && error_msg "mount ${rescue_disk}${PARTITION_NAME}1 failed!" - echo -e "${INFO} The [ ${rescue_disk}${rescue_disk_partition_name}1 ] partition is mounted on [ ${P4_PATH}/bootfs ]." + echo -e "The [ ${rescue_disk}${rescue_disk_partition_name}1 ] partition is mounted on [ ${P4_PATH}/bootfs ]." # Search uuid file if [[ -f "${P4_PATH}/bootfs/uEnv.txt" ]]; then @@ -416,7 +408,7 @@ sos_kernel() { # Mount target rootfs partition mount ${target_rootfs} ${P4_PATH}/rootfs [[ "${?}" -ne "0" ]] && error_msg "mount ${rescue_disk}${PARTITION_NAME}2 failed!" - echo -e "${INFO} The [ ${target_rootfs} ] partition is mounted on [ ${P4_PATH}/rootfs ]." + echo -e "The [ ${target_rootfs} ] partition is mounted on [ ${P4_PATH}/rootfs ]." # Identify the current kernel files kernel_signature="$(uname -r)" @@ -432,7 +424,7 @@ sos_kernel() { } cp -rf /boot/{*-${kernel_signature},uInitrd,*Image,dtb} . [[ "${?}" -ne "0" ]] && error_msg "(1/2) [ boot ] kernel files rescue failed." - echo -e "${INFO} (1/2) [ boot ] kernel files rescue succeeded." + echo -e "(1/2) [ boot ] kernel files rescue succeeded." } || error_msg "(1/2) The [ ${P4_PATH}/bootfs ] folder does not exist, stop rescuing." # 02. For /lib/modules/${kernel_signature} @@ -441,7 +433,7 @@ sos_kernel() { rm -rf * cp -rf /lib/modules/${kernel_signature} . [[ "${?}" -ne "0" ]] && error_msg "(2/2) [ modules ] kernel files rescue failed." - echo -e "${INFO} (2/2) [ modules ] kernel files rescue succeeded." + echo -e "(2/2) [ modules ] kernel files rescue succeeded." } || error_msg "(2/2) The [ ${P4_PATH}/rootfs/lib/modules ] folder does not exist, stop rescuing." # Unmount the emmc partition @@ -456,7 +448,7 @@ sos_kernel() { sync && echo "" } -echo -e "${STEPS} Welcome to the OpenWrt Kernel Management Tool." +echo -e "Welcome to the OpenWrt Kernel Management Tool." # Operation environment check [[ -x "/usr/sbin/openwrt-kernel" ]] || error_msg "Please grant execution permission: chmod +x /usr/sbin/openwrt-kernel" @@ -469,7 +461,7 @@ if [[ "${@}" =~ ^-s(\s)* ]]; then # Kernel restore successful sync && sleep 3 - echo -e "${SUCCESS} Kernel rescue successful, please remove the disk and restart the OpenWrt system." + echo -e "Kernel rescue successful, please remove the disk and restart the OpenWrt system." exit 0 else # Initialize all variables