Improved hostname, added manpage

Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
Łukasz Magiera 2015-02-19 17:12:23 +01:00
parent 9e4b29b4cf
commit cba88c7066
No known key found for this signature in database
GPG Key ID: DAF1D53BBD4D4790
2 changed files with 24 additions and 6 deletions

View File

@ -1,14 +1,20 @@
local args = {...}
if args[1] then
local file = io.open("/etc/hostname", "w")
file:write(args[1])
file:close()
os.setenv("HOSTNAME", args[1])
os.setenv("PS1", "$HOSTNAME:$PWD# ")
local file, reason = io.open("/etc/hostname", "w")
if not file then
io.stderr:write(reason .. "\n")
else
file:write(args[1])
file:close()
os.setenv("HOSTNAME", args[1])
os.setenv("PS1", "$HOSTNAME:$PWD# ")
end
else
local file = io.open("/etc/hostname")
if file then
io.write(file:read("*l"))
io.write(file:read("*l"), "\n")
file:close()
else
io.stderr:write("Hostname not set\n")
end
end

View File

@ -0,0 +1,12 @@
NAME
hostname - Display and modify hostname
SYNOPIS
hostname [NEW NAME]
EXAMPLES
hostname
Prints currently set hostname
hostname test
Sets hostname of this computer to test