-
- -- Determine state
- local keep_avail = true
- local step = tonumber(luci.http.formvalue("step") or 1)
- local has_image = nixio.fs.access(tmpfile)
- local has_support = image_supported()
- local has_platform = nixio.fs.access("/lib/upgrade/platform.sh")
- local has_upload = luci.http.formvalue("image")
-
- -- This does the actual flashing which is invoked inside an iframe
- -- so don't produce meaningful errors here because the the
- -- previous pages should arrange the stuff as required.
- if step == 4 then
- if has_platform and has_image and has_support then
- -- Mimetype text/plain
- luci.http.prepare_content("text/plain")
- luci.http.write("Starting sysupgrade...\n")
-
- io.flush()
-
- -- Now invoke sysupgrade
- local keepcfg = keep_avail and luci.http.formvalue("keepcfg") == "1"
- local flash = ltn12_popen("/sbin/sysupgrade %s %q" %{
- keepcfg and "" or "-n", tmpfile
+ if luci.http.formvalue("backup") then
+ --
+ -- Assemble file list, generate backup
+ --
+ local reader = ltn12_popen(backup_cmd)
+ luci.http.header('Content-Disposition', 'attachment; filename="backup-%s-%s.tar.gz"' % {
+ luci.sys.hostname(), os.date("%Y-%m-%d")})
+ luci.http.prepare_content("application/x-targz")
+ luci.ltn12.pump.all(reader, luci.http.write)
+ elseif luci.http.formvalue("restore") then
+ --
+ -- Unpack received .tar.gz
+ --
+ local upload = luci.http.formvalue("archive")
+ if upload and #upload > 0 then
+ luci.template.render("admin_system/applyreboot")
+ luci.sys.reboot()
+ end
+ elseif luci.http.formvalue("image") or luci.http.formvalue("step") then
+ --
+ -- Initiate firmware flash
+ --
+ local step = tonumber(luci.http.formvalue("step") or 1)
+ if step == 1 then
+ if image_supported() then
+ luci.template.render("admin_system/upgrade", {
+ checksum = image_checksum(),
+ storage = storage_size(),
+ size = nixio.fs.stat(image_tmp).size,
+ keep = (not not luci.http.formvalue("keep"))
+ })
+ else
+ nixio.fs.unlink(image_tmp)
+ luci.template.render("admin_system/flashops", {
+ reset_avail = reset_avail,
+ upgrade_avail = upgrade_avail,
+ image_invalid = true
+ })
+ end
+ --
+ -- Start sysupgrade flash
+ --
+ elseif step == 2 then
+ local keep = (luci.http.formvalue("keep") == "1") and "" or "-n"
+ luci.template.render("admin_system/applyreboot", {
+ title = luci.i18n.translate("Flashing..."),
+ msg = luci.i18n.translate("The system is flashing now.<br /> DO NOT POWER OFF THE DEVICE!<br /> Wait a few minutes until 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 = (#keep > 0) and "192.168.1.1" or nil