1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/bin/sh
# Get the system serial number (ie: chassis, or baseboard, this depends on vendor...)
# and display it on the console. Cache the result to /etc/oci/system-serial
# to avoid expensive calls to dmidecode.
set -e
if [ -r /etc/oci/system-serial ] && [ -n ""$(cat /etc/oci/system-serial) ] ; then
SYSTEM_SERIAL=$(cat /etc/oci/system-serial)
else
SYSTEM_MANUFACTURER=$(dmidecode -s system-manufacturer)
SYSTEM_PRODUCT_NAME=$(dmidecode -s system-product-name)
case "${SYSTEM_MANUFACTURER}" in
"OpenStack Nova"|"OpenStack Foundation")
SSN=$(dmidecode -s system-serial-number)
SYSTEM_SERIAL=$(echo $SSN | cut -d- -f1)-$(echo $SSN | cut -d- -f2)
;;
"HPE"|"Dell"|"Dell Inc."|"Acer"|"LinuxKVM"|"OpenStack Nova"|"GIGABYTE")
# We got some servers that have always "01234567890123456789AB" as serial number,
# for the system-serial-number. Let's use baseboard-serial-number instead.
SYSTEM_SERIAL=$(dmidecode -s system-serial-number)
if [ "${SYSTEM_SERIAL}" = "01234567890123456789AB" ] ; then
SYSTEM_SERIAL=$(dmidecode -s baseboard-serial-number)
fi
;;
"Lenovo"|"LENOVO")
SYSTEM_SERIAL=$(dmidecode -s chassis-serial-number)
;;
# Supermicro is stupid, dmidecode -s system-serial-number
# will always return 1234567890
"Supermicro")
SYSTEM_SERIAL=$(dmidecode -s baseboard-serial-number)
;;
"QEMU")
# Someone reported he's using this, which also works on OpenStack VMs:
SYSTEM_SERIAL=$(dmidecode -s system-uuid)
# Though, under oci-poc, we're in this case:
if [ -z "${SYSTEM_SERIAL}" ] || [ "${SYSTEM_SERIAL}" = "Not Settable" ] ; then
SYSTEM_SERIAL=$(dmidecode -s system-serial-number)
fi
;;
# Fallback for all other (possibly broken?) motherboards.
# Please contribute as you see issues.
*)
SYSTEM_SERIAL=$(dmidecode -s baseboard-serial-number)
if [ -z "${SYSTEM_SERIAL}" ] ; then
SYSTEM_SERIAL=$(dmidecode -s system-serial-number)
if [ -z "${SYSTEM_SERIAL}" ] ; then
SYSTEM_SERIAL=$(dmidecode -s system-uuid)
fi
fi
;;
esac
fi
echo ${SYSTEM_SERIAL} > /etc/oci/system-serial
echo ${SYSTEM_SERIAL}
exit 0
|