hostname revision 127345
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 127345 2004-03-23 23:22:35Z brooks $ 27113674Smtm# 28113674Smtm 29113674Smtm# PROVIDE: hostname 30118219Smtm# REQUIRE: mountcritlocal 31113674Smtm# BEFORE: netif 32113674Smtm# KEYWORD: FreeBSD 33113674Smtm 34113674Smtm. /etc/rc.subr 35113674Smtm 36113674Smtmname="hostname" 37113674Smtmstart_cmd="hostname_start" 38113674Smtmstop_cmd=":" 39113674Smtm 40113674Smtmhostname_start() 41113674Smtm{ 42126647Spjd # If we are not inside a jail, set the host name if it is not already set. 43126647Spjd # If we are inside a jail, set the host name even if it is already set, 44126647Spjd # but first check if it is permitted. 45113674Smtm # 46126647Spjd if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then 47126647Spjd if [ `$SYSCTL_N security.jail.set_hostname_allowed` -eq 0 ]; then 48126647Spjd return 49126647Spjd fi 50126647Spjd elif [ -n "`hostname -s`" ]; then 51126648Spjd return 52127345Sbrooks else 53127345Sbrooks # If we're not in a jail and rc.conf doesn't specify a 54127345Sbrooks # hostname, see if we can get one from kenv. 55127345Sbrooks # 56127345Sbrooks if [ -z "${hostname}" -a \ 57127345Sbrooks -n "`/bin/kenv dhcp.host-name 2> /dev/null`" ]; then 58127345Sbrooks hostname=`/bin/kenv dhcp.host-name` 59127345Sbrooks fi 60113674Smtm fi 61126647Spjd 62126647Spjd hostname ${hostname} 63126647Spjd echo "Setting hostname: `hostname`." 64113674Smtm} 65113674Smtm 66113674Smtmload_rc_config $name 67113674Smtmrun_rc_command "$1" 68