#!/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 ] ; then
	SYSTEM_SERIAL=$(cat /etc/oci/system-serial)
else
	SYSTEM_MANUFACTURER=$(dmidecode -s system-manufacturer)
	if [ "${SYSTEM_MANUFACTURER}" = "Supermicro" ] ; then
	        # Supermicro is stupid, dmidecode -s system-serial-number
	        # will always return 1234567890
	        SYSTEM_SERIAL=$(dmidecode -s baseboard-serial-number)
	else
	        SYSTEM_SERIAL=$(dmidecode -s system-serial-number)
	fi
	echo ${SYSTEM_SERIAL} >/etc/oci/system-serial
fi

echo ${SYSTEM_SERIAL}
exit 0
