#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2 
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/hostname,v 1.16 2003/05/04 23:16:31 azarah Exp $

# This only set what /bin/hostname returns.  If you need to setup NIS, meaning
# what /bin/domainname returns, please see:
#
#   http://www.linux-nis.org/nis-howto/HOWTO/
#
# To have a proper FQDN, you need to setup /etc/hosts and /etc/resolv.conf
# properly (domain entry in /etc/resolv.conf, and FQDN in /etc/hosts).


depend() {
	need checkroot
}

checkconfig() {
	if [ ! -f /etc/hostname ] || [ -z "$(< /etc/hostname)" ]
	then
		eerror "You need to set /etc/hostname to a valid hostname"
		return 1
	fi
}

start() {
	local myhost="localhost"
	local retval=0
	
	# We use whatever is in /etc/hostname here.  That means:
	#
	# 1)  For doing it the proper way, you should NOT put a
	#     FQDN in there, but:
	#     a) Only have the hostname in there (no dns/nis domainname)
	#     b) Set the dnsdomainname via /etc/resolv.conf
	#     c) Set the nisdomainname via 'domainname'.
	#
	# 2)  If the user want a FQDN in there, it should be possible
	#     without hacking things to pieces, but then he should
	#     know what he is doing ...
	#
	if checkconfig
	then
		myhost="$(< /etc/hostname)"
	fi
	
	ebegin "Setting hostname to ${myhost}"
	/bin/hostname "${myhost}"
	retval=$?
	eend ${retval} "Failed to set the hostname"
	
	if [ "${retval}" -eq 0 ]
	then
		# setup $HOSTNAME
		echo "HOSTNAME=\"${myhost}\"" > /etc/env.d/01hostname
	fi

	return ${retval}
}


# vim:ts=4
