#!/bin/ash UUID=$( dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr 'a-z' 'A-Z' ) if [ "${#UUID}" -ne "36" ]; then echo "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..." UUID= else # Got UUID, check blacklist DIR="/opt/openslx/bad-uuid.d" TMPLIST=$(mktemp) BADLIST=$(mktemp) for file in "$DIR"/*; do [ -f "$file" ] || continue # 11111111-2222-3333-4444-555555555555 < "$file" tr 'a-z' 'A-Z' | grep -Eo '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' done | tee "$TMPLIST" > "$BADLIST" # Also add flipped version of bad uuids. Found some of them through googling and discovered that sometimes # users report them in a different order. UUIDs use different endianness for the first three blocks than # the remaining two, but some tools seem to ignore that fact. < "$BADLIST" sed -r 's/^(..)(..)(..)(..)\-(..)(..)\-(..)(..)\-([0-9A-F]{4}\-[0-9A-F]{12})$/\4\3\2\1-\6\5-\8\7-\9/' >> "$TMPLIST" # Finally make unique sort -u "$TMPLIST" > "$BADLIST" if grep -Fxq "$UUID" "$BADLIST"; then echo "WARNING: UUID is blacklisted as potentially not being unique, using MAC fallback" UUID= fi rm -f -- "$TMPLIST" "$BADLIST" fi if [ -z "$UUID" ]; then if [ "${#MAC}" -ne 17 ]; then MAC="$( grep -Po '(?<=ipv4.if=)\S+' /proc/cmdline )" fi if [ "${#MAC}" -ne 17 ]; then MAC="$( grep -Po '(?<=BOOTIF=01-)\S+' /proc/cmdline )" fi if [ "${#MAC}" -ne 17 ]; then echo "Getting MAC from /proc/cmdline failed, using 'ip a'..." MAC="$( ip a | grep -A 1 ': br0' | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 )" fi if [ "${#MAC}" -ne 17 ]; then echo "FAIL FAIL FAIL" MAC="88-77-66-55-44-33" fi UUID=$( echo "$MAC" | sed -r 's/[^0-9A-Fa-f]//g' ) if [ "${#UUID}" -eq 12 ]; then UUID="baad1d00-9491-4716-b98b-$UUID" else UUID="baad1d00-9491-4716-b98b-000000000000" fi fi UUID=$( echo "$UUID" | tr 'a-z' 'A-Z' ) readonly UUID echo "$UUID" > "/run/system-uuid"