]> git.ipfire.org Git - network.git/commitdiff
Add support to set the hostname.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Apr 2011 12:20:16 +0000 (12:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Apr 2011 12:20:16 +0000 (12:20 +0000)
Compatible with systemd.

functions.cli
functions.constants
functions.util
network

index a2ceb99e42df525c881fd3af9fcaeff95d69a550..82a9c6f4a0edf7077df726d6bc5192bb396669ec 100644 (file)
@@ -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
index efca1467216c7a5528c9227f6e0bf33743183894..5de3f7e9e766986d7318a1b8090e124c5abac861 100644 (file)
@@ -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
 
index e63cb76e4902acce4437945f53bedae30df6123e..7ff209404ec614d2ee078723c4c7f96187a52d2f 100644 (file)
@@ -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 2309848272c0eb1758d95482ccddd394a8c1b6a4..e84adff9e953eefbb9675a7681995f0031af6bc7 100755 (executable)
--- 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} $@
                ;;