#!/bin/ksh
#程序名称:smpser_install.sh
#作者姓名:*****
#开发时间:2007-08-14
#功能说明:OCS SMPSER安装程序,用来创建SMPSER目录,创建表结构和存储过程
#日志文件
LogDir=$HOME/smp_run/smpser/log
LogFile=${LogDir}/smpser_install.log
SmpserDir=$HOME/smp_run/smpser
#********************************1.LOG FUNCTION**************************************
#以下三个Log函数是报表程序都需要的,其中:
# Log()函数用于在报表程序执行期间向屏幕和LogFile内写日志
# LogStart()函数用于写报表头。
# LogEnd()函数用于写报表尾。
#在调用这些函数前,需要定义的变量为LogFile,用于指明日志文件的
#路径和文件名。例如:
# LogFile=$HOME/smp_run/runlog/smp_report.log
Log()
{
timestr=`date '+%Y-%m-%d %H:%M:%S '`
if [ "-$LogFile" = "-" ]; then
echo "ERROR: LogFile is not defined!"
exit 1
fi
#如果带-s参数,说明既向日志文件输出,同时也需要向屏幕输出
if [ "x$1" = "x-s" ]; then
shift
echo "$*" >> $LogFile
echo "$*"
else
#否则,只向日志文件输出
echo ${timestr}"$*" >> $LogFile
echo ${timestr}"$*"
fi
}
#调用格式:LogStart 程序名
#例如:LogStart $0
LogStart()
{
Log -s " "
Log -s " "
Log "++++++++++ $1 Start ++++++++++"
}
#调用格式:LogEnd 程序名
#例如:LogEnd $0
LogEnd()
{
Log "---------- $1 End ----------"
Log -s " "
}
LogExec()
{
echo "$*"
$* >> $LogFile 2>&1
ST=$?
}
ErrorExit()
{
echo "==== ERROR occured ===="
LogEnd $ProgName
exit $1
}
create_dir()
{
if [ -d $1 ]
then
{
Log "The directory $1 has existed"
}
else
{
Log "create $1"
mkdir -p $1
if [ $? != 0 ];then
ErrorExit 1;
fi
}
fi
}
# ====== main =========
ProgName=`basename $0`
mkdir -p $SmpserDir/log
#取容灾标志 C03B256
redundance_flag=$1
#程序启动日志
LogStart $ProgName
#创建目录
create_dir $SmpserDir/lockfiles
create_dir $SmpserDir/temp
create_dir $SmpserDir/temp/data
create_dir $SmpserDir/temp/backup
create_dir $SmpserDir/temp/bill
create_dir $SmpserDir/temp/billbackup
create_dir $SmpserDir/flag
create_dir $SmpserDir/load
create_dir $SmpserDir/exception
create_dir $SmpserDir/exception/report
create_dir $SmpserDir/updatetable
#是否已经安装SMP数据库
if [ "-$SMPDBNAME" = "-" ]; then
Log "----You must install SMP database firstly."
exit 1
fi
#判断数据库类型
if [ "-$DBSERVERTYPE" = "-" ]; then
Log "env DBSERVERTYPE is not set, default INFORMIX"
DBSERVERTYPE="INFORMIX"
#exit 1
fi
if [ "-$DBSERVERTYPE" = "-INFORMIX" ]; then
if [ "-${redundance_flag}" = "-Y" ]; then
LogEnd $ProgName
exit 0
fi
Log "entironment DBSERVERTYPE is Informix"
Log "---- Create table using smpser_install.sql ..."
LogExec dbaccess $SMPDBNAME smpser_install.sql
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create sp_upd_rptstatus procedure."
LogExec dbaccess $SMPDBNAME sp_upd_rptstatus.sql
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using smpser_install_stc.sql ..."
LogExec dbaccess $SMPDBNAME smpser_install_stc.sql
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using smpser_install_community.sql ..."
LogExec dbaccess $SMPDBNAME smpser_install_community.sql
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
#Iran-MCCI report add
Log "---- Create table using smpser_install_mci.sql ..."
LogExec dbaccess $SMPDBNAME smpser_install_mci.sql
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using smpser_install_rptmain.sql ..."
LogExec dbaccess $SMPDBNAME smpser_install_rptmain.sql
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
elif [ "-$DBSERVERTYPE" = "-ORACLE" ]; then
Log "DBSERVERTYPE is Oracle"
cd $HOME/smp_run/smpser/dbinstall
#oracle需要增加32位库
if [ "-$DBSERVERTYPE" = "-ORACLE" ]; then
EnvFile=../install/.smpser_ora.env
if [ -f $EnvFile ]; then
rm -f $EnvFile
fi
touch $EnvFile
echo 'if ( $?LD_LIBRARY_PATH ) then ' >> $EnvFile
echo 'setenv LD_LIBRARY_PATH ${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}' >> $EnvFile
echo 'else ' >> $EnvFile
echo 'setenv LD_LIBRARY_PATH ${ORACLE_HOME}/lib ' >> $EnvFile
echo 'endif '>> $EnvFile
if [ "1"="$?LD_LIBRARY_PATH" ]; then
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
else
export LD_LIBRARY_PATH=${ORACLE_HOME}/lib
fi
echo 'if ( $?SHLIB_PATH ) then ' >> $EnvFile
echo 'setenv SHLIB_PATH ${ORACLE_HOME}/lib:${SHLIB_PATH}' >> $EnvFile
echo 'else ' >> $EnvFile
echo 'setenv SHLIB_PATH ${ORACLE_HOME}/lib ' >> $EnvFile
echo 'endif '>> $EnvFile
if [ "1"="$?SHLIB_PATH" ]; then
export SHLIB_PATH=${ORACLE_HOME}/lib:${SHLIB_PATH}
else
export SHLIB_PATH=${ORACLE_HOME}/lib
fi
echo 'if ( $?LIBPATH ) then ' >> $EnvFile
echo 'setenv LIBPATH ${ORACLE_HOME}/lib:${LIBPATH}' >> $EnvFile
echo 'else ' >> $EnvFile
echo 'setenv LIBPATH ${ORACLE_HOME}/lib ' >> $EnvFile
echo 'endif '>> $EnvFile
if [ "1"="$?LIBPATH" ]; then
export LIBPATH=${ORACLE_HOME}/lib:${HOME}/smp_run/smpser/bin:${LIBPATH}
else
export LIBPATH=${ORACLE_HOME}/lib:${HOME}/smp_run/smpser/bin
fi
echo 'if ( $?PATH ) then ' >> $EnvFile
echo 'setenv PATH ${HOME}/smp_run/smpser/bin:${PATH}' >> $EnvFile
echo 'else ' >> $EnvFile
echo 'setenv PATH ${HOME}/smp_run/smpser/bin ' >> $EnvFile
echo 'endif '>> $EnvFile
if [ "1"="$?PATH" ]; then
export PATH=${HOME}/smp_run/smpser/bin:${PATH}
else
export PATH=${HOME}/smp_run/smpser/bin
fi
echo "source $HOME/smp_run/smpser/install/.smpser_ora.env" >> $HOME/.cshrc
#echo 'setenv SHLIB_PATH ${ORACLE_HOME}/lib:${SHLIB_PATH} ' >> ../install/.smpser_ora.env
#echo 'setenv LIBPATH ${ORACLE_HOME}/lib:${LIBRARY}' >> ../install/.smpser_ora.env
#echo 'setenv PATH ${HOME}/smp_run/smpser/bin:${PATH}' >> ../install/.smpser_ora.env
#echo "source $HOME/smp_run/smpser/install/.smpser_ora.env" >> $HOME/.cshrc
#export LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${LD_LIBRARY_PATH}
#export SHLIB_PATH=${ORACLE_HOME}/lib:${SHLIB_PATH}
#export LIBPATH=${ORACLE_HOME}/lib:${LIBPATH}
#export PATH=${HOME}/smp_run/smpser/bin:${PATH}
fi
if [ "-${redundance_flag}" = "-Y" ]; then
LogEnd $ProgName
exit 0
fi
#cd $HOME/smp_run/smpser/dbinstall/
#PASSWD="`getpwd $SMPDBNAME`" #取得数据库密码
PASSWD=${SMP_ORA_DB_PASS}
Log "---- Create table using smpser_install.sql ..."
Log "cat oracle/smpser_install.sql | sqlplus $SMPDBNAME/******"
cat oracle/smpser_install.sql | sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE >> $LogFile 2>&1
ST=$?
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using sp_upd_rptstatus.sql ..."
Log "cat oracle/sp_upd_rptstatus.sql | sqlplus $SMPDBNAME/******"
cat oracle/sp_upd_rptstatus.sql | sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE >> $LogFile 2>&1
ST=$?
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE <<EOF
@oracle/sp_upd_rptstatus.sql
/
exit
EOF
Log "---- Create table using smpser_install_stc.sql ..."
Log "cat oracle/smpser_install_stc.sql | sqlplus $SMPDBNAME/******"
cat oracle/smpser_install_stc.sql | sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE >> $LogFile 2>&1
ST=$?
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using smpser_install_community.sql ..."
Log "cat oracle/smpser_install_community.sql | sqlplus $SMPDBNAME/******"
cat oracle/smpser_install_community.sql | sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE >> $LogFile 2>&1
ST=$?
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using smpser_install_mci.sql ..."
Log "cat oracle/smpser_install_mci.sql | sqlplus $SMPDBNAME/******"
cat oracle/smpser_install_mci.sql | sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE >> $LogFile 2>&1
ST=$?
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
Log "---- Create table using smpser_install_rptmain.sql ..."
Log "cat oracle/smpser_install_rptmain.sql | sqlplus $SMPDBNAME/$PASSWD"
cat oracle/smpser_install_rptmain.sql | sqlplus $SMPDBNAME/$PASSWD@$ORACLE_INSTANCE >> $LogFile 2>&1
ST=$?
if [ $ST -ne 0 ]; then
ErrorExit 1;
fi
fi
#结束日志
LogEnd $ProgName
exit 0