2008-03-02 21:14:01 +00:00
|
|
|
#!@PREFIX@/sbin/runscript
|
2009-05-01 15:11:40 +01:00
|
|
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
2011-06-29 19:46:31 -04:00
|
|
|
# Released under the 2-clause BSD license.
|
2007-12-05 15:57:17 +00:00
|
|
|
|
|
|
|
extra_commands="reset"
|
2009-04-27 07:51:18 +00:00
|
|
|
: ${hostid_file:=/etc/hostid}
|
2007-12-05 15:57:17 +00:00
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
depend()
|
|
|
|
{
|
2009-02-11 17:42:14 +00:00
|
|
|
use root
|
2007-12-07 14:32:57 +00:00
|
|
|
before devd net
|
2012-01-25 11:42:32 -06:00
|
|
|
keyword -jail
|
2007-12-05 15:57:17 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
_set()
|
|
|
|
{
|
2007-12-05 15:57:17 +00:00
|
|
|
local id=0
|
|
|
|
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
id=$(echo "$1" | md5)
|
|
|
|
id="0x${id%????????????????????????}"
|
|
|
|
fi
|
2009-04-27 07:51:18 +00:00
|
|
|
ebegin "Setting Host ID: $id"
|
|
|
|
sysctl -w kern.hostid="$id" >/dev/null
|
2008-01-10 23:48:53 +00:00
|
|
|
eend $? || return 1
|
|
|
|
|
|
|
|
if sysctl -n kern.hostuuid >/dev/null 2>&1; then
|
|
|
|
[ -n "$1" ] && id=$1
|
2009-04-27 07:51:18 +00:00
|
|
|
ebegin "Setting Host UUID: $id"
|
|
|
|
sysctl kern.hostuuid="$id" >/dev/null
|
2008-01-10 23:48:53 +00:00
|
|
|
eend $? || return 1
|
|
|
|
fi
|
|
|
|
|
2007-12-05 15:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# First we check to see if there is a system UUID
|
|
|
|
# If so then we use that and erase the hostid file,
|
|
|
|
# otherwise we generate a random UUID.
|
2008-01-11 12:13:46 +00:00
|
|
|
reset()
|
|
|
|
{
|
2009-04-27 07:51:18 +00:00
|
|
|
local uuid= x="[0-9a-f]" y="$x$x$x$x"
|
2008-10-03 17:50:30 +00:00
|
|
|
|
|
|
|
if type kenv >/dev/null 2>&1; then
|
|
|
|
uuid=$(kenv smbios.system.uuid 2>/dev/null)
|
|
|
|
fi
|
2009-04-27 07:51:18 +00:00
|
|
|
case "$uuid" in
|
|
|
|
$y$y-$y-$y-$y-$y$y$y);;
|
2007-12-05 15:57:17 +00:00
|
|
|
*) uuid=;;
|
|
|
|
esac
|
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ -n "$uuid" ]; then
|
|
|
|
rm -f "$hostid_file"
|
2007-12-05 15:57:17 +00:00
|
|
|
else
|
|
|
|
uuid=$(uuidgen)
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ -z "$uuid" ]; then
|
2007-12-05 15:57:17 +00:00
|
|
|
eerror "Unable to generate a UUID"
|
|
|
|
return 1
|
|
|
|
fi
|
2009-04-27 07:51:18 +00:00
|
|
|
if ! echo "$uuid" >"$hostid_file"; then
|
|
|
|
eerror "Failed to store UUID in \`$hostid_file'"
|
2007-12-05 15:57:17 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
_set "$uuid"
|
2007-12-05 15:57:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start()
|
|
|
|
{
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ -r "$hostid_file" ]; then
|
2011-01-17 04:49:07 -05:00
|
|
|
_set $(cat "$hostid_file")
|
2007-12-05 15:57:17 +00:00
|
|
|
else
|
|
|
|
reset
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
stop()
|
|
|
|
{
|
2007-12-05 15:57:17 +00:00
|
|
|
_set
|
|
|
|
}
|