# !/bin/sh
#
# THIS IS NOT TO BE CONFUSED WITH USER DEFINED BEFORE/AFTER
# BACKUP COMMANDS!
#
# Always called before and after a client backup on the client machine.
# Before/After command environment variables will be set.
#
# bpserverd/bpclientd runs this script. It is picky about permissions
# of this file. It cannot have group or other write permission. This script
# is run as the uid of the user that started the BP task. A normal user
# or from a schedule, root.
#
# Any output from this script will be written to the messages database
# for the task if exiting with a non-zero value. An exit value of 100
# will abort the task.
#
# Usage: taskcmds <start | stop> <task_type> <operator> <catalogue_path>
#
#

# The program name
PNAME="$0"

# First lets notify owner of this workstation via email
# You can edit the given file below to customize report
# subject line and who receives the email for this machine

# $BPDIR should be set by caller, we do it here if you are testing manually
# if [ -z "$BPDIR"  -a  -f /etc/default/bp.ini ]
# then
#  BPDIR=`grep BPDIR /etc/default/bp.ini|sed 's/^[	 ]*//;s/BPDIR=[  	]*//'`
# fi

# if [ -r ${BPDIR:=/usr/bp}/bin/email_notify ]
# then # Notify user of email,
# . $BPDIR/bin/email_notify
# fi



# System V Release 4 needs to reset the security database after
# a backup because the access times may have been set. 
# If not System V, there is no effect and you can see how to 
# perform specific functions using the example shown.

do_setpriv()
{
	SP="/etc/security/tools/setpriv"
	if [ -x "$SP" ]; then
		$SP -x > /dev/null 2>&1
		status=$?
		[ $status -ne 0 ] && echo "$PNAME: error running $SP"
		return $status
	else
		return 0
	fi
}

# ######################################################################
# #
# # MAIN
# #
# ######################################################################

# Exit Status. 100 aborts the task. Not 0 directs output to task messages.
estatus=0

# Get task type from command-line
# M=master, I=incremental, S=special-backup, V=verify, R=restore
TASK_TYPE="$2"

case "$1" in
  start )
	;;
  stop )
	case "$TASK_TYPE" in
	  M )	# Master
		do_setpriv
		;;
	  S )	# Selective
		do_setpriv
		;;
	  I )	# Incremental
		do_setpriv
		;;
	  V )	# Verify
		# nothing yet
		;;
	  R )	# Restore
		# nothing yet
		;;
	esac
	estatus=$?
	;;
esac

exit $estatus
