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

-- no initializer in model - use controller.init for that


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


set = function (self, name)
	local f = io.open ("/etc/hostname", "w")
	if f then
		f:write(name.value)
		f:close()
	end
	f =  io.popen("/bin/hostname -F /etc/hostname")
	f:close()
	return get(self)
end