index.lua 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --[[
  2. Copyright 2013 Nils Schneider <nils@nilsschneider.net>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. $Id$
  8. ]]--
  9. module("luci.controller.gluon-config-mode.index", package.seeall)
  10. function index()
  11. local uci_state = luci.model.uci.cursor_state()
  12. if uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0") == "1" then
  13. local root = node()
  14. if not root.target then
  15. root.target = alias("gluon-config-mode")
  16. root.index = true
  17. end
  18. page = node()
  19. page.lock = true
  20. page.target = alias("gluon-config-mode")
  21. page.subindex = true
  22. page.index = false
  23. page = node("gluon-config-mode")
  24. page.title = _("Wizard")
  25. page.target = alias("gluon-config-mode", "wizard")
  26. page.order = 5
  27. page.setuser = "root"
  28. page.setgroup = "root"
  29. page.index = true
  30. entry({"gluon-config-mode", "wizard"}, form("gluon-config-mode/wizard")).index = true
  31. entry({"gluon-config-mode", "reboot"}, call("action_reboot"))
  32. end
  33. end
  34. function action_reboot()
  35. local uci = luci.model.uci.cursor()
  36. uci:set("gluon-setup-mode", uci:get_first("gluon-setup-mode", "setup_mode"), "configured", "1")
  37. uci:save("gluon-setup-mode")
  38. uci:commit("gluon-setup-mode")
  39. local fs = require "nixio.fs"
  40. local util = require "nixio.util"
  41. local parts_dir = "/lib/gluon/config-mode/reboot/"
  42. local files = util.consume(fs.dir(parts_dir))
  43. table.sort(files)
  44. local parts = {}
  45. for _, entry in ipairs(files) do
  46. if entry:sub(1, 1) ~= '.' then
  47. local f = dofile(parts_dir .. '/' .. entry)
  48. if f ~= nil then
  49. table.insert(parts, f)
  50. end
  51. end
  52. end
  53. local hostname = uci:get_first("system", "system", "hostname")
  54. luci.template.render("gluon/config-mode/reboot",
  55. {
  56. parts = parts,
  57. hostname = hostname,
  58. }
  59. )
  60. if nixio.fork() == 0 then
  61. -- Replace stdout with /dev/null
  62. nixio.dup(nixio.open('/dev/null', 'w'), nixio.stdout)
  63. -- Sleep a little so the browser can fetch everything required to
  64. -- display the reboot page, then reboot the device.
  65. nixio.nanosleep(1)
  66. nixio.execp("reboot")
  67. end
  68. end