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

require("fs")

get = function (self)
	local f = io.popen("/bin/hostname")
	local n = f:read("*a") or "unknown"
	f:close()
	return cfe({value=n, label="Hostname"})
end


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

update_name = function(name)
	local success = true

	if success then
		fs.write_file("/etc/hostname", name.value.hostname.value)
		local f =  io.popen("/bin/hostname -F /etc/hostname")
		f:close()
	else
		name.errtxt = "Failed to set hostname"
	end

	return name
end