#!/bin/sh

##########################################################################
#   Script description:
#       Main menu for cluster admin tasks
#       
#   History:
#   Date        Name        Modification
#   2014-01-08  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0\n"
    exit 1
}


##########################################################################
#   Function description:
#       Pause until user presses return
##########################################################################

pause()
{
    local junk
    
    printf "Press return to continue..."
    read junk
}


##########################################################################
#   Main
##########################################################################

if [ $# != 0 ]; then
    usage
fi

# Prevent user from running a Trojan as root in the case their account
# was compromised
absolute="$(which $0)"
# Don't count on -e being set at this point
if ! auto-file-secure "$absolute"; then
    exit 1
fi

if ! auto-root-check $0; then
    printf "Root "
    # exec quotes '$absolute --flag', causing usage error
    # Assigning to cmd works around the problem
    cmd="$absolute $@"
    exec su -m root -c "$cmd"
fi

while true; do

    clear
    spcm-banner
    cat << EOM

1.. Update manager
2.. User manager
3.. Node manager
4.. Software manager
5.. Diagnostics and Monitoring
6.. Services manager
7.. Power manager
Q.. Quit

EOM

    printf "Selection? "
    read selection
    clear
    case $selection in
    1)
	cluster-update-manager
	;;
    
    2)
	cluster-user-manager
	;;
    
    3)
	set -e
	cluster-node-manager
	set +e
	;;
    
    4)
	cluster-software-manager
	;;
    
    5)
	cluster-diagnostics
	;;
    
    6)
	cluster-services-manager
	;;
    
    7)
	cluster-power-manager
	;;

    Q|q)
	exit 0
	;;
    
    *)
	printf "Invalid selection: '$selection'\n"
	;;
    esac
done
