#!/bin/sh

phase_check()
{
    case $CDAT_TYPE in
    LPAR)
	# Check that the remote node is reachable and has the
	# appropriate OS level, e.g:
	# level=`remote_cmd "/usr/bin/oslevel"`
	# [ $? -ne 0 ] && exit 128
	# Check $level here
	;;

    *)	# All other node types are not supported (ignored)
	exit 1
	;;
    esac
}

phase_init()
{
    # Copy installation files to the remote node:
    # push_file scripts.tar.Z /tmp || exit 128

    # Extract installation files on the remote node:
    # remote_cmd \
        "uncompress -c /tmp/scripts.tar.Z | tar xf -"
    # [ $? -ne 0 ] && exit 128
}

phase_execute()
{
    # Execute our collect on the remote node

    # remote_cmd \
    #    "/tmp/scripts/my_collect_script > /tmp/my_collected_data"
    # [ $? -ne 0 ] && exit 128
}

phase_terminate()
{
    # Our collect terminates by itself so we do nothing here.
}

phase_grab()
{
    # Retrieve collected data from the remote node into destination directory

    # get_file "/tmp/my_collected_data" $CDAT_DEST_DIR/
    # [ $? -ne 0 ] && exit 128
}

phase_clean()
{
    # Perform cleanup on the remote node.
    # Remove files that were installed in "init" phase.
    # Remove data collected in "execute" phase since it was retrieved
    # in the "grab" phase.

    # remote_cmd \
    #    "rm -fr /tmp/scripts.tar.Z /tmp/scripts/ /tmp/my_collect_data"
}

#
# Insert operations common to all phases here.
#

# Add Cluster Data Aggregation Tool helpers to our path.
PATH=$CDAT_SRVC_DIR:${PATH}

#
# Branch on subroutines that implement phases.
#
case $CDAT_PHASE in
check)
    phase_check
    ;;
init)
    phase_init
    ;;
execute)
    phase_execute
    ;;
terminate)
    phase_terminate
    ;;
grab)
    phase_grab
    ;;
clean)
    phase_clean
    ;;
esac

exit 0
