summaryrefslogtreecommitdiffstats
path: root/hostname-model.lua
blob: 11aacae9b45867a6782b070b0c7d314309a3df02 (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
-- hostname model methods
module (..., package.seeall)

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

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


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

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