Rev 1530 | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/sh#set -x#========================================================# **** Program Information ****## Program Name : reqlib.sh## Program Type : Bourne Shell Scripts(.sh)## Original Author(s) : Vasili Chatzimichail(vchatzim)## Description / Purpose:# Called by the request script of a package providing a suite of# common functions to get user input.## Exit Values:# NA.## References:# -None-##========================================================# Global Variables#REQLIB_ORA_TAB=/var/opt/oracle/oratab# Function to get the module enable flag.## Input is the module type and a string to describe the modlue.#reqlib_getOLSModuleEnable (){MODTYPE=$1MODSTR=$2MODDEF=$3MODDEF=`echo $MODDEF | tr '[A-Z]' '[a-z]'`printf "\n\n\n\n"printf "Will the $MODSTR module be enabled on this tier/node?\n"while [ 1 ]docase "$m_resp" in# Simple or Expert'y' | 'n')break;;'q')exit 3;;;*)m_resp=`ckstr -l 1 -d "$MODDEF" -p "(default: $MODDEF) [y,n,q=quit] :"`m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`;;esacdonem_resp=`echo $m_resp | tr '[a-z]' '[A-Z]'`m_str="${MODTYPE}_ENABLED=$m_resp"eval $m_str}# Function to get the install type.#reqlib_getInstallType (){M_VAR=$1M_DEF=$2printf "\n\n\n\n"printf "Please enter the type of installation you would like,\n"printf "Note: s = SIMPLE install\n"printf " e = EXPERT install\n"printf " q = quit\n"while [ 1 ]docase "$m_resp" in# Simple or Expert's' | 'e')break;;'q')exit 3;;;*)m_resp=`ckstr -l 1 -d "$M_DEF" -p "(default: $M_DEF) [s,e,q=quit] :"`m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`;;esacdonem_str="${M_VAR}=$m_resp"eval $m_strprintf "\n\n\n\n"if [ "x$m_resp" = "xe" ]thenprintf "You have chosen an EXPERT installation.\n"elseprintf "You have chosen a SIMPLE installation.\n"fiprintf "Please answer the following questions or accept the default paramaters.\n"}# ---------------------------------------------------------------------------------------reqlib_testDBConnection ()## this function tests the database connection based on the# data entered by the user. Variables used are# sid, user, passowrd and description.## ---------------------------------------------------------------------------------------{M_SID=$1M_USER=$2M_PASSWORD=$3M_DESC=$4printf "\n\n\n\n"# lets verify we can connect to the database#printf "$M_DESC\n"# do we even have access to sqlplus?#su - oracle -c ". .profile; sqlplus -? > /dev/null 2>&1"if [ "$?" -ne "0" ]thenprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;fi# we have access to sqlplus, lets try the database entered#rm -f /tmp/xx_lastsql.txtsu - oracle -c ". .profile; sqlplus ${M_USER}/${M_PASSWORD}@${M_SID} <<EOF 1>/tmp/xx_lastsql.txt 2>&1select 1 from dual;exitEOF"if [ -f /tmp/xx_lastsql.txt ]thenOK=`cat /tmp/xx_lastsql.txt | grep ORA- | wc -l`if [ "$OK" -ne "0" ]thenprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;elseprintf "Database connection OK.\n"fielseprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;fi}# ---------------------------------------------------------------------------------------reqlib_setVariableNoCheck ()## ---------------------------------------------------------------------------------------{M_VAR=$1M_DEF=$2M_DESC=$3printf "\n\n\n\n"printf "$M_DESC"m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_str="${M_VAR}=$m_resp"eval $m_str}# ---------------------------------------------------------------------------------------reqlib_setVariableNoCheck_lc ()## ---------------------------------------------------------------------------------------{M_VAR=$1M_DEF=$2M_DESC=$3printf "\n\n\n\n"printf "$M_DESC"m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`m_str="${M_VAR}=$m_resp"eval $m_str}reqlib_setVariableNoCheck_uc (){M_VAR=$1M_DEF=$2M_DESC=$3printf "\n\n\n\n"printf "$M_DESC"m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_resp=`echo $m_resp | tr '[a-z]' '[A-Z]'`m_str="${M_VAR}=$m_resp"eval $m_str}reqlib_getIntegerResponse (){M_VAR=$1M_DESC=$2M_DEF=$3printf "\n\n\n\n"printf "$M_DESC"m_resp=`ckint -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_str="${M_VAR}=$m_resp"eval $m_str}# lets just test if the oracle config exists.#reqlib_testOratabConfig (){if [ ! -f "$REQLIB_ORA_TAB" ]thenprintf "ERROR: Failed to find file [$REQLIB_ORA_TAB].\n"printf "Check oracle installation before proceeding.\n"exit 1fi}reqlib_getRsOracleSidNoCheck (){reqlib_getRsOracleSid "$1" "$2" "YES"}# Function to get the report server Oracle SID.#reqlib_getRsOracleSid (){M_VAR=$1M_DEF=$2M_NOCHK=$3 # if empty then a check is done as per normalprintf "\n\n\n\n"printf "Please enter the report server Oracle SID.\n"if [ -z "$M_NOCHK" ]; thenm_SIDs=`egrep -v "#|\*" $REQLIB_ORA_TAB | cut -d: -f 1 | tr '[:space:]' | tr '[a-z] [A-Z]'`printf "The current list of active database SIDs on this machine include:\n"printf "$m_SIDs\n"fim_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fiif [ -z "$M_NOCHK" ]; thenfoundIt=0if [ -n "$m_SIDs" ]thenfor i in $m_SIDsdom_Match=`echo $i | egrep "^$m_resp$" | wc -l`if [ "$m_Match" -eq "1" ]thenfoundIt=1fidonefiif [ "$foundIt" -eq "0" ]thenprintf "\n\n\n<<<WARNING: [$m_resp] SID entered does not match any in current active list.>>>\n"fielseprintf "\n\n\n<<<NOTE: Make sure the SID [$m_resp] entered is defined in the tnsnames.ora file>>>\n"fim_str="${M_VAR}=$m_resp"eval $m_str}# Function to get a generic Oracle SID.#reqlib_getOracleSid (){M_VAR=$1M_DEF=$2M_TYPE=$3# first we need to get a list of the current SIDs on this machine.#m_SIDs=`egrep -v "#|\*" $REQLIB_ORA_TAB | cut -d: -f 1 | tr '[:space:]' | tr '[a-z] [A-Z]'`printf "\n\n\n\n"printf "Please enter the $M_TYPE server Oracle SID,\n"printf "the current list of active database SIDs on this machine include:\n"printf "$m_SIDs\n"m_resp=`ckstr -d "$M_DEF" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fi# so the user has entered something..# convert what was entered to upper casem_resp=`echo $m_resp | tr '[:lower:]' '[:upper:]'`foundIt=0if [ -n "$m_SIDs" ]thenfor i in $m_SIDsdom_Match=`echo $i | egrep "^$m_resp$" | wc -l`if [ "$m_Match" -eq "1" ]thenfoundIt=1fidonefiif [ "$foundIt" -eq "0" ]thenprintf "\n\n\n<<<WARNING: [$m_resp] SID entered does not match any in current active list.>>>\n"fim_str="${M_VAR}=$m_resp"eval $m_str}# ---------------------------------------------------------------------------------------reqlib_getYesNoQuitResponse ()## a simple function that determines yes/no respones# we pass to the function:# 1) the variable name as a string# 2) the description displayed to the user# 3) the default value## ---------------------------------------------------------------------------------------{m_VAR=$1m_DESC=$2m_DEFAULT=$3m_DEFAULT=`echo $m_DEFAULT | tr '[A-Z]' '[a-z]'`printf "\n\n\n\n"printf "$m_DESC\n"while [ 1 ]docase "$m_resp" in'y' | 'n')break;;'q')exit 3;;;*)m_resp=`ckstr -l 1 -d "${m_DEFAULT}" -p "(default: ${m_DEFAULT}) [y,n,q=quit] :"`m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`;;esacdonem_resp=`echo $m_resp | tr '[a-z]' '[A-Z]'`m_str="${m_VAR}=$m_resp"eval $m_str}# Function to get proxy peer hostname.#reqlib_getHostname (){m_VAR=$1m_DESC=$2m_DEFAULT=$3printf "\n\n\n\n"printf "$m_DESC\n"m_resp=`ckstr -d "${m_DEFAULT}" -p "(default: ${m_DEFAULT}) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fi# lets test to see if the host is contactable#printf "\n"# lets ping the host with 5 sec timeout./usr/sbin/ping $m_resp 5retVal=$?if [ $retVal != 0 ]thenprintf "WARNING: Host [$m_resp] not contactable, ENSURE you check the network config.\n"fim_str="${m_VAR}=$m_resp"eval $m_str}# ---------------------------------------------------------------------------------------reqlib_setProxyClientConnectionType ()## This function asks the user to select the proxy client connection type.## It assumes the input parameters of:## 1. connection type variable name# 2. conection type descriptive string variable name# 3. description presented to the user# 4. the currently set default value.## Currently the user can only select from two types of connections these include:# 1. IPMS# 2. RPC## ---------------------------------------------------------------------------------------{m_CONN_TYPE=$1m_CONN_TYPE_STR=$2m_DESC=$3m_DEFAULT=$4m_DEFAULT=`echo $m_DEFAULT | tr '[A-Z]' '[a-z]'`printf "\n\n\n\n"printf "$m_DESC\n"printf "Note: i = IPMS proxy client connection type\n"printf " r = RPC proxy client connection type\n"printf " q = quit\n"while [ 1 ]docase "$m_resp" in# ipms or rpc'i' | 'r')break;;'q')exit 3;;;*)m_resp=`ckstr -l 1 -d "$m_DEFAULT" -p "(default: $m_DEFAULT) [i,r,q=quit] :"`m_resp=`echo $m_resp | tr '[A-Z]' '[a-z]'`;;esacdonem_str="${m_CONN_TYPE}=$m_resp"eval $m_strif [ "x$m_resp" = "xi" ]thenm_str="${m_CONN_TYPE_STR}=IPMS"elsem_str="${m_CONN_TYPE_STR}=RPC"fieval $m_str}# ---------------------------------------------------------------------------------------reqlib_updateFileTag ()## This function is used to update a tag in a file with a new string, globally.## It assumes the input parameters of:## 1. the location of the file to be updated# 2. the tag to replaced# 3. the value to be substitued## ---------------------------------------------------------------------------------------{m_file=$1m_tag=$2m_nStr=$3if [ "x$m_nStr" = "x" ]thenm_tStr=""elsem_tStr=`echo $m_nStr | sed 's/\//\\\\\//g'`fiecho "Updating file [$m_file] tag [$m_tag] with string [$m_nStr] ..."# in here we need to inform the pkg database that we have# updated the file from the original#installf -c none $PKGINST $m_file fsed "s/<$m_tag>/$m_tStr/g" $m_file > /tmp/xx.tmpif [ $? -eq 0 ]thencp /tmp/xx.tmp $m_filerm /tmp/xx.tmpecho "Updating file [$m_file] tag [$m_tag] completed."elseecho "sed command failed, file [$m_file] not updated."fi# lets inform the pkg database that files have been updated.#installf -f $PKGINST}# ---------------------------------------------------------------------------------------reqlib_updateFileTag2 ()## This function is used to update a tag in a file with a new string, globally.## It assumes the input parameters of:## 1. the location of the file to be updated# 2. the tag to replaced# 3. the value to be substitued## ---------------------------------------------------------------------------------------{m_file=$1m_tag=$2m_nStr=$3if [ "x$m_nStr" = "x" ]thenm_tStr=""elsem_tStr=`echo $m_nStr | sed 's/\//\\\\\//g'`fised "s/$m_tag/$m_tStr/g" $m_file > /tmp/xx.tmpif [ $? -eq 0 ]thencp /tmp/xx.tmp $m_filerm /tmp/xx.tmpelseecho "sed command failed, file [$m_file] not updated."fi}# ---------------------------------------------------------------------------------------reqlib_updateAllFileTags ()## This function is used to update tags in a file with a new string, globally.## It assumes the input parameters of:## 1. the location of the file to be updated# 2 ... A number of args of type A=B where string A in File will be replaced by B## ---------------------------------------------------------------------------------------{m_file=$1shiftsedScript="/tmp/updateAllFileTags.sed.$$"echo "Updating Tags in file [$m_file] as follows"while [ -n "$1" ]dom_tag=`echo $1 | sed -e 's|^ *\([^=]*\)=.*$|\1|' -e 's| *$||'`m_rep=`echo $1 | sed -e 's|^[^=]*= *\(.*\)$|\1|' -e 's| *$||'`echo " [$m_tag] = [$m_rep]"echo "s|<$m_tag>|$m_rep|g" >> $sedScriptshiftdone# in here we need to inform the pkg database that we have# updated the file from the original#installf -c none $PKGINST $m_file feval sed -f $sedScript $m_file > /tmp/xx.tmpif [ $? -eq 0 ]thencp /tmp/xx.tmp $m_filerm /tmp/xx.tmpecho "Updating Tags for file [$m_file] completed."elseecho "sed command failed, file [$m_file] not updated."firm $sedScript# lets inform the pkg database that files have been updated.#installf -f $PKGINST}# ---------------------------------------------------------------------------------------reqlib_cleanLocalFiles ()## this function is used to clean any new local.profile, local.login# and local.cshrc files that are created by the system when you create# a new user. we never use these files.## It assumes the input parameters of:## 1. the location of the user's home directory## ---------------------------------------------------------------------------------------{m_HOMEDIR=$1if [ "x$m_HOMEDIR" = "x" ]thenecho "ERROR: incorrect number of parameters supplied to reqlib_cleanLocalFiles () function."exit 1;firm -f $m_HOMEDIR/local.profilerm -f $m_HOMEDIR/local.loginrm -f $m_HOMEDIR/local.cshrc}# ---------------------------------------------------------------------------------------reqlib_getStrWithSpacesResponse ()## ---------------------------------------------------------------------------------------{M_VAR=$1M_DESC=$2M_DEF=$3printf "\n\n\n\n"printf "$M_DESC"m_resp=`ckstr -d "$M_DEF" -r ".*" -p "(default: $M_DEF) [q=quit] :"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_str="${M_VAR}=\"$m_resp\""eval $m_str}# ---------------------------------------------------------------------------------------reqlib_getRsIDatasrc ()## Function to get the report server data source interface type.## ---------------------------------------------------------------------------------------{M_VAR=$1M_DESC=$2printf "\n\n\n\n"printf "$M_DESC\n"m_resp=`ckitem -o -l "Data Source Type List" "oracle9i - Oracle 9i" "mssqlserver2000 - MS SQLServer 2000"`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_str="${M_VAR}=$m_resp"eval $m_strif [ "x$m_resp" = "xoracle9i" ]then# lets just be sure oracle exists on this machine#reqlib_testOratabConfigfi}# ---------------------------------------------------------------------------------------reqlib_getListEntry ()## Function to get a list item selected by the user.# The list is provided in a simple text file# with the format:## item - description## if the user enters a 'q' or 'Q' the funtion exits.## ---------------------------------------------------------------------------------------{M_VAR=$1M_DESC=$2M_IFILE=$3M_SORT=$4printf "\n\n\n\n"printf "$M_DESC\n"if [ -f "./$M_IFILE" ]then_file="./$M_IFILE"else_file="$INFODIR/$M_IFILE"fiif [ "x$M_SORT" = "xNO_SORT" ]then_sortOption="-n"else_sortOption=""fim_resp=`ckitem -o -f $_file $_sortOption`if [ "x$m_resp" = "xq" -o "x$m_resp" = "xQ" ]thenexit 3;fim_str="${M_VAR}=$m_resp"eval $m_str}# ---------------------------------------------------------------------------------------reqlib_testDBConnection2 ()## this function tests the database connection based on the# data entered by the user.## The input Variables used are:## datasrc,# sid,# user,# passowrd# description.## ---------------------------------------------------------------------------------------{M_DATASRC=$1M_SID=$2M_USER=$3M_PASSWORD=$4M_DESC=$5LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/easysoft/libLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/easysoft/oob/clientLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/easysoft/unixODBC/libexport LD_LIBRARY_PATHprintf "\n\n\n\n"# lets verify we can connect to the database#printf "$M_DESC\n"# we know what to do with various datasrc types#if [ "x$M_DATASRC" = "xoracle9i" ]then# do we even have access to sqlplus?#su - oracle -c ". .profile; sqlplus -? > /dev/null 2>&1"if [ "$?" -ne "0" ]thenprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;fi# we have access to sqlplus, lets try the database entered#rm -f /tmp/xx_lastsql.txtsu - oracle -c ". .profile; sqlplus ${M_USER}/${M_PASSWORD}@${M_SID} <<EOF 1>/tmp/xx_lastsql.txt 2>&1select 1 from dual;exitEOF"if [ -f /tmp/xx_lastsql.txt ]thenOK=`cat /tmp/xx_lastsql.txt | grep ORA- | wc -l`if [ "$OK" -ne "0" ]thenprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;elseprintf "Database connection OK.\n"fielseprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;fielif [ "x$M_DATASRC" = "xmssqlserver2000" ]then# here we test the SQL connectionmyEasySoftLoc="/usr/local/easysoft"myPinger="$myEasySoftLoc/bin/oobpingd"if [ -d "$myEasySoftLoc" ]thenif [ -x "$myPinger" ]then$myPinger -d "DSN=$M_SID;UID=$M_USER;PWD=$M_PASSWORD" > /dev/null 2>&1if [ $? -ne 0 ]thenprintf "Cannot connect to database $M_SID - check database before continuing.\n"exit 1;elseprintf "Database connection OK.\n"fielseprintf "ERROR cannot locate easysoft tool [$myPinger].\n"exit 1;fielseprintf "ERROR cannot locate easysoft default installation location [$myEasySoftLoc].\n"exit 1;fielseecho "\n\n*** Database connection test for datasource [$M_DATASRC] - NOT SUPPORTED (yet!). ***"fi}# EOF, done.