diff options
Diffstat (limited to 'modules.d/slx-uuid/hooks/s3-get-system-uuid.sh')
-rwxr-xr-x | modules.d/slx-uuid/hooks/s3-get-system-uuid.sh | 116 |
1 files changed, 55 insertions, 61 deletions
diff --git a/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh index e65a3394..e97a0e18 100755 --- a/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh +++ b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh @@ -1,71 +1,65 @@ -#!/usr/bin/env bash -# +#!/bin/ash + # Slighty changed version of: # http://git.openslx.org/openslx-ng/mltk.git/plain/core/modules/system-uuid/data/bin/get-uuid -. /lib/dracut-lib.sh - -get_system_uuid() { - if [ -e /run/openslx/network.conf ]; then - . /run/openslx/network.conf - else - echo "Don't have /run/openslx/network.conf" - fi +if [ -e /run/openslx/network.conf ]; then + . /run/openslx/network.conf +else + echo "Don't have /run/openslx/network.conf" +fi - if [ -z "$SLX_PXE_MAC" ]; then - warn "Getting MAC from /run/openslx/network.conf failed, using 'ip a'..." - for iface in "${SLX_BRIDGE:-br0}" boot0 eth0; do - BOOTIF=01-$(ip a | grep -A 1 ": ${iface}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) - [ "${#BOOTIF}" -eq "20" ] && break - done - if [ "${#BOOTIF}" -ne "20" ]; then - warn "Getting MAC from 'ip a' failed, using bogus value..." - BOOTIF="99-88-77-66-55-44-33" - fi - else - BOOTIF="01-$(tr ':' '-' <<< $SLX_PXE_MAC)" +if [ -z "$SLX_PXE_MAC" ]; then + echo "Getting MAC from /run/openslx/network.conf failed, using 'ip a'..." + for iface in "${SLX_BRIDGE:-br0}" boot0 eth0; do + BOOTIF=01-$(ip a | grep -A 1 ": ${iface}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) + [ "${#BOOTIF}" -eq "20" ] && break + done + if [ "${#BOOTIF}" -ne "20" ]; then + echo "Getting MAC from 'ip a' failed, using bogus value..." + BOOTIF="99-88-77-66-55-44-33" fi +else + BOOTIF="01-$( echo "$SLX_PXE_MAC" | tr ':' '-' )" +fi - local UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr 'a-z' 'A-Z') - if [ "${#UUID}" -ne "36" ]; then - warn "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..." - # Maybe use /proc/sys/kernel/random/uuid ? +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..." + # Maybe use /proc/sys/kernel/random/uuid ? + UUID= +else + # Got UUID, check blacklist + DIR="/etc/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= - else - # Got UUID, check blacklist - local DIR="/etc/bad-uuid.d" - local TMPLIST=$(mktemp) - local 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 - warn "WARNING: UUID is blacklisted as potentially not being unique, using MAC fallback" - UUID= - fi - rm -f -- "$TMPLIST" "$BADLIST" fi + rm -f -- "$TMPLIST" "$BADLIST" +fi - if [ -z "$UUID" ]; then - UUID=$( echo "$BOOTIF" | sed -r 's/[^0-9A-Fa-f]//g' ) - [ "${#UUID}" -eq 14 ] && UUID="${UUID:2}" - if [ "${#UUID}" -eq 12 ]; then - UUID="baad1d00-9491-4716-b98b-$UUID" - else - UUID="baad1d00-9491-4716-b98b-000000000000" - fi +if [ -z "$UUID" ]; then + UUID=$( echo "$BOOTIF" | sed -r 's/[^0-9A-Fa-f]//g' ) + [ "${#UUID}" -eq 14 ] && UUID="${UUID:2}" + if [ "${#UUID}" -eq 12 ]; then + UUID="baad1d00-9491-4716-b98b-$UUID" + else + UUID="baad1d00-9491-4716-b98b-000000000000" fi - UUID=$( echo "$UUID" | tr 'a-z' 'A-Z' ) - readonly UUID - echo "$UUID" > "/run/system-uuid" -} - -get_system_uuid +fi +UUID=$( echo "$UUID" | tr 'a-z' 'A-Z' ) +readonly UUID +echo "$UUID" > "/run/system-uuid" |