modules/admin-full: fix status output of luci-flash with lucid
[project/luci.git] / modules / admin-full / luasrc / controller / admin / system.lua
index 6031034..9f66f17 100644 (file)
@@ -2,6 +2,7 @@
 LuCI - Lua Configuration Interface
 
 Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008-2009 Jo-Philipp Wich <xm@subsignal.org>
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
@@ -31,7 +32,7 @@ function index()
        end
 
        entry({"admin", "system", "backup"}, call("action_backup"), i18n("a_s_backup"), 70)
-       entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("a_s_flash"), 80)
+       entry({"admin", "system", "upgrade"}, call("action_upgrade"), i18n("admin_upgrade"), 80)
        entry({"admin", "system", "reboot"}, call("action_reboot"), i18n("reboot"), 90)
 end
 
@@ -39,6 +40,7 @@ function action_packages()
        local ipkg = require("luci.model.ipkg")
        local void = nil
        local submit = luci.http.formvalue("submit")
+       local changes = false
        
        
        -- Search query
@@ -56,6 +58,7 @@ function action_packages()
                        install = {}
                end
                install[url] = 1
+               changes = true
        end
        
        -- Do install
@@ -63,6 +66,7 @@ function action_packages()
                for k, v in pairs(install) do
                        void, install[k] = ipkg.install(k)
                end
+               changes = true
        end
        
        
@@ -71,7 +75,8 @@ function action_packages()
        if remove then  
                for k, v in pairs(remove) do
                        void, remove[k] = ipkg.remove(k)
-               end     
+               end
+               changes = true
        end
        
        
@@ -115,7 +120,12 @@ function action_packages()
        end 
        
        luci.template.render("admin_system/packages", {pkgs=pkgs, query=query,
-        install=install, remove=remove, update=update, upgrade=upgrade})       
+        install=install, remove=remove, update=update, upgrade=upgrade})
+        
+       -- Remove index cache
+       if changes then
+               luci.fs.unlink("/tmp/luci-indexcache")
+       end     
 end
 
 function action_backup()
@@ -213,6 +223,14 @@ function action_upgrade()
                                        break
                                end
                        end
+               elseif luci.fs.access("/proc/partitions") then
+                       for l in io.lines("/proc/partitions") do
+                               local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)')
+                               if b and n and not n:match('[0-9]') then
+                                       size = tonumber(b) * 1024
+                                       break
+                               end
+                       end
                end
                return size
        end
@@ -248,15 +266,21 @@ function action_upgrade()
        -- previous pages should arrange the stuff as required.
        if step == 4 then
                if has_platform and has_image and has_support then
-                       -- Next line is to bypass luci.http layer
-                       luci.http.context.eoh = true
-
                        -- Now invoke sysupgrade
                        local keepcfg = keep_avail and luci.http.formvalue("keepcfg") == "1"
-                       os.execute("/sbin/luci-flash %s %q" %{
+                       local fd = io.popen("/sbin/luci-flash %s %q" %{
                                keepcfg and "-k %q" % _keep_pattern() or "", tmpfile
                        })
 
+                       if fd then
+                               while true do
+                                       local ln = fd:read("*l")
+                                       if not ln then break end
+                                       luci.http.write(ln)
+                               end
+                               fd:close()
+                       end
+
                        -- Make sure the device is rebooted
                        luci.sys.reboot()
                end
@@ -278,7 +302,8 @@ function action_upgrade()
                luci.template.render("admin_system/upgrade", {
                        step=1,
                        bad_image=(has_image and not has_support or false),
-                       keepavail=keep_avail
+                       keepavail=keep_avail,
+                       supported=has_platform
                } )
 
        -- Step 2: present uploaded file, show checksum, confirmation