#!/bin/sh
#
# /etc/init.d/init.d-sdkinit
# Creates some fake information for the SDK fake xapi
#
# chkconfig: 345 21 00
# description: Populate xensource-inventory

. /etc/init.d/functions

case "$1" in
    start)
	# This is a run-once script!
	if [ -e /etc/xensource-inventory ]; then
            exit 0
	fi
	echo -n "Starting sdkinit: "
	cat /proc/cpuinfo > /etc/xensource/boot_time_cpu
	touch /etc/xensource/boot_time_info_updated

	if [ -d /proc/xen ]; then
		# Set the domain0 uuid to the real uuid of this SDK VM

		DOMID=`/usr/bin/xenstore-read domid`
		VMUUID=`/usr/bin/xenstore-read /local/domain/$DOMID/vm | cut -c5-`
		DOM0UUID=$VMUUID
	else
		# If booting HVM we have no uuid knowledge
		DOM0UUID=`uuidgen`
	fi
	HOSTUUID=`uuidgen`
	INSTALLDATE=`date "+%Y-%m-%d %H:%M:%S.000000"`

	(cat /etc/xensource-inventory.skel; cat << EOF) > /etc/xensource-inventory
KERNEL_VERSION='2.6.18-92.1.6.el5.xs4.1.920.367.638xen'
XEN_VERSION='3.2.1'
INSTALLATION_DATE='${INSTALLDATE}'
PRIMARY_DISK='/dev/sda'
BACKUP_PARTITION='/dev/sda2'
INSTALLATION_UUID='${HOSTUUID}'
CONTROL_DOMAIN_UUID='${DOM0UUID}'
DEFAULT_SR_PHYSDEVS='/dev/sda3'
DOM0_MEM='752'
EOF
	echo "[  OK  ]"
        ;;
    stop)
        ;;
    *)
        echo "Usage: $0 [start|stop]"
        ;;
esac
