blob: 87b3b5f99dfce23015768b91b26ef11927300b31 (
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
|
-- hostname model methods
module (..., package.seeall)
fs = require("acf.fs")
get = function (fqdn)
local f,n
if fqdn then
f = io.popen("/bin/hostname -f 2>/dev/null")
n = f:read("*a")
f:close()
end
if not n or n == "" then
f = io.popen("/bin/hostname")
n = f:read("*a") or "unknown"
f:close()
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)
local f = io.popen("/bin/hostname -F /etc/hostname")
f:close()
else
name.errtxt = "Failed to set hostname"
end
return name
end
|