summaryrefslogtreecommitdiffstats
path: root/hostname-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'hostname-model.lua')
-rw-r--r--hostname-model.lua26
1 files changed, 16 insertions, 10 deletions
diff --git a/hostname-model.lua b/hostname-model.lua
index ba0c117..7d4238e 100644
--- a/hostname-model.lua
+++ b/hostname-model.lua
@@ -1,24 +1,30 @@
-- hostname model methods
module (..., package.seeall)
--- no initializer in model - use controller.init for that
-
+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"})
+ 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
-set = function (self, name)
- local f = io.open ("/etc/hostname", "w")
- if f then
- f:write(name.value)
+ 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
- f = io.popen("/bin/hostname -F /etc/hostname")
- f:close()
- return get(self)
+
+ return name
end