#!/bin/sh
#$Id: sm_notify,v 1.10 2009/10/21 06:52:21 sesam Exp $
#******************************************************************************
#
# File      : sm_notify
# Copyright : (c) SEP AG  D83629 Weyarn
# Project   : SESAM Backup Utility
# Date      : 2007-01-18
#
#******************************************************************************
#
# Description : Template for the SESAM notify interface.
#               It is called from SESAM after finishing a backup, media change
#               media init or SESAM day change.
#
# Parameters  : $1 = Calling module (BACKUP, GET_VOLUME, INIT,
#                                    ALL_JOBS_DONE, NEWDAY)
#               $2 = message text
#
#
#     This is a user programable shell script with 2 parameters.
#     Please insert your specific code-lines after this comment.
#     Take care of not inserting any command waiting for an answer from
#     the user ( OK-buttons etc. ) - this may cause a complete blocking of
#     backups during the night.
#
#*******************************************************************************

# Example 

read_ini()
{
  source `grep -i '^sm_ini=' /etc/sesam2000.ini|cut -d"=" -f2` 2>/dev/null
}

send_mail()
{
   ## Set mail subject
   mail_subject="Sesam: $1"
   mail_text="$2"
   sm_smtp -A "sesam" -s "$mail_subject" -m "$mail_text" 
}

send_mail_file()
{
   ## Set mail subject
   mail_subject="Sesam: $1 $2"
   mail_text="$3"
   ## Send Sesam status file as mail body
   sm_smtp -A "sesam" -s "$mail_subject" -M "$mail_text" 
}


send_status_mail()
{
   ## Set mail subject
   mail_subject="Sesam backup status: $1"
   ## Send Sesam status as mail text and protocol file as mail attachment
   sm_smtp -A "sesam" -s "$mail_subject" -M "gv_dayfile:" -a "gv_prot:" 
}

unload_tape()
{
   ## Unload tape from a stand alone drive. First parameter is sesam drive num 

   ## Send Sesam status as mail text and protocol file as mail attachment
   sm_drive dismount $1 unload 
}

#--------------- MAIN ----------------------

read_ini
source "${gv_rw_ini}/sesam2000.profile" >/dev/null 2>&1

echo "$0" "$*" >> "${gv_rw_lgc}/sm_notify.lgc"

case $1 in
      ALL_JOBS_DONE)
         send_status_mail "$2";
         # unload_tape 2;
         ;;
      INIT)
         # send_mail "$1" "$2"
         ;;
      GET_VOLUME)
         # send_mail "$1" "$2" 
         ;;
      BACKUP)
         # send_mail "$1" "$2"
         ;;
      RESTORE)
         # send_mail_file "$1" "$2" "$3"
         ;;
      BACKUP_GROUP:)
         ;;
      COPY)
         ;;
      *)
      ;;
esac
exit

