gluon/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua

36 lines
1.2 KiB
Lua
Raw Normal View History

return function(form, uci)
2018-02-23 05:26:10 +00:00
local pkg_i18n = i18n 'gluon-config-mode-hostname'
local site_i18n = i18n 'gluon-site'
2018-02-23 05:26:10 +00:00
local pretty_hostname = require 'pretty_hostname'
local site = require 'gluon.site'
local util = require 'gluon.util'
local help = site_i18n._translate("gluon-config-mode:hostname-help") or pkg_i18n.translate(
'The node name is used solely for identification of your node, e.g. on a '
.. 'node map. It does not affect the name (SSID) of the broadcasted WLAN.'
)
form:section(Section, nil, help)
local current_hostname = pretty_hostname.get(uci)
local default_hostname = util.default_hostname()
2019-06-16 18:06:45 +00:00
local configured = uci:get_first('gluon-setup-mode', 'setup_mode', 'configured', false) or
(current_hostname ~= default_hostname)
local s = form:section(Section)
2018-02-23 05:26:10 +00:00
local o = s:option(Value, "hostname", pkg_i18n.translate("Node name"))
o.datatype = 'minlength(1)'
if site.config_mode.hostname.optional(true) then
o.optional = true
o.placeholder = default_hostname
end
if configured or site.config_mode.hostname.prefill(true) then
o.default = current_hostname
end
function o:write(data)
pretty_hostname.set(uci, data or default_hostname)
uci:save('system')
end
end