aboutsummaryrefslogtreecommitdiffstats
path: root/hook/hostname
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-05-27 11:44:04 +0200
committerGravatar Christian Hesse <mail@eworm.de>2013-05-27 11:44:04 +0200
commitf4acbd06fd8dbfb52b8d3f4b0b93be04a1130af7 (patch)
tree54116435a3c5471cd492a7885efea0728b93bc4e /hook/hostname
parentacc15c936077c3ca163d651b7714a00c4e446deb (diff)
downloadmkinitcpio-hostname-f4acbd06fd8dbfb52b8d3f4b0b93be04a1130af7.tar.gz
mkinitcpio-hostname-f4acbd06fd8dbfb52b8d3f4b0b93be04a1130af7.tar.zst
Initial import0.1.0
Diffstat (limited to 'hook/hostname')
-rw-r--r--hook/hostname17
1 files changed, 17 insertions, 0 deletions
diff --git a/hook/hostname b/hook/hostname
new file mode 100644
index 0000000..6421987
--- /dev/null
+++ b/hook/hostname
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+run_latehook() {
+ local newroot="/new_root/"
+ 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"
+}