#!/bin/bash
#
# $Id: cdd-update-usermenus 431 2006-10-23 06:11:32Z tille $ 

usage() {
   echo "Usage: `basename $0` <CDD>"
   echo "CDD:   `getCDDList|tr ' ' '|'`"
   echo
   echo "Updates user menus of all users registered for CDD"
}

# the base dir for CDD conffiles, where script expects to find dirs named like
# each registered CDDs
CONFBASE=${CONFBASE:-/etc/cdd}

# a local per CDD conf is sourced later, after argument parsing
. ${CONFBASE}/cdd.conf

# specific utilities for cdd-update-menus
. ${SHAREDIR}/cdd-update-menus

if ! amI root; then
	cddLog "$0 must be called by root.  If you are a normal user just call update-menus ."
	exit 0
fi

case $1 in
	-h|--help|"")
            usage
            exit 0
            ;;
        *)
	    set -e
            checkCDD $1 || \
                cddFail $? "Custom distribution $1 does not exist"
	    CDD=$1
            set +e
esac

if [ -s /etc/cdd/${CDD}/${CDD}.conf ] ; then
	. /etc/cdd/${CDD}/${CDD}.conf
fi

for ROLE in `getCDDRoleList ${CDD}`; do
        for CDDUSER in `getUsersInRole ${CDD} ${ROLE} 1`; do
		# Update user menus if UPDATEUSERMENU is set to yes
            	cddLog "Adding menu for user ${CDDUSER} of ${CDD} ..."
            	su ${CDDUSER} -c "update-menus"
        done
done

