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

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

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

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

	echo -n "${hostname}" > "${newroot}/etc/hostname"
	sed -i "/^127.0.0.1/s/$/\t${hostname}/" "${newroot}/etc/hosts"
}