modules/admin-*: Fixes for firmware upgrade and system reset

This commit is contained in:
Steven Barth 2008-08-03 16:33:49 +00:00
parent f26e93bead
commit 15facd9280
5 changed files with 17 additions and 7 deletions

View file

@ -2,7 +2,7 @@
. /etc/functions.sh . /etc/functions.sh
# initialize defaults # initialize defaults
RAMFS_COPY_BIN="" # extra programs for temporary ramfs root RAMFS_COPY_BIN="/usr/bin/awk" # extra programs for temporary ramfs root
RAMFS_COPY_DATA="" # extra data files RAMFS_COPY_DATA="" # extra data files
export KEEP_PATTERN="" export KEEP_PATTERN=""
export VERBOSE=1 export VERBOSE=1

View file

@ -155,7 +155,7 @@ function action_packages()
end end
function action_backup() function action_backup()
local reset_avail = luci.sys.exec([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0 local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1" local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1"
local backup_cmd = "tar -c %s | gzip 2>/dev/null" local backup_cmd = "tar -c %s | gzip 2>/dev/null"
@ -242,8 +242,11 @@ function action_upgrade()
local ret = nil local ret = nil
local plat = luci.fs.mtime("/lib/upgrade/platform.sh") local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
local broadcom = os.execute('grep brcm_ /lib/upgrade/platform.sh >/dev/null 2>&1') == 0
local tmpfile = "/tmp/firmware.img" local tmpfile = "/tmp/firmware.img"
local keep_avail = not broadcom
local file local file
luci.http.setfilehandler( luci.http.setfilehandler(
function(meta, chunk, eof) function(meta, chunk, eof)
@ -260,13 +263,13 @@ function action_upgrade()
) )
local fname = luci.http.formvalue("image") local fname = luci.http.formvalue("image")
local keepcfg = luci.http.formvalue("keepcfg") local keepcfg = keep_avail and luci.http.formvalue("keepcfg")
if plat and fname then if plat and fname then
ret = luci.sys.flash(tmpfile, keepcfg and _keep_pattern()) ret = luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
end end
luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret}) luci.template.render("admin_system/upgrade", {sysupgrade=plat, ret=ret, keep_avail=keep_avail})
end end
function _keep_pattern() function _keep_pattern()

View file

@ -24,8 +24,10 @@ $Id$
<input type="file" size="30" name="image" /> <input type="file" size="30" name="image" />
<br /> <br />
<br /> <br />
<% if keep_avail then -%>
<input type="checkbox" name="keepcfg" value="1" checked="checked" /> <input type="checkbox" name="keepcfg" value="1" checked="checked" />
<span class="bold"><%:a_s_flash_keepcfg%></span> <span class="bold"><%:a_s_flash_keepcfg%></span>
<% end -%>
</div> </div>
<div> <div>
<input type="submit" value="<%:a_s_flash_fwupgrade%>" /> <input type="submit" value="<%:a_s_flash_fwupgrade%>" />

View file

@ -28,7 +28,7 @@ function index()
end end
function action_backup() function action_backup()
local reset_avail = luci.sys.exec([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0 local reset_avail = os.execute([[grep '"rootfs_data"' /proc/mtd >/dev/null 2>&1]]) == 0
local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1" local restore_cmd = "gunzip | tar -xC/ >/dev/null 2>&1"
local backup_cmd = "tar -c %s | gzip 2>/dev/null" local backup_cmd = "tar -c %s | gzip 2>/dev/null"
@ -81,8 +81,11 @@ function action_upgrade()
local ret = nil local ret = nil
local plat = luci.fs.mtime("/lib/upgrade/platform.sh") local plat = luci.fs.mtime("/lib/upgrade/platform.sh")
local broadcom = os.execute('grep brcm_ /lib/upgrade/platform.sh >/dev/null 2>&1') == 0
local tmpfile = "/tmp/firmware.img" local tmpfile = "/tmp/firmware.img"
local keep_avail = not broadcom
local file local file
luci.http.setfilehandler( luci.http.setfilehandler(
function(meta, chunk, eof) function(meta, chunk, eof)
@ -99,13 +102,13 @@ function action_upgrade()
) )
local fname = luci.http.formvalue("image") local fname = luci.http.formvalue("image")
local keepcfg = luci.http.formvalue("keepcfg") local keepcfg = keep_avail and luci.http.formvalue("keepcfg")
if plat and fname then if plat and fname then
ret = luci.sys.flash(tmpfile, keepcfg and _keep_pattern()) ret = luci.sys.flash(tmpfile, keepcfg and _keep_pattern())
end end
luci.template.render("mini/upgrade", {sysupgrade=plat, ret=ret}) luci.template.render("mini/upgrade", {sysupgrade=plat, ret=ret, keep_avail=keep_avail})
end end
function action_passwd() function action_passwd()

View file

@ -24,8 +24,10 @@ $Id$
<input type="file" size="30" name="image" /> <input type="file" size="30" name="image" />
<br /> <br />
<br /> <br />
<% if keep_avail then -%>
<input type="checkbox" name="keepcfg" value="1" checked="checked" /> <input type="checkbox" name="keepcfg" value="1" checked="checked" />
<span class="bold"><%:a_s_flash_keepcfg%></span> <span class="bold"><%:a_s_flash_keepcfg%></span>
<% end -%>
</div> </div>
<div> <div>
<input type="submit" value="<%:a_s_flash_fwupgrade%>" /> <input type="submit" value="<%:a_s_flash_fwupgrade%>" />