#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2019,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsm_adminmanual.sh 1.1 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsm_adminmanual.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
#################################################################################
# Name: cl_tsm_adminmanual
#
# Purpose: To create PowerHA SystemMirror resources and Resource group for Managing
#          TSM Admin center using manual configuration.
#
# Arguments:
# 	n/a 
#
# Returns: 0 for Sucess
#          1 for Failure
################################################################################

. /usr/es/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminGlobals
. /usr/es/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminUtilities
KLIB_HACMPLOG_ENTRY=$KLIB_TSM_ADMIN_HACMPLOG_ENTRY

dspmsg -s 1 tsmadminsa.cat 43 "configuring TSM Admin center using manual configuration\n"
KLIB_SA_logmsg INFO 1 43 tsmadminsa.cat "configuring TSM Admin center using manual configuration\n"

typeset APPLICATION_ID       # Smart Assist Application Name of the TSM Admin center.
typeset PRIMNODE TAKEOVNODES # primary and takeover nodes.
typeset SERVICE_IP           # Service IP for the TSM instance.
typeset NETMASK              # Netmask/ prefix Length of service IP address.
typeset USERID               # TSM Admin center user id
typeset XML_PATH=""

while getopts f: opt
do
        case $opt in

                f) # xml file path
                        XML_PATH=$OPTARG
                        ;;
        esac
done

APPLICATION_ID=$($TSM_AC_HA_SBIN/cl_tsm_admin_query -n|grep -v application_name|awk -F: '{ print $1 }')
validateAppName "$APPLICATION_ID"
[[ "$?" == "1" ]] && {
        KLIB_SA_logmsg ERROR 1 11 tsmadminsa.cat "TSM admin smart assist Application id=%1\$s is not in the rage [a-z][A-z][0-9]_.\n" "$APPLICATION_ID"
        exit 1
        }

PRIMNODE=$($SA_SBIN/clsaxmlutil -s -x $XML_PATH -m $TSM_ADMIN_HA_CONFIG/cl_tsmadmin_config.xsd -t PrimaryNode|awk -F= '{ print $2 }')
[[ $? != 0 || -z $PRIMNODE ]] && {
	KLIB_SA_logmsg ERROR 1 44 tsmadminsa.cat "No value is specified for PrimaryNode property in TSM admin xml file\n"
	exit 1
	}

TAKEOVNODES=$($SA_SBIN/clsaxmlutil -s -x $XML_PATH -m $TSM_ADMIN_HA_CONFIG/cl_tsmadmin_config.xsd -t TakeoverNodes|awk -F= '{ print $2 }')
if [[ $? == 0 && -n $TAKEOVNODES ]]
then
        TAKEOVNODES=$(echo $TAKEOVNODES|tr "," " ")
else
        KLIB_SA_logmsg ERROR 1 45 tsmadminsa.cat "No value is specified for TakeoverNodes property in TSM admin xml file\n"
	exit 1
fi

SERVICE_IP=$($SA_SBIN/clsaxmlutil -s -x $XML_PATH -m $TSM_ADMIN_HA_CONFIG/cl_tsmadmin_config.xsd -t IPAddress_or_name|awk -F= '{ print $2 }')
[[ $? != 0 || -z $SERVICE_IP ]] && {
	KLIB_SA_logmsg ERROR 1 46 tsmadminsa.cat "No value is specified for ServiceIPs property in TSM admin xml file\n"
	exit 1
	}

SERVICE_IP=$(/usr/bin/host $SERVICE_IP|awk -F" " '{print $1}'|awk -F. '{print $1}')
[[ $? != 0 ]] && {
	KLIB_SA_logmsg ERROR 1 49 tsmadminsa.cat "No entry for service IP in /etc/host file\n"
	exit 1
	}

NETMASK=$($SA_SBIN/clsaxmlutil -s -x $XML_PATH -m $TSM_ADMIN_HA_CONFIG/cl_tsmadmin_config.xsd -t Prefix_or_Netmask|awk -F= '{ print $2 }')

USER=$($SA_SBIN/clsaxmlutil -s -x $XML_PATH -m $TSM_ADMIN_HA_CONFIG/cl_tsmadmin_config.xsd -t User|awk -F= '{ print $2 }')
[[ $? != 0 || -z $USER ]] && {
	KLIB_SA_logmsg ERROR 1 47 tsmadminsa.cat "No value is specified for User property in TSM admin xml file\n"
	exit 1
	}

validateNodes $PRIMNODE "$TAKEOVNODES"
(( $? != 0 )) && {
KLIB_SA_logmsg ERROR 1 14 tsmadminsa.cat "TSM admin smart assist has primary=%1\$s and takeover nodes=%2\$s as repetitive\n" $PRIMNODE "$TAKEOVNODES"
exit 1
}

if [[ -z $$NETMASK ]];then
	$TSM_AC_HA_SBIN/cl_tsm_admin_config -a $APPLICATION_ID -p $PRIMNODE -t "$TAKEOVNODES" -s $SERVICE_IP -u $USER
	exit $?
else
	$TSM_AC_HA_SBIN/cl_tsm_admin_config -a $APPLICATION_ID -p $PRIMNODE -t "$TAKEOVNODES" -s $SERVICE_IP -n $NETMASK -u $USER
	exit $?
fi
