#! /bin/bash
#
# xen-domain-uuid
#
# chkconfig: 2345 20 80
# description: Set control domain uuid
#

# Only run if we are in domain 0
if [ ! -f /etc/xensource-inventory -o ! -e /proc/xen ]; then
    exit 0
fi
 
# Source function library.
. /etc/init.d/functions

start() {
	local r
	base="xen-domain-uuid"
	echo -n $"Setting control domain uuid: "
	eval $(awk '/^(CONTROL_DOMAIN_UUID)/ {print}' /etc/xensource-inventory)

	[ -z ${CONTROL_DOMAIN_UUID} ] && { failure $"$base startup"; return 1;}

	/opt/xensource/bin/set-domain-uuid 0 ${CONTROL_DOMAIN_UUID}
	r=$?
	[ "$r" -eq 0 ] && success $"$base startup" || failure $"$base startup"
	echo

	return $r
}

case "$1" in
  start)
  	start
	;;
  stop)
	;;
  restart)
	start
	;;
  status)
	;;
  condrestart)
	start
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart}"
	exit 1
esac
