mirror of
https://github.com/opnsense/src.git
synced 2026-02-24 18:30:55 -05:00
rc.d/hostid_save saves a UUID generated by rc.d/hostid in /etc/hostid. Store the same UUID, without hyphens, in /etc/machine-id. The hypĥens are removed with a shell function because hostid_save runs before file systems are mounted so other tools may not be available yet. This eliminates some duplication between hostid and machine-id and for virtual machines machine-id now contains the UUID configured in the hypervisor like it does on Linux. Reviewed by: delphij Discussed with: bapt MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D38811
48 lines
889 B
Bash
Executable file
48 lines
889 B
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
|
|
# PROVIDE: hostid_save
|
|
# REQUIRE: hostid root
|
|
# KEYWORD: nojail
|
|
|
|
. /etc/rc.subr
|
|
|
|
name="hostid_save"
|
|
desc="Save unique host ID to disk"
|
|
start_cmd="hostid_save"
|
|
stop_cmd=":"
|
|
rcvar="hostid_enable"
|
|
|
|
hostid_machine_id()
|
|
{
|
|
local IFS
|
|
|
|
IFS=-
|
|
set -- ${current_hostid}
|
|
IFS=
|
|
current_machine_id=$*
|
|
}
|
|
|
|
hostid_save()
|
|
{
|
|
current_hostid=`$SYSCTL_N kern.hostuuid`
|
|
|
|
read saved_hostid 2>/dev/null < ${hostid_file}
|
|
if [ "${saved_hostid}" != "${current_hostid}" ]; then
|
|
echo "${current_hostid}" > ${hostid_file} ||
|
|
warn "could not store hostuuid in ${hostid_file}."
|
|
fi
|
|
|
|
hostid_machine_id
|
|
|
|
read saved_machine_id 2>/dev/null < ${machine_id_file}
|
|
if [ "${saved_machine_id}" != "${current_machine_id}" ]; then
|
|
echo "${current_machine_id}" > ${machine_id_file} ||
|
|
warn "could not store hostuuid in ${machine_id_file}."
|
|
fi
|
|
}
|
|
|
|
load_rc_config $name
|
|
run_rc_command "$1"
|