Merge pull request #2708 from chewitt/systemd-machineid

systemd: change uuid generation
This commit is contained in:
MilhouseVH 2018-07-07 18:26:10 +01:00 committed by GitHub
commit 65d87ea47f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 28 deletions

View File

@ -159,7 +159,7 @@ makeinstall_target() {
touch $INSTALL/etc/fstab
# /etc/machine-id, needed by systemd and dbus
ln -sf /storage/.cache/machine-id $INSTALL/etc/machine-id
ln -sf /storage/.cache/systemd-machine-id $INSTALL/etc/machine-id
# /etc/mtab is needed by udisks etc...
ln -sf /proc/self/mounts $INSTALL/etc/mtab

View File

@ -1,42 +1,32 @@
#!/bin/sh
#!/bin/bash
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
# This file is part of LibreELEC - https://libreelec.tv
# Copyright (C) 2018-present Team LibreELEC
# Copyright (C) 2009-2014 Stephan Raue
#
# OpenELEC is free software: you can redistribute it and/or modify
# LibreELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# OpenELEC is distributed in the hope that it will be useful,
# LibreELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC. If not, see <http://www.gnu.org/licenses/>.
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
# 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.
# remove old machine-id file
[[ -f "/storage/.cache/machine-id" ]] && rm /storage/.cache/machine-id
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_ADDRESS=`cat /sys/class/net/wlan0/address`
else
MAC_ADDRESS=`/usr/bin/dbus-uuidgen`
fi
# test systemd-machine-id exists and is 32 hex chars or generate a new uuid
MACHINEID="$(cat /storage/.cache/systemd-machine-id 2>/dev/null)"
[ "${#MACHINEID}" != "32" ] && MACHINEID=
[[ "${MACHINEID//[a-f0-9]/}" != "" ]] && MACHINEID=
[ -z "${MACHINEID}" ] && MACHINEID=$(/usr/bin/dbus-uuidgen)
if [ -z "$MACHINEID" ]; then
MACHINEID=`echo $MAC_ADDRESS | md5sum | cut -f1 -d" "`
mkdir -p /storage/.cache
fi
echo "$MACHINEID" > /storage/.cache/machine-id
# persist uuid
mkdir -p /storage/.cache
echo "$MACHINEID" > /storage/.cache/systemd-machine-id