#!/sbin/runscript
# Copyright 1999-2002 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.10 2002/11/18 13:07:02 azarah Exp $


depend() {
	need checkroot
}

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

start() {
	local myhost=""
	retval=0
	if ! checkconfig
	then
		myhost="localhost"
	else
		myhost="$(cat /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
