#!/bin/bash2

# author: K. M. Gheri
#         phion IT GmbH
#         Copyright 2002
#
# PhionVersionString 3.2.0.1

# $Id: notification_activate,v 2.2.2.1 2002/12/17 18:01:13 root Exp root $



set -f

if [ -f /etc/phion/phion.sh ]; then
        source /etc/phion/phion.sh
fi

if [ -f /etc/phion/options ]; then
        source /etc/phion/options
fi


if [ -f /etc/phion/functions ]; then
        source /etc/phion/functions
fi



umask 177

getopts ":b" opt
case $opt in
        b  )
                shift 1
                ;;
esac        

PMODPATH="/opt/phion/modules/box/boxother/notification"
[ -f ${PMODPATH}/moddefs.conf ] && source ${PMODPATH}/moddefs.conf  
MYLOGFLE="box_Auth_activation"


logerror="LogError $MYLOGFLE"

ARGS="ARGS"
ARG1=${1:-"/opt/phion/config/active/notification.conf"}

ARG0=activate

export H=1


if [ ! -f $ARG1 ]; then
	$logerror "Error" "---RE0020--- activate($ARGS): missing conf file $ARGS"
        $logerror "Error" "---OP0010--- activate($ARGS)->1: cannot parse configuration data" 
	exit 1 
elif [ ! -s $ARG1 ]; then
	exit 0
fi




# read in conf-file


function readCONFs
        {
	local ARG0="$(SUB1) readCONFs"
	local ARGS=""
	
        if [ ! -x "$PHION_ROLLOUT" ]; then
                $logerror "Error" "---RE0040--- ${ARG0}(${ARGS}): missing executable $PHION_ROLLOUT"
                $logerror "Error" "---OP0010--- ${ARG0}(${ARGS})->1: cannot parse configuration data"
                return 1
        fi

	ARG1=${ARG1:-"/opt/phion/config/active/notification.conf"}

        if [ -f "$ARG1" ]; then
                $PHION_ROLLOUT ${ARG1} /etc/phion/dynconf/notification.conf.rollout.$$ &>/dev/null
                #source /etc/phion/dynconf/notification.conf.rollout.$$
                #rm -f /etc/phion/dynconf/notification.conf.rollout.$$
        fi

	}


$logerror "Info" "------------ ${ARG0}(${ARGS}): -----------------------------------------------"
$logerror "Info" "------------ ${ARG0}(${ARGS}): starting activation of notification settings"
$logerror "Info" "------------ ${ARG0}(${ARGS}): ARGS=$ARG1"

readCONFs

{

defgrp=-1
type1=1
type2=2
type3=3



echo -n > /etc/phion/dynconf/notification.op.tmp
while read line; do

	[ "_$line" = "_" ] && continue

	for i in defgrp type1 type2 type3; do
		STUB=${line#box_${i}_}
		[ ${STUB%=*} = N ] && break
		if [ $STUB != $line ]; then
			FRONT=${STUB%_*}
			
			#eval VAL=${STUB#*=}
			#echo ${FRONT}_"${!i}"=$VAL >> /tmp/ert

			[ "_$FRONT" = "_NAME" ] && break	
			#echo ${FRONT}_"${!i}"=$VAL >> /tmp/ert

			eval echo ${FRONT}_"${!i}"=${STUB#*=} >> /etc/phion/dynconf/notification.op.tmp  
			break;
		fi
	done
		
		
		
done

} < /etc/phion/dynconf/notification.conf.rollout.$$ 



[ -f /opt/phion/preserve/notification.op ] && {
						cd /opt/phion/preserve
						cp notification.op notification.op.last
						cd -
						}

mv /etc/phion/dynconf/notification.op.tmp /opt/phion/preserve/notification.op
chmod 644 /opt/phion/preserve/notification.op 


[ -f /etc/phion/dynconf/notification.op.$$ ] && rm -f /etc/phion/dynconf/notification.op.$$  
[ -f /etc/phion/dynconf/notification.conf.rollout.$$ ] && rm -f /etc/phion/dynconf/notification.conf.rollout.$$

$logerror "Info" "------------ ${ARG0}(${ARGS}): -----------------------------------------------"
exit 0







