aboutsummaryrefslogtreecommitdiffstats
path: root/hook/hostname
blob: 7b6e331001f8a02a64855950df6772eb2da23a66 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh

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

	/usr/bin/systemd-machine-id-setup --root="${newroot}"

	hostprefix="$(cat "${newroot}/etc/hostname")"

	if [[ -n "${hostname}" ]]; then
		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"
}