#! /bin/ksh
########
#
# $Copyright: Copyright (c) 2022 Veritas Technologies LLC. All rights reserved $
# AIX preremove script.
# @(#) $Revision$

#
########

PBX_ROOT=/opt/VRTSpbx
LOGCFG=$PBX_ROOT/bin/vxlogcfg
LOGMGR=$PBX_ROOT/bin/vxlogmgr
PROD_ID=50936
ORIG_ID=103
LIBPATH=$PBX_ROOT/lib
export LIBPATH

# stop exchange.

$PBX_ROOT/bin/vxpbx_exchanged stop > /dev/null

# This needs to be set for the VxUL tools to work
VRTSLOG_RES_PATH=$PBX_ROOT/resources
export VRTSLOG_RES_PATH
ICU_DATA=$VRTSLOG_RES_PATH
export ICU_DATA

# Before unconfigure, remove the log files.
if [ -f $LOGMGR ] ; then
	$LOGMGR -q -d -p $PROD_ID -o $ORIG_ID
else
	/bin/rm -f $PBX_ROOT/log/$PROD_ID-$ORIG_ID-*.log
fi

if [ -e /usr/sbin/rmitab ]; then
        /usr/sbin/rmitab vxpbxexchanged
fi

###################################
# Remove Start and stop sym linked.
###################################
LINK_PATH=/etc/rc.d
START_DIRS=/etc/rc.d/rc[23456789].d
STOP_DIRS=/etc/rc.d/rc[23456789].d

LINK_TARGET=$LINK_PATH/vxpbx_exchanged
if [ -h $LINK_TARGET ];then
        /bin/rm $LINK_TARGET
fi

# delete start links in run levels 2-9.
for rcdir in $START_DIRS; do
    if [ -h $rcdir/S45vxpbx_exchanged ]; then
        /bin/rm $rcdir/S45vxpbx_exchanged
    fi;
done;

# delete stop links in run level 2-9.
for rcdir in $STOP_DIRS; do
    if [ -h $rcdir/K*vxpbx_exchanged ]; then
        /bin/rm $rcdir/K*vxpbx_exchanged
    fi;
done;

# unconfiguration
if [ -f $LOGCFG ]; then
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s DebugLevel -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s LogToOslog -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s LogDirectory -q 
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s L10nResourceDir -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s L10nLib -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s L10nResource -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s MaxLogFileSizeKB -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s RolloverMode -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s NumberOfLogFiles -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s LogFilePermissions -q
    $LOGCFG -r -p $PROD_ID -o $ORIG_ID -s LogRecycle -q
    $LOGCFG -d -p $PROD_ID -q >/dev/null
fi;
# Clean the pbxcfg script linked
if [ -e $PBX_ROOT/bin/vxpbxcfg ]; then
        /bin/rm $PBX_ROOT/bin/vxpbxcfg;
fi

if [ -h /usr/share/man/man1/pbxcfg.1 ]; then
    /bin/rm /usr/share/man/*/pbxcfg.1      
fi;

# Remove the log dir linked.
/bin/rm -f $PBX_ROOT/log


###############
#
# VxUL remove wrapper scripts
#
###############
# Remove the wrapper scripts.
for LOG_TOOL in vxlogcfg vxlogview vxlogmgr ; do
    /bin/rm -f $PBX_ROOT/bin/$LOG_TOOL
done

#Emacs Customization
#Local Variables:  
# mode: shell-script
#End:
exit 0
