diff options
author | Luka Pivk <luka.pivk@toradex.com> | 2020-03-06 16:01:52 +0100 |
---|---|---|
committer | Luka Pivk <luka.pivk@toradex.com> | 2020-03-18 14:52:16 +0000 |
commit | 745a6d6da292280207d1b0d8a0662e49d3cbd8e6 (patch) | |
tree | 31de0d82438bc4a4187f8e109b46f2ee26324b01 /recipes-core/set-hostname/files/sethostname | |
parent | 47ef64803548f73a0eda753c5d3d3f7f315af606 (diff) |
hostname: generate a uniqe hostname on boot
This will generate a hostname based on machine name and serial number.
(E.g. colibri-imx7-031111777)
If serial number is not found it will say "no-serial-number" in host
name.
If machine is not supported hostname will include "unsupported-device"
string.
If /dev/device-tree does not exist it will say "recovery-mode"
as it assumes its in recovery mode of Toradex Easy Installer
To prevent openembedded from creating /etc/hostname file
add hostname_pn-base-files = "" to configration
Related-to: TEI-100, ELB-1322
Signed-off-by: Luka Pivk <luka.pivk@toradex.com>
Diffstat (limited to 'recipes-core/set-hostname/files/sethostname')
-rw-r--r-- | recipes-core/set-hostname/files/sethostname | 19 |
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 |