xref: /freebsd/libexec/rc/rc.d/hostid_save (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: hostid_save
7# REQUIRE: hostid root
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="hostid_save"
13desc="Save unique host ID to disk"
14start_cmd="hostid_save"
15stop_cmd=":"
16rcvar="hostid_enable"
17
18hostid_save()
19{
20	current_hostid=`$SYSCTL_N kern.hostuuid`
21
22	if [ -r ${hostid_file} ]; then
23		read saved_hostid < ${hostid_file}
24		if [ ${saved_hostid} = ${current_hostid} ]; then
25			exit 0
26		fi
27	fi
28
29	echo ${current_hostid} > ${hostid_file}
30	if [ $? -ne 0 ]; then
31		warn "could not store hostuuid in ${hostid_file}."
32	fi
33}
34
35load_rc_config $name
36run_rc_command "$1"
37