luci-app-advanced-reboot: bugfix: luci error on reboot, logger errors 3335/head
authorStan Grishin <stangri@melmac.net>
Tue, 19 Nov 2019 16:54:37 +0000 (09:54 -0700)
committerStan Grishin <stangri@melmac.net>
Tue, 19 Nov 2019 16:54:37 +0000 (09:54 -0700)
Signed-off-by: Stan Grishin <stangri@melmac.net>
applications/luci-app-advanced-reboot/Makefile
applications/luci-app-advanced-reboot/luasrc/controller/advanced_reboot.lua
applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/applyreboot.htm [new file with mode: 0644]

index a08d57fd8b12425a9e3074d07c1210def7a2997f..e3037df2f8ba5d528aa925a945bd29a52de15f77 100644 (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_PKGARCH:=all
-PKG_RELEASE:=43
+PKG_RELEASE:=45
 
 include ../../luci.mk
 
index 8b97f2e560b7b1eddcffd2f58a89c77b5b162fe5..e1e63bcbf8a61c54b1812a8827e99042d5e4ca67 100644 (file)
@@ -45,7 +45,6 @@ end
 function alt_partition_mount(op_ubi)
        local ubi_dev
        util.exec('for i in rom overlay firmware; do [ ! -d "$i" ] && mkdir -p "/alt/${i}"; done')
-       util.exec("ubidetach -m " .. tostring(op_ubi))
        ubi_dev = tostring(util.exec("ubiattach -m " .. tostring(op_ubi)))
        _, _, ubi_dev = ubi_dev:find("UBI device number (%d+)")
        if not ubi_dev then 
@@ -54,17 +53,23 @@ function alt_partition_mount(op_ubi)
        end
        util.exec("ubiblock --create /dev/ubi" .. ubi_dev .. "_0")
        util.exec("mount -t squashfs -o ro /dev/ubiblock" .. ubi_dev .. "_0 /alt/rom")
-       util.exec("mount -t ubifs /dev/ubi1_" .. ubi_dev .. " /alt/overlay")
-       util.exec("mount -t overlay overlay -o noatime,lowerdir=/alt/rom,upperdir=/alt/overlay/upper,workdir=/alt/overlay/work /alt/firmware")
+       util.exec("mount -t ubifs /dev/ubi" .. ubi_dev .. "_1 /alt/overlay")
+--     util.exec("mount -t overlay overlay -o noatime,lowerdir=/alt/rom,upperdir=/alt/overlay/upper,workdir=/alt/overlay/work /alt/firmware")
 end
 
 function alt_partition_unmount(op_ubi)
-       util.exec("umount /alt/firmware")
-       util.exec("umount /alt/overlay")
-       util.exec("umount /alt/rom")
-       util.exec("ubiblock --remove /dev/ubi1_0")
-       util.exec("ubidetach -m " .. tostring(op_ubi))
-       util.exec('rm -rf /alt')
+--     util.exec("[ -d /alt/firmware ] && umount /alt/firmware")
+       util.exec("[ -d /alt/overlay ] && umount /alt/overlay")
+       util.exec("[ -d /alt/rom ] && umount /alt/rom")
+       for i = 0, 10 do
+               if not fs.access("/sys/devices/virtual/ubi/ubi" .. tostring(i) .. "/mtd_num") then break end
+               ubi_mtd =  tonumber(util.trim(util.exec("cat /sys/devices/virtual/ubi/ubi" .. i .. "/mtd_num")))
+               if ubi_mtd and ubi_mtd == op_ubi then
+                       util.exec("ubiblock --remove /dev/ubi" .. tostring(i) .. "_0")
+                       util.exec("ubidetach -m " .. tostring(op_ubi))
+                       util.exec('rm -rf /alt')
+               end
+       end
 end
 
 devices = {
@@ -169,7 +174,7 @@ function index()
 end
 
 function action_reboot()
-       ltemplate.render("admin_system/applyreboot", {
+       ltemplate.render("advanced_reboot/applyreboot", {
                                title = i18n.translate("Rebooting..."),
                                msg   = i18n.translate("The system is rebooting now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."),
                                addr  = ip.new(type(ip) == "string" and ip or "192.168.1.1") or "192.168.1.1"
@@ -240,7 +245,7 @@ function action_altreboot()
                        end
                end
                if not errorMessage then
-                       ltemplate.render("admin_system/applyreboot", {
+                       ltemplate.render("advanced_reboot/applyreboot", {
                                                title = i18n.translate("Rebooting..."),
                                                msg   = i18n.translate("The system is rebooting to an alternative partition now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes before you try to reconnect. It might be necessary to renew the address of your computer to reach the device again, depending on your settings."),
                                                addr  = ip.new(uci:get("network", "lan", "ipaddr")) or "192.168.1.1"
@@ -274,7 +279,7 @@ function action_poweroff()
                        ltemplate.render("advanced_reboot/advanced_reboot",{})
                end
        elseif step == 2 then
-               ltemplate.render("admin_system/applyreboot", {
+               ltemplate.render("advanced_reboot/applyreboot", {
                                        title = i18n.translate("Shutting down..."),
                                        msg   = i18n.translate("The system is shutting down now.<br /> DO NOT POWER OFF THE DEVICE!<br /> It might be necessary to renew the address of your computer to reach the device again, depending on your settings."),
                                        addr  = ip.new(uci:get("network", "lan", "ipaddr")) or "192.168.1.1"
diff --git a/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/applyreboot.htm b/applications/luci-app-advanced-reboot/luasrc/view/advanced_reboot/applyreboot.htm
new file mode 100644 (file)
index 0000000..94ac36b
--- /dev/null
@@ -0,0 +1,53 @@
+<%#
+ Copyright 2008 Steven Barth <steven@midlink.org>
+ Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
+ Licensed to the public under the Apache License 2.0.
+-%>
+
+<html>
+       <head>
+               <title><%=luci.sys.hostname()%> - <%= title or translate("Rebooting...") %></title>
+               <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css?v=git-19.271.68204-f8775ee" />
+               <script type="text/javascript" src="<%=resource%>/xhr.js?v=git-19.271.68204-f8775ee"></script>
+               <script type="text/javascript">//<![CDATA[
+                       var interval = window.setInterval(function() {
+                               var img = new Image();
+                               var target = ('https:' == document.location.protocol ? 'https://' : 'http://') + <%=addr and "'%s'" % addr or "window.location.host"%>;
+               
+                               img.onload = function() {
+                                       window.clearInterval(interval);
+                                       window.location.replace(target);
+                               };
+                               
+                               img.src = target + '<%=resource%>/icons/loading.gif?' + Math.random();
+                               
+                       }, 5000);
+               //]]></script>
+       </head>
+       <body>
+               <header>
+                       <div class="fill">
+                               <div class="container">
+                                       <p class="brand"><%=luci.sys.hostname() or "?"%></p>
+                               </div>
+                       </div>
+               </header>
+               &#160;
+               <div class="main">
+                       <div id="maincontainer">
+                               <div id="maincontent" class="container">
+                                       <h2 name="content" id="applyreboot-container" ><%:System%> - <%= title or translate("Rebooting...") %></h2>
+                                       <div class="cbi-section" id="applyreboot-section">
+                                               <div>
+                                                       <%= msg or translate("Changes applied.") %>
+                                               </div>
+                                               <div>
+                                                       <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
+                                                       <%:Waiting for changes to be applied...%>
+                                               </div>
+                                       </div>
+                               </div>
+                       </div>
+               </div>
+       </body>
+</html>
\ No newline at end of file