#!/bin/sh
#*********************************************************************
#   Copyright (c) International Business Machines  Corp., 2000
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this pronram;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#  FILE   : cron02 
#
#  PURPOSE: Test a postive cron job
#			- add new job
#   		- check correct execution of job
#   		- delete job
#
#  HISTORY:
#     	SUSE
#

TEST_USER="c01_user"
TEST_USER_GROUP="users"
TEST_USER_HOMEDIR="/home/$TEST_USER"

#-----------------------------------------------------------------------
# FUNCTION:  do_setup
#-----------------------------------------------------------------------

do_setup(){
	#erase any data from potential defunt cron test
	rm -rf /tmp/crontest &> /dev/null

    #erase user if he may exist , so we can have a clean env
        rm -rf /home/$TEST_USER
        userdel $TEST_USER
	sleep 1

        useradd -m -g $TEST_USER_GROUP $TEST_USER 
        if [ $? != 0 ]
        then {
                echo "Could not add test user $TEST_USER to system $RHOST."
                exit 1
        }
        fi

	# restart cron daemon
# Red Hat uses crond, SuSE/Other uses cron. Check if this is Red Hat/SuSE/Other
tvar=${MACHTYPE%-*}
tvar=${tvar#*-}
echo "Distro type is: $tvar \n"

if [ $tvar != "redhat" -a $tvar != "redhat-linux" ]; then

	/etc/init.d/cron restart
else
	/etc/init.d/crond restart
fi
}

#-----------------------------------------------------------------------
# FUNCTION:  do_cleanup
#-----------------------------------------------------------------------

do_cleanup(){
        rm -rf /home/$TEST_USER
        userdel $TEST_USER 
}

#-----------------------------------------------------------------------
# FUNCTION:  MAIN
#-----------------------------------------------------------------------
do_setup
cron_pos_tests.sh $TEST_USER
EXIT_CODE=$?
do_cleanup
exit $EXIT_CODE
