xref: /freebsd/libexec/rc/rc.d/hostid_save (revision 9bc300465e48e19d794d88d0c158a2adb92c7197)
1#!/bin/sh
2#
3#
4
5# PROVIDE: hostid_save
6# REQUIRE: hostid root
7# KEYWORD: nojail
8
9. /etc/rc.subr
10
11name="hostid_save"
12desc="Save unique host ID to disk"
13start_cmd="hostid_save"
14stop_cmd=":"
15rcvar="hostid_enable"
16
17hostid_machine_id()
18{
19	local IFS
20
21	IFS=-
22	set -- ${current_hostid}
23	IFS=
24	current_machine_id=$*
25}
26
27hostid_save()
28{
29	current_hostid=`$SYSCTL_N kern.hostuuid`
30
31	read saved_hostid 2>/dev/null < ${hostid_file}
32	if [ "${saved_hostid}" != "${current_hostid}" ]; then
33		echo "${current_hostid}" > ${hostid_file} ||
34			warn "could not store hostuuid in ${hostid_file}."
35	fi
36
37	hostid_machine_id
38
39	read saved_machine_id 2>/dev/null < ${machine_id_file}
40	if [ "${saved_machine_id}" != "${current_machine_id}" ]; then
41		echo "${current_machine_id}" > ${machine_id_file} ||
42			warn "could not store hostuuid in ${machine_id_file}."
43	fi
44}
45
46load_rc_config $name
47
48# doesn't make sense to run in a svcj: config setting
49hostid_save_svcj="NO"
50
51run_rc_command "$1"
52