summaryrefslogtreecommitdiff
path: root/recipes-core/set-hostname/files/sethostname
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/set-hostname/files/sethostname')
-rw-r--r--recipes-core/set-hostname/files/sethostname19
1 files changed, 19 insertions, 0 deletions
diff --git a/recipes-core/set-hostname/files/sethostname b/recipes-core/set-hostname/files/sethostname
new file mode 100644
index 0000000..87e6320
--- /dev/null
+++ b/recipes-core/set-hostname/files/sethostname
@@ -0,0 +1,19 @@
+#!/bin/sh
+if [ ! -f /proc/device-tree/serial-number ]; then
+ serial="recovery-mode"
+else
+ serial=$(tr -d '\0' </proc/device-tree/serial-number)
+
+ #if serial number is empty we append no-serial-number string
+ if [ -z "$serial" -a "$serial" != " " ]; then
+ serial="no-serial-number"
+ fi
+fi
+
+hostname=@@MACHINE@@"-"${serial}
+
+if [ -f /usr/bin/hostnamectl ]; then
+ /usr/bin/hostnamectl set-hostname ${hostname}
+else
+ hostname ${hostname}
+fi