From: Michael Tremer Date: Sat, 30 Apr 2011 12:20:16 +0000 (+0000) Subject: Add support to set the hostname. X-Git-Tag: 001~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31e59f2bd2da11cf3b3fa52b1721b88c6fc55d6f;p=network.git Add support to set the hostname. Compatible with systemd. --- diff --git a/functions.cli b/functions.cli index a2ceb99e..82a9c6f4 100644 --- a/functions.cli +++ b/functions.cli @@ -132,6 +132,25 @@ function cli_device_discover() { [ "${up}" = "1" ] || device_set_down ${device} } +function cli_hostname() { + if cli_help_requested $@; then + cli_usage hostname + exit ${EXIT_OK} + fi + + local hostname=${1} + + if [ -n "${hostname}" ]; then + config_hostname ${hostname} + log INFO "Hostname was set to '${hostname}'." + log INFO "Changes do only take affect after reboot." + exit ${EXIT_OK} + fi + + echo "$(config_hostname)" + exit ${EXIT_OK} +} + function cli_port() { if cli_help_requested $@; then cli_usage root-port diff --git a/functions.constants b/functions.constants index efca1467..5de3f7e9 100644 --- a/functions.constants +++ b/functions.constants @@ -34,6 +34,7 @@ PPP_SECRETS=/etc/ppp/secrets CONFIG_FILE=${CONFIG_DIR}/network_config CONFIG_FILE_PARAMS="COLOURS DEBUG SHELL TIMEOUT_RESTART" +CONFIG_HOSTNAME="/etc/hostname" RED_DB_DIR=${RUN_DIR}/red diff --git a/functions.util b/functions.util index e63cb76e..7ff20940 100644 --- a/functions.util +++ b/functions.util @@ -132,6 +132,16 @@ function config_check() { [ -n "$(type -t _check)" ] && _check } +function config_hostname() { + local hostname=${1} + + if [ -n "${hostname}" ]; then + echo "${hostname}" > ${CONFIG_HOSTNAME} + else + echo "$(<${CONFIG_HOSTNAME})" + fi +} + function network_config_set() { while [ $# -gt 0 ]; do case "${1}" in diff --git a/network b/network index 23098482..e84adff9 100755 --- a/network +++ b/network @@ -42,7 +42,7 @@ case "${action}" in init_run ;; - config|port|device|zone|start|stop|restart|status|reset) + config|hostname|port|device|zone|start|stop|restart|status|reset) cli_${action} $@ ;;