Redesigned firmware upgrade process
authorSteven Barth <steven@midlink.org>
Fri, 12 Sep 2008 11:53:08 +0000 (11:53 +0000)
committerSteven Barth <steven@midlink.org>
Fri, 12 Sep 2008 11:53:08 +0000 (11:53 +0000)
contrib/package/luci-addons/dist/sbin/luci-flash
i18n/english/luasrc/i18n/admin-core.en.lua
i18n/english/luasrc/i18n/admin-core.en.xml
i18n/german/luasrc/i18n/admin-core.de.lua
i18n/german/luasrc/i18n/admin-core.de.xml
libs/sys/luasrc/sys.lua
modules/admin-full/luasrc/controller/admin/system.lua
modules/admin-full/luasrc/view/admin_system/upgrade.htm
modules/admin-mini/luasrc/controller/mini/system.lua
modules/admin-mini/luasrc/view/mini/upgrade.htm

index 79bc834..07434b5 100755 (executable)
@@ -85,9 +85,5 @@ done
 [ -n "$sysupgrade_init_conffiles" ] && do_save_conffiles
 run_hooks "" $sysupgrade_pre_upgrade
 
-ask_bool() {
-       false
-}
-
 v "Switching to ramdisk..."
 run_ramfs '. /etc/functions.sh; include /lib/upgrade; do_upgrade'
index 88d6249..c260b59 100644 (file)
@@ -70,7 +70,7 @@ a_s_flash_flashed = 'Firmware successfully flashed. Rebooting device...'
 a_s_flash_flasherr = 'Failed to flash'
 a_s_flash_fwimage = 'Firmwareimage'
 a_s_flash_received = 'Image received. About to start flashing process. DO NOT POWER OFF THE DEVICE!'
-a_s_flash_inprogress = 'Writing firmware...'
+a_s_flash_inprogress = 'Now writing firmware. Depending on your hardware this can take up to 20 minutes or more. Please check your device from time to time to see whether the writing process has completed.'
 a_s_flash_fwupgrade = 'Flash Firmware'
 a_s_flash_keepcfg = 'Keep configuration files'
 a_s_flash_notimplemented = 'Sorry, this function is not (yet) available for your platform.'
index c161a94..322185d 100644 (file)
@@ -74,7 +74,7 @@
 <i18n:msg xml:id="a_s_flash_flasherr">Failed to flash</i18n:msg>
 <i18n:msg xml:id="a_s_flash_fwimage">Firmwareimage</i18n:msg>
 <i18n:msg xml:id="a_s_flash_received">Image received. About to start flashing process. DO NOT POWER OFF THE DEVICE!</i18n:msg>
-<i18n:msg xml:id="a_s_flash_inprogress">Writing firmware...</i18n:msg>
+<i18n:msg xml:id="a_s_flash_inprogress">Now writing firmware. Depending on your hardware this can take up to 20 minutes or more. Please check your device from time to time to see whether the writing process has completed.</i18n:msg>
 <i18n:msg xml:id="a_s_flash_fwupgrade">Flash Firmware</i18n:msg>
 <i18n:msg xml:id="a_s_flash_keepcfg">Keep configuration files</i18n:msg>
 <i18n:msg xml:id="a_s_flash_notimplemented">Sorry, this function is not (yet) available for your platform.</i18n:msg>
index 30258fb..5221b9a 100644 (file)
@@ -40,7 +40,7 @@ a_s_flash_flashed = 'Flashvorgang erfolgreich. Router startet neu...'
 a_s_flash_flasherr = 'Flashvorgang fehlgeschlagen'
 a_s_flash_fwimage = 'Firmwareimage'
 a_s_flash_received = 'Abbild empfangen. Starte Flashvorgang. SCHALTEN SIE DAS GERÄT NICHT AUS!'
-a_s_flash_inprogress = 'Schreibe Firmware...'
+a_s_flash_inprogress = 'Die Firmware wird nun geschrieben. Abhängig von der Hardware kann dieser Prozess bis zu 20 Minuten und länger dauern. Bitte prüfen sie das Gerät von Zeit zu Zeit, um zu sehen, ob der Schreibvorgang beendet ist.'
 a_s_flash_fwupgrade = 'Firmware aktualisieren'
 a_s_flash_keepcfg = 'Konfigurationsdateien übernehmen'
 a_s_flash_notimplemented = 'Diese Funktion steht leider (noch) nicht zur Verfügung.'
index 3a821c3..f963d03 100644 (file)
@@ -44,7 +44,7 @@
 <i18n:msg xml:id="a_s_flash_flasherr">Flashvorgang fehlgeschlagen</i18n:msg>
 <i18n:msg xml:id="a_s_flash_fwimage">Firmwareimage</i18n:msg>
 <i18n:msg xml:id="a_s_flash_received">Abbild empfangen. Starte Flashvorgang. SCHALTEN SIE DAS GERÄT NICHT AUS!</i18n:msg>
-<i18n:msg xml:id="a_s_flash_inprogress">Schreibe Firmware...</i18n:msg>
+<i18n:msg xml:id="a_s_flash_inprogress">Die Firmware wird nun geschrieben. Abhängig von der Hardware kann dieser Prozess bis zu 20 Minuten und länger dauern. Bitte prüfen sie das Gerät von Zeit zu Zeit, um zu sehen, ob der Schreibvorgang beendet ist.</i18n:msg>
 <i18n:msg xml:id="a_s_flash_fwupgrade">Firmware aktualisieren</i18n:msg>
 <i18n:msg xml:id="a_s_flash_keepcfg">Konfigurationsdateien übernehmen</i18n:msg>
 <i18n:msg xml:id="a_s_flash_notimplemented">Diese Funktion steht leider (noch) nicht zur Verfügung.</i18n:msg>
index e27e1c4..9b68a25 100644 (file)
@@ -60,15 +60,35 @@ exec = luci.util.exec
 --- Invoke the luci-flash executable to write an image to the flash memory.
 -- @param image                Local path or URL to image file
 -- @param kpattern     Pattern of files to keep over flash process
--- @return                     Return value of os.execute()
+-- @return                     boolean indicating status
+-- @return                     error message if any
 function flash(image, kpattern)
        local cmd = "luci-flash "
        if kpattern then
                cmd = cmd .. "-k '" .. kpattern:gsub("'", "") .. "' "
        end
-       cmd = cmd .. "'" .. image:gsub("'", "") .. "' >/dev/null 2>&1"
+       cmd = cmd .. "'" .. image:gsub("'", "") .. "' 2>/dev/null"
 
-       return os.execute(cmd)
+       local fp = io.popen(cmd)
+       local line = fp:read()
+       
+       if line == "Invalid image type" then
+               fp:close()
+               return false, line
+       else
+               line = fp:read()
+               if line == "Performing system upgrade" then
+                       return true
+               end
+               
+               line = fp:read()
+               if line == "Performing system upgrade" then
+                       return true
+               end
+               
+               fp:close()
+               return false, line
+       end
 end
 
 --- Retrieve information about currently mounted file systems.
index 5d64336..55087a0 100644 (file)
@@ -182,7 +182,7 @@ end
 function action_upgrade()
        require("luci.model.uci")
 
-       local ret
+       local ret, err
        local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
        local tmpfile = "/tmp/firmware.img"
        local broadcom = os.execute('grep brcm_ /lib/upgrade/platform.sh >/dev/null 2>&1') == 0
@@ -208,12 +208,11 @@ function action_upgrade()
        local keepcfg = keep_avail and luci.http.formvalue("keepcfg")
 
        if plat and fname then
-               ret = function()
-                       return luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
-               end
+               ret, err = luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
        end
 
-       luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret, keep_avail=keep_avail})
+       luci.template.render("admin_system/upgrade", {sysupgrade=plat,
+               ret=ret, err=err, keep_avail=keep_avail})
 end
 
 function _keep_pattern()
index a3d97d6..40f3ec9 100644 (file)
@@ -17,7 +17,7 @@ $Id$
 <h2><%:a_s_flash%></h2>
 <p><%:a_s_flash_upgrade1%></p>
 <br />
-<% if sysupgrade and not ret then %>
+<% if sysupgrade and ret == nil then %>
 <form method="post" action="<%=REQUEST_URI%>" enctype="multipart/form-data">
        <div class="left"><%:a_s_flash_fwimage%>:</div>
        <div>
@@ -33,20 +33,14 @@ $Id$
                <input type="submit" value="<%:a_s_flash_fwupgrade%>" />
        </div>
 </form>
-<% elseif ret then %>
-       <p><%:a_s_flash_received%></p>
-       <p><%:a_s_flash_inprogress%></p>
-       
-<!-- <%=string.rep(" ", 2048)%> -->
-       <% %>
-       <% local ret = ret() 
-       if ret == 0 then %>
-<div class="ok"><%:a_s_flash_flashed%></div>
+<% elseif ret ~= nil then %>
+       <% if ret then %>
+<p><%:a_s_flash_received%></p>
+<p><%:a_s_flash_inprogress%></p>
        <% else %>
-<div class="error"><%:a_s_flash_flasherr%>! (<%:code%> <%=ret%>)</div> 
+<div class="error"><%:a_s_flash_flasherr%>! (<%=err%>)</div>   
        <% end %>
 <% else %>
 <div class="error"><%:a_s_flash_notimplemented%></div>
 <% end %>
 <%+footer%>
-<% if ret == 0 then luci.sys.reboot() end %>
index 6d16ef8..d68283c 100644 (file)
@@ -79,7 +79,7 @@ end
 function action_upgrade()
        require("luci.model.uci")
 
-       local ret  = nil
+       local ret, err
        local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
        local tmpfile = "/tmp/firmware.img"
        local broadcom = os.execute('grep brcm_ /lib/upgrade/platform.sh >/dev/null 2>&1') == 0
@@ -105,12 +105,11 @@ function action_upgrade()
        local keepcfg = keep_avail and luci.http.formvalue("keepcfg")
 
        if plat and fname then
-               ret = function()
-                       return luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
-               end
+               ret, err = luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
        end
 
-       luci.template.render("mini/upgrade", {sysupgrade=plat, ret=ret, keep_avail=keep_avail})
+       luci.template.render("admin_system/upgrade", {sysupgrade=plat,
+               ret=ret, err=err, keep_avail=keep_avail})
 end
 
 function _keep_pattern()
index a3d97d6..40f3ec9 100644 (file)
@@ -17,7 +17,7 @@ $Id$
 <h2><%:a_s_flash%></h2>
 <p><%:a_s_flash_upgrade1%></p>
 <br />
-<% if sysupgrade and not ret then %>
+<% if sysupgrade and ret == nil then %>
 <form method="post" action="<%=REQUEST_URI%>" enctype="multipart/form-data">
        <div class="left"><%:a_s_flash_fwimage%>:</div>
        <div>
@@ -33,20 +33,14 @@ $Id$
                <input type="submit" value="<%:a_s_flash_fwupgrade%>" />
        </div>
 </form>
-<% elseif ret then %>
-       <p><%:a_s_flash_received%></p>
-       <p><%:a_s_flash_inprogress%></p>
-       
-<!-- <%=string.rep(" ", 2048)%> -->
-       <% %>
-       <% local ret = ret() 
-       if ret == 0 then %>
-<div class="ok"><%:a_s_flash_flashed%></div>
+<% elseif ret ~= nil then %>
+       <% if ret then %>
+<p><%:a_s_flash_received%></p>
+<p><%:a_s_flash_inprogress%></p>
        <% else %>
-<div class="error"><%:a_s_flash_flasherr%>! (<%:code%> <%=ret%>)</div> 
+<div class="error"><%:a_s_flash_flasherr%>! (<%=err%>)</div>   
        <% end %>
 <% else %>
 <div class="error"><%:a_s_flash_notimplemented%></div>
 <% end %>
 <%+footer%>
-<% if ret == 0 then luci.sys.reboot() end %>