2013-12-21 14:51:11 -06:00
|
|
|
#!@SBINDIR@/openrc-run
|
2015-12-04 16:52:19 -06:00
|
|
|
# Copyright (c) 2007-2015 The OpenRC Authors.
|
|
|
|
# See the Authors file at the top-level directory of this distribution and
|
|
|
|
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
|
|
|
#
|
|
|
|
# This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
# the LICENSE file found in the top-level directory of this
|
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
2007-11-14 15:22:04 +00:00
|
|
|
|
2007-07-10 19:09:41 +00:00
|
|
|
description="Sets the hostname of the machine."
|
|
|
|
|
2017-06-10 03:05:09 +01:00
|
|
|
depend()
|
|
|
|
{
|
2017-03-16 10:16:39 -05:00
|
|
|
after clock
|
2016-07-31 13:01:17 -05:00
|
|
|
keyword -docker -lxc -prefix -systemd-nspawn
|
2008-03-02 21:13:21 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
start()
|
|
|
|
{
|
2016-08-23 13:22:19 -05:00
|
|
|
local h source x
|
2017-12-14 17:07:31 -06:00
|
|
|
if [ -s /etc/hostname ] && [ -r /etc/hostname ]; then
|
|
|
|
read h x </etc/hostname
|
|
|
|
source="from /etc/hostname"
|
2016-08-23 13:22:19 -05:00
|
|
|
else
|
|
|
|
# HOSTNAME variable used to be defined in caps in conf.d/hostname.
|
|
|
|
# It is also a magic variable in bash.
|
2017-06-10 03:12:49 +01:00
|
|
|
h=${hostname:-${HOSTNAME}} # checkbashisms: false positive (HOSTNAME var)
|
2016-08-24 13:43:11 -05:00
|
|
|
fi
|
|
|
|
if [ -z "$h" ]; then
|
|
|
|
einfo "Using default system hostname"
|
|
|
|
return 0
|
2016-08-23 13:22:19 -05:00
|
|
|
fi
|
|
|
|
ebegin "Setting hostname to $h $source"
|
|
|
|
hostname "$h"
|
2007-04-05 11:18:42 +00:00
|
|
|
eend $? "Failed to set the hostname"
|
|
|
|
}
|