From bafd26a80d23c9d03d406122c713906226da3e47 Mon Sep 17 00:00:00 2001 From: chewitt Date: Mon, 2 May 2016 09:53:13 +0100 Subject: [PATCH] systemd: fix machine-id uniqueness --- packages/sysutils/busybox/package.mk | 2 +- .../systemd/scripts/systemd-machine-id-setup | 30 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/sysutils/busybox/package.mk b/packages/sysutils/busybox/package.mk index ead4e5bb99..338cd3c046 100644 --- a/packages/sysutils/busybox/package.mk +++ b/packages/sysutils/busybox/package.mk @@ -184,7 +184,7 @@ makeinstall_target() { touch $INSTALL/etc/fstab # /etc/machine-id, needed by systemd and dbus - ln -sf /run/machine-id $INSTALL/etc/machine-id + ln -sf /storage/.cache/machine-id $INSTALL/etc/machine-id # /etc/mtab is needed by udisks etc... ln -sf /proc/self/mounts $INSTALL/etc/mtab diff --git a/packages/sysutils/systemd/scripts/systemd-machine-id-setup b/packages/sysutils/systemd/scripts/systemd-machine-id-setup index 866f153eff..1fd53fa19e 100755 --- a/packages/sysutils/systemd/scripts/systemd-machine-id-setup +++ b/packages/sysutils/systemd/scripts/systemd-machine-id-setup @@ -17,21 +17,25 @@ # along with OpenELEC. If not, see . ################################################################################ -# Attempts to generate a unique machine ID based on one local MAC address -# MACHINEID SHOULD be the same between upgrades/reinstalls -# MAC is hashed so that it cant be reversed making it anonymous -# Used to help with global usage statistics, also used for dbus and systemd +# Creates a unique machine-id based on a local MAC address which persists over +# reboots, upgrades and reinstallation. For systems with slow loading network +# drivers (no MAC's available) dbus-uuidgen is used which persists over reboot +# and upgrades but not reinstallation. If a MAC is used it is hashed to make it +# anonymous. The machine-id is used by dbus and systemd, and to collect basic +# active-installation statistics on LibreELEC users. -# creating machine-id, systemd otherwise does this automatically if not present. -# this we want to avoid to have the same machine-id over reboot, fallback -# to systemd's solution if this dont work here - -if [ -e "/sys/class/net/eth0/address" ]; then - MAC_ADRESS=`cat /sys/class/net/eth0/address` +if [ -e "/storage/.cache/machine-id" ]; then + MACHINEID=`cat /storage/.cache/machine-id` +elif [ -e "/sys/class/net/eth0/address" ]; then + MAC_ADDRESS=`cat /sys/class/net/eth0/address` elif [ -e "/sys/class/net/wlan0/address" ]; then - MAC_ADRESS=`cat /sys/class/net/wlan0/address` + MAC_ADDRESS=`cat /sys/class/net/wlan0/address` +else + MAC_ADDRESS=`/usr/bin/dbus-uuidgen` fi -MACHINEID=`echo $MAC_ADRESS | md5sum | cut -f1 -d" "` +if [ -z "$MACHINEID" ]; then + MACHINEID=`echo $MAC_ADDRESS | md5sum | cut -f1 -d" "` +fi -echo "$MACHINEID" > /run/machine-id +echo "$MACHINEID" > /storage/.cache/machine-id