xref: /freebsd-14.2/libexec/rc/rc.d/hostid_save (revision d0b2dbfa)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb#
40696600cSBjoern A. Zeeb
50696600cSBjoern A. Zeeb# PROVIDE: hostid_save
60696600cSBjoern A. Zeeb# REQUIRE: hostid root
70696600cSBjoern A. Zeeb# KEYWORD: nojail
80696600cSBjoern A. Zeeb
90696600cSBjoern A. Zeeb. /etc/rc.subr
100696600cSBjoern A. Zeeb
110696600cSBjoern A. Zeebname="hostid_save"
120696600cSBjoern A. Zeebdesc="Save unique host ID to disk"
130696600cSBjoern A. Zeebstart_cmd="hostid_save"
140696600cSBjoern A. Zeebstop_cmd=":"
150696600cSBjoern A. Zeebrcvar="hostid_enable"
160696600cSBjoern A. Zeeb
17*ecad3f5cSTijl Coosemanshostid_machine_id()
18*ecad3f5cSTijl Coosemans{
19*ecad3f5cSTijl Coosemans	local IFS
20*ecad3f5cSTijl Coosemans
21*ecad3f5cSTijl Coosemans	IFS=-
22*ecad3f5cSTijl Coosemans	set -- ${current_hostid}
23*ecad3f5cSTijl Coosemans	IFS=
24*ecad3f5cSTijl Coosemans	current_machine_id=$*
25*ecad3f5cSTijl Coosemans}
26*ecad3f5cSTijl Coosemans
270696600cSBjoern A. Zeebhostid_save()
280696600cSBjoern A. Zeeb{
290696600cSBjoern A. Zeeb	current_hostid=`$SYSCTL_N kern.hostuuid`
300696600cSBjoern A. Zeeb
31*ecad3f5cSTijl Coosemans	read saved_hostid 2>/dev/null < ${hostid_file}
32*ecad3f5cSTijl Coosemans	if [ "${saved_hostid}" != "${current_hostid}" ]; then
33*ecad3f5cSTijl Coosemans		echo "${current_hostid}" > ${hostid_file} ||
34*ecad3f5cSTijl Coosemans			warn "could not store hostuuid in ${hostid_file}."
350696600cSBjoern A. Zeeb	fi
360696600cSBjoern A. Zeeb
37*ecad3f5cSTijl Coosemans	hostid_machine_id
38*ecad3f5cSTijl Coosemans
39*ecad3f5cSTijl Coosemans	read saved_machine_id 2>/dev/null < ${machine_id_file}
40*ecad3f5cSTijl Coosemans	if [ "${saved_machine_id}" != "${current_machine_id}" ]; then
41*ecad3f5cSTijl Coosemans		echo "${current_machine_id}" > ${machine_id_file} ||
42*ecad3f5cSTijl Coosemans			warn "could not store hostuuid in ${machine_id_file}."
430696600cSBjoern A. Zeeb	fi
440696600cSBjoern A. Zeeb}
450696600cSBjoern A. Zeeb
460696600cSBjoern A. Zeebload_rc_config $name
470696600cSBjoern A. Zeebrun_rc_command "$1"
48