aboutsummaryrefslogtreecommitdiffstats
#!/bin/sh

run_latehook() {
	local newroot="/new_root/"

	if [[ ! -s "${newroot}/etc/hostprefix" ]]; then
		cp "${newroot}/etc/hostname" "${newroot}/etc/hostprefix"
	fi
	hostprefix="$(cat "${newroot}/etc/hostprefix")"

	if [[ -n "${hostname}" ]]; then
		hostname="${hostname%%.*}"
		msg ":: Setting hostname for main system to '${hostprefix}-${hostname}'..."
	elif [[ -e /sys/class/dmi/id/product_uuid ]]; then
		msg ":: Setting hostname from product uuid..."
		hostname="$(sha1sum < /sys/class/dmi/id/product_uuid | cut -c1-8)"
	else
		msg ":: Setting hostname to random string..."
		hostname="$(cut -d- -f1 < /proc/sys/kernel/random/boot_id)"
	fi

	echo -n "${hostprefix}-${hostname}" > "${newroot}/etc/hostname"
}