+ -- Determine state
+ local keep_avail = true
+ local step = tonumber(luci.http.formvalue("step") or 1)
+ local has_image = luci.fs.access(tmpfile)
+ local has_support = image_supported()
+ local has_platform = luci.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
+ -- 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" %{
+ keepcfg and "-k %q" % _keep_pattern() or "", tmpfile
+ })
+
+ -- Make sure the device is rebooted
+ luci.sys.reboot()
+ end