summaryrefslogtreecommitdiffstats
path: root/hostname-model.lua
blob: 8e20707a18149ca2a11dca76487b6d179796e145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- hostname model methods
local mymodule = {}

fs = require("acf.fs")
modelfunctions = require("modelfunctions")

mymodule.get = function (fqdn)
	local n
	if fqdn then
		n = modelfunctions.run_executable({"hostname", "-f"})
	end
	if not n or n == "" then
		n = modelfunctions.run_executable({"hostname"})
	end
	if not n or n == "" then
		n = "unknown"
	end

	return cfe({value=n, label="Hostname"})
end


mymodule.read_name = function ()
	return cfe({ type="group", value={hostname=mymodule.get(false)}, label="Hostname" })
end

mymodule.update_name = function(self, name)
	local success = true

	if success then
		fs.write_file("/etc/hostname", name.value.hostname.value)
		modelfunctions.run_executable({"hostname", "-F", "/etc/hostname"})
	else
		name.errtxt = "Failed to set hostname"
	end

	return name
end

return mymodule