hostname revision 166620
1113674Smtm#!/bin/sh 2113674Smtm# 3113674Smtm# Copyright (c) 2003 The FreeBSD Project. All rights reserved. 4113674Smtm# 5113674Smtm# Redistribution and use in source and binary forms, with or without 6113674Smtm# modification, are permitted provided that the following conditions 7113674Smtm# are met: 8113674Smtm# 1. Redistributions of source code must retain the above copyright 9113674Smtm# notice, this list of conditions and the following disclaimer. 10113674Smtm# 2. Redistributions in binary form must reproduce the above copyright 11113674Smtm# notice, this list of conditions and the following disclaimer in the 12113674Smtm# documentation and/or other materials provided with the distribution. 13113674Smtm# 14113674Smtm# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 15113674Smtm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16113674Smtm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17113674Smtm# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 18113674Smtm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19113674Smtm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20113674Smtm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21113674Smtm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22113674Smtm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23113674Smtm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24113674Smtm# SUCH DAMAGE. 25113674Smtm# 26113674Smtm# $FreeBSD: head/etc/rc.d/hostname 166620 2007-02-10 13:13:32Z yar $ 27113674Smtm# 28113674Smtm 29113674Smtm# PROVIDE: hostname 30118219Smtm# REQUIRE: mountcritlocal 31113674Smtm# BEFORE: netif 32113674Smtm 33113674Smtm. /etc/rc.subr 34113674Smtm 35113674Smtmname="hostname" 36113674Smtmstart_cmd="hostname_start" 37113674Smtmstop_cmd=":" 38113674Smtm 39113674Smtmhostname_start() 40113674Smtm{ 41126647Spjd # If we are not inside a jail, set the host name if it is not already set. 42126647Spjd # If we are inside a jail, set the host name even if it is already set, 43126647Spjd # but first check if it is permitted. 44113674Smtm # 45126647Spjd if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then 46126647Spjd if [ `$SYSCTL_N security.jail.set_hostname_allowed` -eq 0 ]; then 47126647Spjd return 48126647Spjd fi 49127744Skrion elif [ -n "`/bin/hostname -s`" ]; then 50126648Spjd return 51127345Sbrooks else 52127345Sbrooks # If we're not in a jail and rc.conf doesn't specify a 53127345Sbrooks # hostname, see if we can get one from kenv. 54127345Sbrooks # 55127345Sbrooks if [ -z "${hostname}" -a \ 56127345Sbrooks -n "`/bin/kenv dhcp.host-name 2> /dev/null`" ]; then 57127345Sbrooks hostname=`/bin/kenv dhcp.host-name` 58127345Sbrooks fi 59113674Smtm fi 60126647Spjd 61166620Syar # Have we got a hostname yet? 62166620Syar # 63166620Syar if [ -z "${hostname}" ]; then 64166620Syar warn "\$hostname is not set -- see ${rcvar_manpage}." 65166620Syar return 66166620Syar fi 67166620Syar 68166620Syar # All right, it is safe to invoke hostname(1) now. 69166620Syar # 70166620Syar /bin/hostname "${hostname}" 71126647Spjd echo "Setting hostname: `hostname`." 72113674Smtm} 73113674Smtm 74113674Smtmload_rc_config $name 75113674Smtmrun_rc_command "$1" 76