From 9e4b29b4cf9334281f22d31a8941a748ce32e28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 19 Feb 2015 00:42:50 +0100 Subject: [PATCH] Added basic hostname mechanism to OpenOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ɓukasz Magiera --- .../opencomputers/loot/OpenOS/bin/hostname.lua | 14 ++++++++++++++ .../opencomputers/loot/OpenOS/boot/94_shell.lua | 11 ++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/opencomputers/loot/OpenOS/bin/hostname.lua diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/hostname.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/hostname.lua new file mode 100644 index 000000000..c3be4d110 --- /dev/null +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/hostname.lua @@ -0,0 +1,14 @@ +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# ") +else + local file = io.open("/etc/hostname") + if file then + io.write(file:read("*l")) + file:close() + end +end diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/94_shell.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/boot/94_shell.lua index e754143d7..1527af1ad 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/boot/94_shell.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/boot/94_shell.lua @@ -13,4 +13,13 @@ shell.setAlias("rs", "redstone") shell.setAlias("view", "edit -r") shell.setAlias("help", "man") shell.setAlias("?", "man") -shell.setAlias("cp", "cp -i") \ No newline at end of file +shell.setAlias("cp", "cp -i") + +event.listen("init", function() + local file = io.open("/etc/hostname") + if file then + os.setenv("HOSTNAME", file:read("*l")) + os.setenv("PS1", "$HOSTNAME:$PWD# ") + file:close() + end +end)