| 1 |
#!/sbin/runscript
|
| 2 |
# Copyright 1999-2005 Gentoo Foundation
|
| 3 |
# Distributed under the terms of the GNU General Public License v2
|
| 4 |
|
| 5 |
depend() {
|
| 6 |
need checkroot
|
| 7 |
}
|
| 8 |
|
| 9 |
start() {
|
| 10 |
local myhost=$(/bin/hostname 2>/dev/null)
|
| 11 |
local retval=0
|
| 12 |
|
| 13 |
# If the hostname is already set via the kernel, and /etc/hostname
|
| 14 |
# isn't setup, then we shouldn't go reseting the configuration #38172.
|
| 15 |
if [[ -z ${myhost} ]] || [[ ${myhost} == "(none)" ]] ; then
|
| 16 |
myhost="localhost"
|
| 17 |
fi
|
| 18 |
|
| 19 |
if [[ -f /etc/hostname ]] ; then
|
| 20 |
ewarn "You should stop using /etc/hostname and use /etc/conf.d/hostname"
|
| 21 |
myhost=$(</etc/hostname)
|
| 22 |
else
|
| 23 |
myhost=${HOSTNAME}
|
| 24 |
fi
|
| 25 |
|
| 26 |
ebegin "Setting hostname to ${myhost}"
|
| 27 |
/bin/hostname "${myhost}"
|
| 28 |
retval=$?
|
| 29 |
eend ${retval} "Failed to set the hostname"
|
| 30 |
|
| 31 |
if [[ ${retval} -eq 0 ]] ; then
|
| 32 |
# setup $HOSTNAME, ignore errors in case /etc is readonly.
|
| 33 |
echo "HOSTNAME=\"${myhost}\"" 2>/dev/null > /etc/env.d/01hostname
|
| 34 |
fi
|
| 35 |
|
| 36 |
return ${retval}
|
| 37 |
}
|
| 38 |
|
| 39 |
# vim:ts=4
|