#!/bin/sh

PKGADD=/usr/sbin/pkgadd
PKGINFO=/usr/bin/pkginfo
PKGRM=/usr/sbin/pkgrm
WHOAMI=/usr/ucb/whoami
CAT=/usr/bin/cat
TAR=/usr/bin/tar
CP=/usr/bin/cp
RM=/usr/bin/rm
CHMOD=/usr/bin/chmod
CHOWN=/usr/bin/chown
CHGRP=/usr/bin/chgrp
LN=/usr/bin/ln
DU=/usr/bin/du
AWK=/usr/bin/awk
SED=/usr/bin/sed
PWD=/usr/bin/pwd
MKDIR=/usr/bin/mkdir
GREP=/usr/bin/grep
ECHO=/usr/bin/echo
BASENAME=/usr/bin/basename
DATE=/usr/bin/date
TM_BIN=/opt/HiCommand/TuningManager/bin		# 40H0123 C
HTM_INSTALLED=0	# 04H0512 A

DIRNAME=/opt/HiCommand/TuningManager
RESPONSE_FILE=/tmp/htm.response.$$
LICENSE_KEY_FILE=/tmp/htm.license.key
LOG_DIR=/tmp
LOG_FILE=$LOG_DIR/htm-install-cd1.log
TO_LOG='>> $LOG_FILE'
LIC_PACKAGE="HTMCD1"
OLD_PKGS="HTMAnt HTMSNMP HTMApache HTMTomcat HTMJava HTMJars"
OLD_IPKGS="HTMMain"
CURRENT_VERSION="none"
OLD_VERSION=1
PFM_CHECK_FILE="/opt/jp1pc/instmgr.ini"
TARGET_VERSION="5.8"                            #41H0006 C 51H0001 C 55H0006 C 57H0015 C 58H0002 C
PROPERTIES_DIR=/opt/HiCommand/TuningManager/inst	# 40H0123 A
DOWN_INSTALL_MODE=0								# 40H0425 C
CD1_DOWNINSTOALL_FILE=/tmp/cd1_downinstoall_file	# 40H0596 A
EGREP=/usr/bin/egrep						# 40H0635 A
CUT=/usr/bin/cut                            # 50H0057 A
HTM_PKG_CAPA_EN_0=0                         # デフォルト容量(MB) 50H0057 A
HTM_PKG_CAPA_EN_3=30                        # Ver3.x EN 容量(MB) 50H0057 A
HTM_PKG_CAPA_EN_4=30                        # Ver4.x EN 容量(MB) 50H0057 A
HTM_PKG_CAPA_EN_5=30                        # Ver5.x EN 容量(MB) 50H0057 A
HTM_PKG_CAPA_JP_0=0                         # デフォルト容量(MB) 50H0057 A
HTM_PKG_CAPA_JP_3=30                        # Ver3.x JP 容量(MB) 50H0057 A
HTM_PKG_CAPA_JP_4=30                        # Ver4.x JP 容量(MB) 50H0057 A
HTM_PKG_CAPA_JP_5=30                        # Ver5.x JP 容量(MB) 50H0057 A
HTMCD1_PKGINFO=/var/sadm/pkg/HTMCD1/pkginfo # 50H0057 A
PFM_BASE_CHECK_FILE="/opt/jp1pc/instagtp.ini"   # JP1/PFM-Baseインストール情報ファイル # 57H0021 A
HTM_CM_CHECK_FILE="/opt/jp1pc/TunMgr.dat"       # HTM-MCインストール情報ファイル       # 57H0021 A

PATCH_HISTORY=/opt/HiCommand/TuningManager/patch_history        # 修正パッチ履歴ファイル 57H0206 C
PATCHLOG_TXT=/opt/HiCommand/TuningManager/logs/PATCHLOG.TXT     # 修正パッチログファイル 57H0206 C
PATCH_BACKUP_DIR=/opt/HiCommand/TuningManager/patch_backup_dir  # 修正パッチバックアップディレクトリ 57H0206 C

unalias cd > /dev/null 2>&1

#### Functions/Routines ####

###############################################################################
#
# 40H0123 A START
#
###############################################################################
#名前：RecommendBackup
#詳細：HTnMは新規インストールであるが、他のHiCommand Suite製品が
#インストール済みの場合、インストールの前に、HBaseのデータベース，
#および他のHiCommand Suite製品のデータベースをバックアップしておく
#ことを推奨する旨のメッセージを表示する。
#復帰コード RC_RECOMMENDBACKUP  1:  継続
#                               2:  中断
RecommendBackup() {

    # 40H0439 C 57H0016 C 57H0116 C START 57H0203 C START
    printf "\nIf other HiCommand Suite products have already been installed, "
    printf "we strongly recommend that you back up the HiCommand Common "
    printf "Component database, as well as the database of each HiCommand "
    printf "Suite product.\n"
    printf "However, if the database was created by using HiCommand Tuning "
    printf "Manager version 4.0 or later, you can acquire the backup data "
    printf "during the installation.\n"
    # 40H0439 C 57H0016 C 57H0116 C STOP 57H0203 C STOP
	while [ 1 ];
	do
        # 40H0437 57H0016 C 57H0116 C START 57H0203 C START
        printf "\nTo continue installation, press [Y].\n"
        printf "If either of the following conditions exists, we strongly "
        printf "recommend that you acquire the backup data in advance: \n"
        printf " - The version of HiCommand Tuning Manager is 3.5 or earlier.\n"
        printf " - The version of HiCommand Tuning Manager is 4.0 or later, "
        printf "but the database is version 3.5 or earlier (the database has "
        printf "not been converted to 4.0 or later).\n"
        printf "For details, see the HiCommand Tuning Manager Administration "
        printf "Guide.\n"
        printf "To cancel installation, press [N]. (Default Y) Y/N  > "
        # 40H0437 57H0016 C 57H0116 C STOP 57H0203 C STOP
        read USER_RESPONSE
		htmInstallLog "Recommended back up the HiCommand Common Component database. user input:[$USER_RESPONSE]"  # 40H0635 A

        
		checkZero "$USER_RESPONSE" 				# 40H0635 A
		ISZERO=$?                               # 40H0635 A
		if [ $ISZERO -eq 1 ]; then              # 40H0635 C
            RC_RECOMMENDBACKUP=1
            break
        fi

		case "${USER_RESPONSE}" in			# 40H0635 start
			[Yy])
	            RC_RECOMMENDBACKUP=1
	            break
				;;
			[Nn])
	            RC_RECOMMENDBACKUP=2
	            break
				;;
		esac								# 40H0635 end
    done
    return $RC_RECOMMENDBACKUP
}

#名前：checkPropertyFile
#詳細：プロパティファイルチェックをする。
#引数１：PropertyFile
#引数２：キーワード
#復帰コード RC_CHECKPROPERTYFILE  0:  正常終了
#                                 1:  引数エラー
#                                 2:  文字列エラー
#           RC_CHECKPROPERTYFILE_VALUE
#                                  :  キーワードパラメータの値(＝の右辺)
checkPropertyFile() {
    PARAM1=$1
    PARAM2=$2

    #プロパティファイル
    #文字列があるか？
    if [ -z "$PARAM1" ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    #ファイルがあるか？
    if [ ! -f "$PARAM1" ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    #キーワード
    #文字列があるか？
    if [ -z "$PARAM2" ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    #キーワードを含む行を取得
    GREP_VALUE=`grep $PARAM2 $PARAM1`
    GREP_RC=$?

    #キーワードが見つからない場合
    if [ $GREP_RC -ne 0 ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    #キーワードを含む行が空の場合
    if [ -z "$GREP_VALUE" ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    #キーワードの右辺を取得
    CUT_VALUE=`echo $GREP_VALUE|cut -f2 -d'='`
    CUT_RC=$?

    #キーワードの右辺が見つからない場合
    if [ $CUT_RC -ne 0 ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    #キーワードの右辺が空の場合
    if [ -z "$CUT_VALUE" ]; then
        RC_CHECKPROPERTYFILE=1
        return 1
    fi

    RC_CHECKPROPERTYFILE_VALUE=$CUT_VALUE
    return 0
}

#NAME : checkCapacity
#DETAIL : Check Disk Capacity
#PARAM1 :Specified Directory
#PARAM2 : Specified Capacity(MB)
#RETURN CODE :  RC_CHECKCAPACITY  0:  OK
#RETURN CODE :  RC_CHECKCAPACITY  1:  NG(Parameter Error)
#RETURN CODE :  RC_CHECKCAPACITY  2:  NG(Capacity Over)
checkCapacity() {
	PARAM1=$1
	PARAM2=$2

	if [ ! -d "$PARAM1" ]; then
		DIRNAME="$PARAM1"
		while : ;
		do
			DIRNAME=`dirname "$DIRNAME"`
			if [ -d "$DIRNAME" ]; then
				htmInstallLog "checkCapacity (Mount=$CAPACITYDIRNAME Dir=$PARAM1)"	# 40H0401 C
				PARAM1=$DIRNAME
				break;
			fi
		done
	fi

	if [ $PARAM2 -le 0 ]; then      # 50H0078 50H0084 C
		return 0                    # 50H0084 C
	fi

	# 40H0602 C START
	set `df -k $PARAM1 | $SED "1d"`   # 50H0064
	TARGET_MP=$6                      # 50H0064
	TARGET_MP_CAPA=$4                 # 50H0064
	# 40H0602 C END

	CURRENT_CAPCITY_MB=`expr $TARGET_MP_CAPA / 1024`

    for CNT in 1 2 3 4
    do
        eval MOUNT_POINT=\$MOUNT_POINT_${CNT}             #マウントポイントを代入
        eval MOUNT_POINT_CAPA=\$MOUNT_POINT_CAPA_${CNT}   #マウントポイントの容量を代入
        if [ -z "${MOUNT_POINT}" ]; then
            MOUNT_POINT=${TARGET_MP}    # 40H0609 C
            MOUNT_POINT_CAPA=${PARAM2}
            htmInstallLog "checkCapacity (Capa=${PARAM2}, Total Capa=${MOUNT_POINT_CAPA}, Dir=${PARAM1})"    # 40H0401 C
            htmInstallLog "checkCapacity (avail=${CURRENT_CAPCITY_MB},  Mount On=${TARGET_MP})"    # 40H0401 C
            if [ ${CURRENT_CAPCITY_MB} -ge ${MOUNT_POINT_CAPA} ]; then
                eval MOUNT_POINT_${CNT}=${MOUNT_POINT}
                eval MOUNT_POINT_CAPA_${CNT}=${MOUNT_POINT_CAPA}
                return 0
            else
                return 2
            fi
        else
            if [ "${TARGET_MP}" = "${MOUNT_POINT}" ]; then    # 40H0609 C
                MOUNT_POINT_CAPA=`expr ${MOUNT_POINT_CAPA} + ${PARAM2}`
                TOTAL_CAPA=${MOUNT_POINT_CAPA}
                htmInstallLog "checkCapacity (Cap=${PARAM2}, Total Capa=${MOUNT_POINT_CAPA}, Dir=${PARAM1})"    # 40H0401 C
                htmInstallLog "checkCapacity (avail=${CURRENT_CAPCITY_MB},  Mount On=${TARGET_MP})"    # 40H0401 C
                if [ ${CURRENT_CAPCITY_MB} -ge ${MOUNT_POINT_CAPA} ]; then
                    eval MOUNT_POINT_${CNT}=$MOUNT_POINT
                    eval MOUNT_POINT_CAPA_${CNT}=${MOUNT_POINT_CAPA}
                    return 0
                else
                    return 2
                fi
            fi
        fi
    done
}


# 40H0401 A START 
#NAME : htmInstallLog
##DETAIL : write htm log into logfile
##PARAM2 :message
##PARAM3 :line feed
htmInstallLog() {
	if [ ! -z "$1" ]; then
		printf "`date '+%y/%m/%d %H:%M:%S'` $1\n" >> $LOG_FILE
	fi
}
# 40H0401 A END 

# 40H0493 A START
#NAME : checkDowninstall
#DETAIL : ダウンインストールチェック。
#PARAM1 : Pplistd
#PARAM2 : キーワード
#RETURN CODE  0 : 修復インストール                  (40H0650)
#             1 : ダウンインストール                (40H0650)
#             2 : アップグレードインストール        (40H0650)
checkDowninstall() {
	PARAM1=$1
	PARAM2=$2

	# 40H0596 C START
	# CD1ダウンインストール完了フラグファイルがある場合、修復インストール
	if [ -f $CD1_DOWNINSTOALL_FILE ]; then
		return 0
	fi
	# 40H0596 C END

	# For down grade 
	# 前回のVVRRSSを取得する
	checkPplistd $PARAM1 $PARAM2
	RC_PRE_REVISION=$?
	if [ $RC_PRE_REVISION -eq 0 ]; then	# 40H0263 C  
		if [ -z "$CHECKPPLISTD_VALUE" ]; then
			PRE_REVISION_VALUE=""
			RC_CHECKDOWNINSTALL=0
		else
			PRE_REVISION_VALUE=$CHECKPPLISTD_VALUE
		fi
	else
		RC_CHECKDOWNINSTALL=0
	fi

	# 今回のVVRRSSを取得する
	CHECKPPLISTD_BASENAME=`basename $PARAM1`
	checkPplistd $CD_DIRECTORY/$CHECKPPLISTD_BASENAME $PARAM2
	RC_CUR_REVISION=$?
	if [ $RC_CUR_REVISION -eq 0 ]; then	# 40H0263 C  
		if [ -z "$CHECKPPLISTD_VALUE" ]; then
			CUR_REVISION_VALUE=""
			RC_CHECKDOWNINSTALL=0
		else
			CUR_REVISION_VALUE=$CHECKPPLISTD_VALUE
		fi
	else
		RC_CHECKDOWNINSTALL=0
	fi

	# 前回・今回のリビジョンを比較する
	if [ $RC_PRE_REVISION -eq 0 -a $RC_CUR_REVISION -eq 0 ]; then
		RC_REVISION_COMP=`expr "$PRE_REVISION_VALUE" \> "$CUR_REVISION_VALUE" `
	    if [ $RC_REVISION_COMP -eq 1 ]; then	# 今回のリビジョンが小さいか？
	         RC_CHECKDOWNINSTALL=1
		else
            # 40H0650 ADD START
            RC_REVISION_COMP=`expr "$PRE_REVISION_VALUE" \< "$CUR_REVISION_VALUE" `
            if [ $RC_REVISION_COMP -eq 1 ]; then    # 今回のリビジョンが大きいか？
                 RC_CHECKDOWNINSTALL=2
            else
                 RC_CHECKDOWNINSTALL=0
            fi
            # 40H0650 ADD END
	    fi
	else
         RC_CHECKDOWNINSTALL=0
	fi
	return $RC_CHECKDOWNINSTALL
}

#NAME : checkPplistd
#DETAIL : Pplistdファイルチェックをする。
#PARAM1 : Pplistd
#PARAM2 : キーワード
#RETURN CODE :  RC_CHECKPROPERTYFILE  0:  正常終了
#								 1:  引数エラー
#		   RC_CHECKPROPERTYFILE_VALUE
#								  :  パラメータの値
checkPplistd() {
	PARAM1=$1
	PARAM2=$2

	RC_CHECKPROPERTYFILE_VALUE=""
	#プロパティファイル
	#文字列があるか？
	if [ -z "$PARAM1" ]; then
		return 1
	fi

	#ファイルがあるか？
	if [ ! -f "$PARAM1" ]; then
		return 1
	fi

	#キーワードを含む行を取得
	CHECKPPLISTD_VALUE=`grep "$PARAM2" $PARAM1 | cut -c29,30`
	return 0
}
# 40H0493 A END

###############################################################################
#
# 40H0123 A END
#
###############################################################################

stop_old() {
	htmInstallLog "Entering stop_old() routine\n"  	# 40H0401 C
	## stop Tomcat ##
	if [ -f "/etc/init.d/htm-tomcat" ]; then
		/etc/init.d/htm-tomcat stop > /dev/null 2>&1
	fi

	## stop Apache ##
	if [ -f "/etc/init.d/htm-apache" ]; then
		/etc/init.d/htm-apache stop > /dev/null 2>&1
	fi

	htmInstallLog "Exiting stop_old() routine\n"  	 	# 40H0401 C
}

save_db() {

	htmInstallLog "Entering save_db() routine\n"	# 40H0401 C
    # we need to save the current database
    # so let's find out where it's located

    if [ $CURRENT_VERSION = "1.0" ]; then
       INSTALL=`$CAT /var/sadm/pkg/HTMApache/pkginfo | $GREP HTMINSTALL | sed 's/^.*=//g'`
    else
       INSTALL=/opt/HiCommand/TuningManager
    fi


    if [ $? -eq 0 ]; then
	# ok we got a value, but is it really a directory #
	if [ -d "$INSTALL" ]; then
            CWD=`$PWD`
	    cd ${INSTALL}
            SIZE=`$DU -sk $INSTALL/data | $GREP data | $AWK '{print $1;}'`
            while :
            do
                printf "\nSpecify a directory to backup previous database\n"
                printf "Required disk space is $SIZE KB: "

                read BACKUPDIR
				checkZero "$BACKUPDIR" 					# 40H0635 A 
				ISZERO=$?                               # 40H0635 A
				if [ $ISZERO -eq 1 ]; then              # 40H0635 C
					continue
				fi
                if [ -d "$BACKUPDIR" ]; then
                    break
                else
                    $MKDIR -p "$BACKUPDIR"				# 40H0635 C
                    if [ $? -ne 0 ]; then 
                        printf "*** Unable to create directory\n"
                    else
                        break
                    fi
                fi
            done

            DB_TAR_FILE="$BACKUPDIR/htm_db_backup.tar"
	    printf "Backing up previous database to $DB_TAR_FILE...\n"
	    $TAR cfh $DB_TAR_FILE data
	    printf "Done\n"
            cd $CWD

	fi
    fi
	htmInstallLog "Exiting save_db() routine\n"	# 40H0401 C
}

remove_old() {

	htmInstallLog "Entering remove_old() routine\n"	# 40H0401 C
if [ $CURRENT_VERSION = "1.0" ]; then     
	OLD_PKGS="HTMAnt HTMSNMP HTMApache HTMTomcat HTMJava HTMJars"
	OLD_IPKGS="HTMMain"
fi


if [ $CURRENT_VERSION = "1.1" ]; then     
	OLD_PKGS=""
	OLD_IPKGS=""
fi

	for pkg in $OLD_PKGS
		do
			$PKGINFO $pkg > /dev/null 2>&1
			if [ $? -eq 0 ]; then
				$PKGRM -n $pkg
			fi
		done

	for pkg in $OLD_IPKGS  # these packages require interactivity
		do
			$PKGINFO $pkg > /dev/null 2>&1
			if [ $? -eq 0 ]; then
				$PKGRM $pkg
			fi
		done

	htmInstallLog "Exiting remove_old() routine\n"	# 40H0401 C
}

isHbaseRunning() {
	htmInstallLog "Entering isHbaseRunning() routine\n" 	# 40H0401 C
 # check if any HiCommand Services are running
 # stop them if they are
 _hicommand="/opt/HiCommand/Base/bin"
 HCMDSSRV="${_hicommand}/hcmdssrv"

 if [ -x ${HCMDSSRV} ]; then
	
	${HCMDSSRV} -check -nolog
	if [ $? -gt 0 ]; then
		printf  "Please stop all HiCommand processes and run $0 again\n"
		exit 1
	fi
 fi

	htmInstallLog "Exiting isHbaseRunning() routine\n" 		# 40H0401 C
}
	 			
	
checkPkgAdm() {

	htmInstallLog "Entering checkPkgAdm() routine\n"  	# 40H0401 C
	REQUIRED_VALUE="rewrite"
	ADM_FILE="/var/sadm/install/admin/default"
	
	if [ ! -f "$ADM_FILE" ]; then
		printf "System package admin file not found, will be unable to upgrade the HiCommand components.\n"
		HTMCLMGR_UPGRADE="FALSE"
		return
	fi

	# otherwise get the value for the 'instance' property and make sure it's "rewrite"
	
# 40H0618 d START
#	VALUE=`$CAT $ADM_FILE | $GREP instance | sed 's/instance=//g'`

#        if [ $VALUE != "$REQUIRED_VALUE" ]; then
#                printf "The value for the 'instance' property in $ADM_FILE currently reads:\ninstance=$VALUE\n"
#                printf "In order to upgrade a HiCommand component it must read:\ninstance=$REQUIRED_VALUE\n"
#                printf "Please change the 'instance' value and run $0 again\n"
#		printf "( You may wish to restore the original value after the installation is complete. )\n"
#                exit 1
#        fi
# 40H0618 d END
	htmInstallLog "Exiting checkPkgAdm() routine\n"  	# 40H0401 C
}


##NAME : checkZero
#DETAIL : パラメータが空文字かどうか判定する
#引数1  : チェック対象文字列
#RETURN CODE :  1 - 空文字,  0 - 空文字以外
checkZero() {											# 40H0635 A start
  if [ `echo "$1" | $EGREP -c "^.+$"` -eq 0 ]; then
    return 1
  fi
  return 0
}														# 40H0635 A end

# 50H0091 A START
#NAME : putVersionToLog
#DETAIL : バージョン情報をインストールログに出力する。                          55H0008 C
#       : 初期メッセージに出力するバージョン情報文字列を作成を作成する。        55H0008 C
#バージョン情報文字列：v.r. 0 (v.r.0-g)                                         55H0008 C
#  v   : バージョン番号。                                                       55H0008 C
#  r   : リリース番号。                                                         55H0008 C
#  0   : 0固定。                                                                55H0008 C
#  g   : 限定コード（01〜99）。                                                 55H0008 C
#OUTPUT:INIT_MSG_VERSION_STR:初期メッセージに表示する詳細バージョン情報文字列   55H0008 C
#RETURN CODE  なし
putVersionToLog() {

    #前バージョン(R)を取得
    $PKGINFO -q HTMCD1
    if [ $? -eq 0 ]; then    # アップグレード・修復インストール
        LOG_PRE_VERSION=`${CAT} ${HTMCD1_PKGINFO} | ${GREP} "^VERSION=" | ${SED} 's/^.*=//g'| ${CUT} -d. -f1`
        LOG_PRE_REVISION=`${CAT} ${HTMCD1_PKGINFO} | ${GREP} "^VERSION=" | ${SED} 's/^.*=//g'| ${CUT} -d. -f2`
        # 前回のVVRRSSを取得する
        checkPplistd /opt/HiCommand/TuningManager/pplistd "HiCommand Tuning Manager"
        RC_PRE_SLANT=$?
        if [ $RC_PRE_SLANT -eq 0 ]; then
            LOG_PRE_SLANT=$CHECKPPLISTD_VALUE
        else
            LOG_PRE_SLANT="xx"
        fi
        PRE_VERSION_STR=`printf "%s.%s.0-%s" ${LOG_PRE_VERSION} ${LOG_PRE_REVISION} ${LOG_PRE_SLANT}`
        htmInstallLog "INSTALLED VERSION : ${PRE_VERSION_STR}"
    fi

    #今バージョン(R)を取得
    LOG_CUR_VERSION=`$ECHO ${TARGET_VERSION} | ${CUT} -d. -f1`
    LOG_CUR_REVISION=`$ECHO ${TARGET_VERSION} | ${CUT} -d. -f2`

    # 今回のVVRRSSを取得する
    checkPplistd ${CD_DIRECTORY}/pplistd "HiCommand Tuning Manager"
    RC_CUR_SLANT=$?
    LOG_CUR_SLANT="xx"
    if [ $RC_CUR_SLANT -eq 0 ]; then    # 40H0263 C  
        LOG_CUR_SLANT=$CHECKPPLISTD_VALUE
    fi
    CUR_VERSION_STR=`printf "%s.%s.0-%s" ${LOG_CUR_VERSION} ${LOG_CUR_REVISION} ${LOG_CUR_SLANT}`
    htmInstallLog "TARGET VERSION : ${CUR_VERSION_STR}"

    # 55H0008 A START
    # 初期メッセージに出力するバージョン情報文字列を作成
    INIT_MSG_VERSION_STR=`printf "%s.%s.0(%s.%s.0-%s)" ${LOG_CUR_VERSION} ${LOG_CUR_REVISION} ${LOG_CUR_VERSION} ${LOG_CUR_REVISION} ${LOG_CUR_SLANT}`
    # 55H0008 A END

}
# 50H0091 A END

#### End Functions/Routines ####




##############
#### MAIN ####
##############

### start log file
STAMP=`$DATE`
htmInstallLog "\n*************************************\n"  	 	# 40H0401 C
htmInstallLog "Beginning TM-CD1 install ( $STAMP )\n"  	# 40H0401 C

# Installer Absolute path check
RC_CMD_ABSO_CHECK=`echo "$0" |egrep -c "^/"`                    # 50H0050
if [ ${RC_CMD_ABSO_CHECK} -eq 0 ]; then                         # 50H0050
    $ECHO "To start the installer, specify the absolute path"   # 50H0050
    htmInstallLog "To start the installer, specify the absolute path" # 50H0050
    exit                                                        # 50H0050
fi                                                              # 50H0050

START_LOCATION=`$PWD`
script=`$BASENAME $0`
CD_DIRECTORY=`$ECHO $0 | $SED "s/\/$script//g"`

## move onto the cd
cd $CD_DIRECTORY

if [ `$WHOAMI` != "root" ]; then
    $ECHO "You must be root to install HiCommand Tuning Manager"
    htmInstallLog "Error: must be root to install HTM" 
    exit
fi

# 40H0615 a start
while [ 1 ];
do
	printf "WARNING: The kernel parameters must be set before installing HiCommand "
	printf "Tuning Manager.\nIf the kernel parameters have not been set, enter n to "
	printf "cancel installation.\nIf the kernel parameters have been set, enter y to"
	printf " continue installation.\nHave the kernel parameters for HiCommand Tuning"
	printf " Manager been set? Y/N > "
	read USER_RESPONSE
	htmInstallLog "[$USER_RESPONSE] was input at WARNING of kernel parameters."

	case "${USER_RESPONSE}" in			# 40H0635 start
		[Yy])
			break
			;;
		[Nn])
			exit
			;;
	esac								# 40H0635 end

done
# 40H0615 a end


# 41H0021 ADD START
# check the status of Device Manager Server(HiCommandService)
htmInstallLog "check the status of Device Manager Server(HiCommandService)" 
if [ -x "/opt/HiCommand/hicommand.sh" ]; then
    /opt/HiCommand/hicommand.sh status2
    DVCSTS=$?
    if [ ${DVCSTS} -eq 0 -o ${DVCSTS} -eq 2 ]; then
        printf "Please stop Device Manager Server and run $0 again\n"
        htmInstallLog "Error: Device Manager processes running, user alerted\n" 
        exit 1
    elif [ ${DVCSTS} -ge 3 ]; then
        printf "Getting the status of Device Manager Server is failed\n"
        htmInstallLog "Error: Getting the status of Device Manager Server is failed, return code -> $DVCSTS" 
        exit 1
    else
        htmInstallLog "Device Manager Server is stopped" 
    fi
fi
# 41H0021 ADD END

isHbaseRunning

# PFM - Managerがインストールされているかチェック
# 40H0204 A START 
htmInstallLog "Check for PFM - Manager" 
if [ -f "$PFM_CHECK_FILE" ]; then
    PFM_CHECK_COUNT1=`grep -c "P-9D2C-A.62" ${PFM_CHECK_FILE}`    # 51H0109    # 51H0109
    PFM_CHECK_COUNT2=`grep -c "P-9D2C-A.72" ${PFM_CHECK_FILE}`    # 51H0109    # 51H0109
    PFM_CHECK_COUNT3=`grep -c "P-9D2C-A.82" ${PFM_CHECK_FILE}`    # 51H0109    # 51H0109
    if [ ${PFM_CHECK_COUNT1} -gt 0 -o ${PFM_CHECK_COUNT2} -gt 0 -o ${PFM_CHECK_COUNT3} -gt 0 ]; then    # 51H0109

        #ProductIDを取得
        checkPropertyFile "$PFM_CHECK_FILE" "ProductID"
        if [ ! -z "$RC_CHECKPROPERTYFILE_VALUE" ]; then
            PRODUCTID_VALUE=$RC_CHECKPROPERTYFILE_VALUE    # 50H0030
        fi

        #ExCurrentVersionを取得
        checkPropertyFile "$PFM_CHECK_FILE" "ExCurrentVersion"
        if [ ! -z "$RC_CHECKPROPERTYFILE_VALUE" ]; then
            EXCURRENTVERSION_VALUE=$RC_CHECKPROPERTYFILE_VALUE    # 50H0030
        fi

        #ExCurrentVersionを取得
        checkPropertyFile "$PFM_CHECK_FILE" "ProgramName"
        if [ ! -z "$RC_CHECKPROPERTYFILE_VALUE" ]; then
            PROGRAMNAME_VALUE=$RC_CHECKPROPERTYFILE_VALUE    # 50H0030
        fi

		# 40H0561 C START
        printf "The following product is installed, "
        printf "so HiCommand Tuning Manager $TARGET_VERSION\n"
        printf "cannot be installed.\n\n"
        printf "Product ID: $PRODUCTID_VALUE\n"
        printf "Product name : $PROGRAMNAME_VALUE\n"
        printf "version : $EXCURRENTVERSION_VALUE\n"
		# 40H0561 C END

        exit

    fi
fi
# 40H0204 A END

# JP1/PFM-Baseがインストールされているかチェック
# 57H0021 A START 
htmInstallLog "Check for JP1/PFM-Base" 
# 57H0141 C START
if [ -f "${PFM_BASE_CHECK_FILE}" ]; then
    # JP1/PFM-Baseインストール情報ファイル有り場合、HTM-MC5.7以上はインストール不可。それ以外はインストール可
    # 57H0202 C START
    htmInstallLog "You cannot install HiCommand Tuning Manager on a server on "
    htmInstallLog "which agents have already been installed. To install HiCommand"
    htmInstallLog "Tuning Manager and agents on the same server, install as follows:\n"
    htmInstallLog "(1) Back up the agent data, and then uninstall all agents.\n"
    htmInstallLog "(2) Install Tuning Manager.\n"
    htmInstallLog "(3) Install the agents again, and then restore the backed-up data.\n\n"

    printf "\nYou cannot install HiCommand Tuning Manager on a server on "
    printf "which agents have already been installed. To install HiCommand"
    printf "Tuning Manager and agents on the same server, install as follows:\n"
    printf "(1) Back up the agent data, and then uninstall all agents.\n"
    printf "(2) Install Tuning Manager.\n"
    printf "(3) Install the agents again, and then restore the backed-up data.\n\n"
    # 57H0202 C END
    exit
fi
# 57H0141 C END

# 40H0500 A START 57H0206 C START
# 修正パッチ履歴ファイル削除
if [ -f "${PATCH_HISTORY}" ]; then
    $RM -f ${PATCH_HISTORY}
    htmInstallLog "Patch history file is deleted : [${PATCH_HISTORY}]"
fi
# 修正パッチログファイル
if [ -f "${PATCHLOG_TXT}" ]; then
    $RM -f ${PATCHLOG_TXT}
    htmInstallLog "Patch log file is deleted : [${PATCHLOG_TXT}]"
fi
# 修正パッチバックアップディレクトリ削除
if [ -d "${PATCH_BACKUP_DIR}" ]; then
    $RM -fR ${PATCH_BACKUP_DIR}
    htmInstallLog "Patch backup directory is deleted : [${PATCH_BACKUP_DIR}]"
fi
# 40H0500 A END 57H0206 C END

# 40H0564 A START
#データ移行プロパティファイルのdb_migrate_statusキーの値を取得
checkPropertyFile $PROPERTIES_DIR/db_migrate.properties "db_migrate_status"
RC_CHECKPROPERTYFILE=$?
if [ $RC_CHECKPROPERTYFILE -ne 0 ]; then
	MIGRATE_STATUS=1
else
	if [ "$RC_CHECKPROPERTYFILE_VALUE" = "not_complete" ] ; then
		MIGRATE_STATUS=1
	elif [ "$RC_CHECKPROPERTYFILE_VALUE" = "completed" ] ; then
		MIGRATE_STATUS=2
	else
		MIGRATE_STATUS=1
	fi
fi
# 40H0564 A END

# バージョン情報をログファイルへ出力する。    # 50H0091
putVersionToLog                               # 50H0091

# check if 1.0 is installed
$PKGINFO HTMApache > /dev/null 2>&1
if [ $? -eq 0 ]; then
    htmInstallLog "HTMApache package found.  Assuming TM 1.0 installed\n" 	# 40H0401 CG_FILE
    CURRENT_VERSION=1.0
else
    $PKGINFO HTMCD1 > /dev/null 2>&1
    if [ $? -eq 0 ]; then
      #CURRENT_VERSION=1.1
      # check that HTMCD1 has not already been updated
      vers=`$CAT /var/sadm/pkg/HTMCD1/pkginfo | $GREP "^VERSION=" | $SED 's/^.*=//g'`	# 40H0272 A END
      vers=`echo "$vers" | cut -c1,2,3`										# 40H0629 C
      CURRENT_VERSION=$vers
      htmInstallLog "HTM-CD1 version $vers installed\n" 	# 40H0401 C
       if [ "$vers" = "$TARGET_VERSION" ]; then

		# 40H0425 A START
		# For down grade 

		# 40H0493 A START
		checkDowninstall /opt/HiCommand/TuningManager/pplistd "HiCommand Tuning Manager"
		DOWN_INSTALL_MODE=$?
		# 40H0493 A END


        # 40H0650 C START
        htmInstallLog "Check Downinstall  (DOWN_INSTALL_MODE=$DOWN_INSTALL_MODE)"
        if [ $DOWN_INSTALL_MODE -eq 0 -o $DOWN_INSTALL_MODE -eq 1 ]; then
            # 修復インストール・ダウンインストールを行う。

			# 40H0425 A START
			# For down grade 
			if [ $DOWN_INSTALL_MODE -eq 0 ]; then
				# this is where you ask the user if they want to repair
				# 40H0185 C START
				printf "\nBegin Repair of HiCommand Tuning Manager - Server Part 1 - ${INIT_MSG_VERSION_STR} installation\n"    # 50H0113 C 55H0008 C 55H0010 C 
		        printf "Do you wish to start the installation? \n"
				# 40H0185 C END
				DEFAULT_CHAR="Y"		# 40H0437
			else
				printf "\nVersion %s.%s.0-%s of HiCommand Tuning Manager - Server Part 1 " ${LOG_CUR_VERSION} ${LOG_CUR_REVISION} ${LOG_PRE_SLANT}    # 40H0627 41H0006 C 50H0080 C 51H0001 C 50H0113 C 55H0009 C
				printf "is already installed. Do you want to install the old "
				printf "version %s.%s.0-%s of HiCommand Tuning Manager - Server Part 1? \n" ${LOG_CUR_VERSION} ${LOG_CUR_REVISION} ${LOG_CUR_SLANT}    # 40H0627 41H0006 C 50H0080 C 51H0001 C 50H0113 C 55H0009 C
				DEFAULT_CHAR="N"		# 40H0437
			fi
			while [ 1 ];
	  		do
				printf "To continue, enter Y. (Default $DEFAULT_CHAR) Y/N > "	# 40H0185	# 40H0437
				read USER_RESPONSE
				htmInstallLog "Install the old version. user input:[$USER_RESPONSE]"  # 40H0635	A

				checkZero "$USER_RESPONSE" 				# 40H0635 A
				ISZERO=$?                               # 40H0635 A
				if [ $ISZERO -eq 1 ]; then              # 40H0635 A
                    if [ $DOWN_INSTALL_MODE -eq 0 ]; then    # 57H0129 C
                        USER_RESPONSE="y"                    # 57H0129 C
                    else                                     # 57H0129 C
                        USER_RESPONSE="n"                    # 57H0129 C
                    fi                                       # 57H0129 C
	            fi
	           
				case "${USER_RESPONSE}" in			# 40H0635 start
					[Yy])
		                REPAIR="true"
		                break
						;;
					[Nn])
		               	printf "Exiting..\n"
		               	htmInstallLog "User selected to cancel repair sequence\n" 	# 40H0401 C
		               	exit;
						;;
				esac								# 40H0635 end

			done
	# 40H0188 A START
	        #recommended that you back up the Hicommand Common Component database
	        RecommendBackup
	        if [ $RC_RECOMMENDBACKUP -eq 2 ]; then	# 40H0259 C  
	            exit;
	        fi
	# 40H0188 A END

	# 41H0026 A START
	#		# 40H0564 C START
	#		if [ $MIGRATE_STATUS -eq 1 ]; then	# 40H0259 C  
	#			# Save database
	#			save_db
	#		fi
	#		# 40H0564 C END
	# 41H0026 A END
	       fi
			HTM_INSTALLED=0	# 04H0512 A
			if [ $DOWN_INSTALL_MODE -eq 0 ]; then   # 50H0057
                ACTION="repair"                     # 50H0057
            else                                    # 50H0057
                ACTION="down install"               # 50H0057
            fi                                      # 50H0057
        fi 
        # 40H0650 C END

    else ## this is a fresh install
	# 40H0185 C START
    printf "\nBegin installation of HiCommand Tuning Manager - Server Part 1 - ${INIT_MSG_VERSION_STR}\n"    # 50H0113 C 55H0008 C 55H0010 C
    printf "Do you wish to start the installation? \n"
	# 40H0185 C END
	while [ 1 ];
	 do
		printf "To continue, enter Y. (Default Y) Y/N > "	# 40H0185 40H0437
	    read USER_RESPONSE
		htmInstallLog "Begin installation of HiCommand Tuning Manager CD1:[$USER_RESPONSE]"  # 40H0635 A

		checkZero "$USER_RESPONSE" 				# 40H0635 A
		ISZERO=$?                               # 40H0635 A
		if [ $ISZERO -eq 1 ]; then              # 40H0635 C
            USER_RESPONSE="y"
        fi

		case "${USER_RESPONSE}" in			# 40H0635 start 
			[Yy])
	    	    htmInstallLog "Clean HTM-CD1 install\n" 	# 40H0401 C
		    	break
				;;
			[Nn])
	    	    htmInstallLog "User electing to cancel install\n" 	# 40H0401 C
		    	printf "Exiting..\n"
		    	exit
				;;
		esac								# 40H0635 end

	 done

# 40H0188 A START
    #recommended that you back up the Hicommand Common Component database
    RecommendBackup
    if [ $RC_RECOMMENDBACKUP -eq 2 ]; then	# 40H0259 C  
        exit;
    fi
# 40H0188 A END
	HTM_INSTALLED=1	# 04H0512 A
    ACTION="install"    # 50H0057

    fi
fi

# upgrade if current version is 1.0, 1.1, 3.0 or 3.1 or or 3.2 or 3.3
RESULT=`expr $CURRENT_VERSION \< $TARGET_VERSION`

# if [ $CURRENT_VERSION = "1.0" ] || [ $CURRENT_VERSION = "1.1" ] || [ $CURRENT_VERSION = "3.0" ] || [ $CURRENT_VERSION = "3.1" ] || [ $CURRENT_VERSION = "3.2" ] || [ $CURRENT_VERSION = "3.3" ]; then
if [ $RESULT -eq 1 -o $DOWN_INSTALL_MODE -eq 2 ]; then				# 41H0020 C, 40H0650 C

    # make sure we can perform package overwrites for upgrades
    checkPkgAdm
    # make sure no HiCommand svcs are running
    isHbaseRunning

    htmInstallLog "UPGRADE of TM version $CURRENT_VERSION to TM version $TARGET_VERSION\n" 	# 40H0401 C 

	# 40H0185 C START
    printf "\nBegin Upgrade of HiCommand Tuning Manager - Server Part 1 - ${INIT_MSG_VERSION_STR} installation\n"    # 41H0019 C 55H0008 C 55H0010 C
    printf "Do you wish to start the installation? \n"
	# 40H0185 C END

    while [ 1 ];
    do
		printf "To continue, enter Y. (Default Y) Y/N > "	# 40H0185	# 40H0437
    	read USER_RESPONSE
		htmInstallLog "Begin Upgrade of the HiCommand Tuning Manager CD1 installation:[$USER_RESPONSE]"  # 40H0635 A # 41H0019 C 50H0113 C
		
		checkZero "$USER_RESPONSE" 				# 40H0635 A 
		ISZERO=$?                               # 40H0635 A
		if [ $ISZERO -eq 1 ]; then              # 40H0635 C
            USER_RESPONSE="y"
        fi

		case "${USER_RESPONSE}" in			# 40H0635 start 
			[Yy])
				break
				;;
			[Nn])
                printf "Exiting..\n"
                htmInstallLog "User selected to cancel upgrade sequence\n" 	# 40H0401 C
                exit
				;;
		esac								# 40H0635 end 

   done	

# 40H0188 A START
    #recommended that you back up the Hicommand Common Component database
    RecommendBackup
    if [ $RC_RECOMMENDBACKUP -eq 2 ]; then	# 40H0259 C  
        exit;
    fi
# 40H0188 A END

# 40H0564 A START
    if [ $MIGRATE_STATUS -eq 1 ]; then	# 40H0259 C  

		# 40H0437 C START
	    while :
	    do
#		    printf "\nDo you want to migrate your database to the new version of HiCommand Tuning Manager?\n"	# 40H0185 C
#		    printf "If you choose N, all existing data will be lost. Y/N/A > "	# 40H0185 C
#			# 40H0437 C END
#	        read RESPONSE
	        RESPONSE="N"					# 41H0026 C
			htmInstallLog "Migrate your database to the new version of HiCommand Tuning Manager:[$RESPONSE]"# 40H0635 A

			checkZero "$RESPONSE" 					# 40H0635 A
			ISZERO=$?                               # 40H0635 A
			if [ $ISZERO -eq 1 ]; then              # 40H0635 C
				continue
			fi

			case "${RESPONSE}" in			# 40H0635 start 
				[Yy])
		            UPGRADE=1
		            PRESERVE_DB=1
					htmInstallLog "User selected to preserve the database\n" 	# 40H0401 C
					break
					;;
				[Nn])
		            UPGRADE=0
		            PRESERVE_DB=0
				    htmInstallLog "User selected not to preserve the database\n" 	# 40H0401 C
				    break
					;;
				[Aa])
				    htmInstallLog "User selected to abort upgrade\n" 	# 40H0401 C
				    exit
					;;
				*)
			    	printf "Answer yes or no or abort: "
					;;
			esac								# 40H0635 end 

	    done
	else
		PRESERVE_DB=0
		UPGRADE=0								# 41H0015
	fi
# 40H0564 A END
    ACTION="upgrade"    # 50H0057

	HTM_INSTALLED=1	# 04H0512 A
else
    UPGRADE=0
    OLD_VERSION=0
fi

# 40H0377 A START                                                               # 50H0057 C
if [ "$ACTION" = "upgrade" -o "$ACTION" = "install" ] ; then                    # 40H0267 C 50H0015 C 50H0057 C
    #Check Disk Capcity                                                         # 50H0057 C
                                                                                # 50H0057 C
    #前バージョン(R)を取得                                                      # 50H0057 C
    $PKGINFO -q HTMCD1                                                          # 50H0057 C
    if [ $? -eq 0 ]; then                                                       # 50H0057 C
        # アップグレード(Ver3.x→3、Ver4.x→4、Ver5.x→5)                       # 50H0057 C
        PRE_VERSION=`${CAT} ${HTMCD1_PKGINFO} | ${GREP} "^VERSION=" | ${SED} 's/^.*=//g'| ${CUT} -c1` # 50H0057 C
    else                                                                        # 50H0057 C
        PRE_VERSION="0"      # 新規インストール                                 # 50H0057 C
    fi                                                                          # 50H0057 C
    #今バージョン(R)を取得                                                      # 50H0057 C
    CUR_VERSION=`$ECHO ${TARGET_VERSION} | ${CUT} -d. -f1`                      # 50H0057 C
    htmInstallLog "CD1 PKG Capacity Check(PRE_VERSION=${PRE_VERSION})"          # 50H0057 C
    htmInstallLog "CD1 PKG Capacity Check(CUR_VERSION=${CUR_VERSION})"          # 50H0057 C
    # 国内版                                                                    # 50H0057 C 
    eval PRE_HTM_PKG_CAPA=\$HTM_PKG_CAPA_JP_${PRE_VERSION}        #前バージョンのPKG容量 50H0057 C
    eval CUR_HTM_PKG_CAPA=\$HTM_PKG_CAPA_JP_${CUR_VERSION}        #今バージョンのPKG容量 50H0057 C
    INSTALL_CAPA=`expr ${CUR_HTM_PKG_CAPA} - ${PRE_HTM_PKG_CAPA}` #今回の必要容量 40H0123 C 50H0057 C
    htmInstallLog "CD1 PKG Capacity Check(INSTALL_CAPA=${INSTALL_CAPA})"        # 50H0057 C
                                                                                # 50H0057 C
    checkCapacity "/opt/HiCommand" ${INSTALL_CAPA}                              # 50H0057 C
    if [ $? -eq 1 ] ; then                                                      # 50H0057 C 50H0078
        printf "Parameter Error\n"                                              # 50H0057 C
        exit                                                                    # 50H0057 C
    elif [ $? -eq 2 ] ; then                                                    # 50H0057 C
        printf "/opt/HiCommand Directory Capacity is insufficiency\n"           # 50H0057 C
        exit                                                                    # 50H0057 C
    fi                                                                          # 50H0057 C
fi                                                                              # 50H0057 C
# 40H0377 A End                                                                 # 50H0057 C

if [ "$CURRENT_VERSION" != "none" ]; then                                           # 41H0654 A
    RESULT=`expr "$CURRENT_VERSION" \> "$TARGET_VERSION"`                           # 41H0654 A
    if [ $RESULT -eq 1 ]; then                                                      # 41H0654 A
        printf "The product of a new version has already been installed.\n"         # 41H0654 A
        htmInstallLog "The product of a new version has already been installed.\n"  # 41H0654 A
        exit                                                                        # 41H0654 A
    fi                                                                              # 41H0654 A
fi                                                                                  # 41H0654 A

if [ $UPGRADE -eq 1 ]; then
   if [ $CURRENT_VERSION = "1.0" ]; then
    	DIRNAME=`$CAT /var/sadm/pkg/HTMApache/pkginfo | $GREP HTMINSTALL | sed 's/^.*=//g'`
   fi
else
    DIRNAME=/opt/HiCommand/TuningManager
fi



# For upgrade uninstall the old version & save the database
if [ $UPGRADE -eq 1 ]; then
    #stop Apache/Tomcat 
    if [ $CURRENT_VERSION = "1.0" ]; then
    	stop_old  
    else
    	isHbaseRunning  
    fi


    # backup the db
    if [ $PRESERVE_DB -eq 1 ]; then
        save_db
    fi
    # delete everything else from HTM 1.0
    if [ $CURRENT_VERSION = "1.0" ]; then
    	remove_old
    fi

elif [ -n $CURRENT_VERSION ]; then
    #stop Apache/Tomcat 
    if [ $CURRENT_VERSION = "1.0" ]; then
       stop_old  
       remove_old
    fi

fi

# v5.0-02でアンインストーラの名称を変更したが、             # 50H0116 A
# アップグレードインストールで旧アンインストーラ            # 50H0116 A
# が残ってしまうので削除する                                # 50H0116 A
if [ -f ${DIRNAME}/uninstall/uninstall-cd1.sh ]; then       # 50H0116 A
    htmInstallLog "delete ${DIRNAME}/uninstall/uninstall-cd1.sh"   # 50H0116 A
    ${RM} ${DIRNAME}/uninstall/uninstall-cd1.sh             # 50H0116 A
fi                                                          # 50H0116 A

cat > $RESPONSE_FILE <<!
HTMINSTALL='$DIRNAME'
DB_TAR_FILE='$DB_TAR_FILE'
!


# install HTM-CD1
htmInstallLog "Installing HTMCD1\n" # 40H0401 C
$PKGADD -a "$CD_DIRECTORY/dontask" -r $RESPONSE_FILE -d . $LIC_PACKAGE 2>> /dev/null    # 40H0296 C 51H0094 C
htmInstallLog "HTMCD1 install exit code: ($?)\n" # 40H0401 C

# 40H0297 C START
if [ -f $RESPONSE_FILE ]; then
    $RM -f $RESPONSE_FILE
fi
# 40H0297 C END

# 40H0596 C START
# CD1ダウンインストール完了フラグファイル作成
if [ $DOWN_INSTALL_MODE -eq 1 ]; then
    $ECHO > $CD1_DOWNINSTOALL_FILE
fi
# 40H0596 C END

# 40H0123 D START
## Check if interbase is installed
#$ECHO "Checking if Interbase is already installed ..."
#printf "Checking Interbase\n" >> $LOG_FILE
#
#$PKGINFO | $GREP -i interbase > /dev/null 2>&1
#
#if [ $? -ne 0 ]; then
#    $ECHO "Installing Interbase ..."
#    printf "Installing Interbase\n" $LOG_FILE
#    $PKGADD  -d . IBCSN60
#    # Setup init.d scripts
#    $CP interbaseserver /etc/init.d/interbaseserver
#    $CHMOD 744 /etc/init.d/interbaseserver
#    $CHOWN root /etc/init.d/interbaseserver
#    $CHGRP sys /etc/init.d/interbaseserver
#    $LN -s /etc/init.d/interbaseserver /etc/rc2.d/S98interbaseserver
#    $LN -s /etc/init.d/interbaseserver /etc/rc0.d/K02interbaseserver
#else
#    $ECHO "Interbase already installed"
#    printf "Interbase already installed\n" >> $LOG_FILE
#fi
#
#/etc/init.d/interbaseserver start > /dev/null 2>&1
#
## Check if interclient is installed
#$ECHO "Checking if Interclient is already installed ..."
#printf "Checking for Interclient\n" >> $LOG_FILE
#if [ -d "/usr/interclient" ]; then
#    $ECHO "Interclient already installed"
#    printf "Interclient already installed\n" >> $LOG_FILE
#else
#    ## interclient install contents must be moved to the local machine
#    ## and then installed
#    printf "Installing InterClient\n" >> $LOG_FILE
#    HERE=`$PWD`
#    INTC_DIR="interclient_install_temp_dir.$$"
#    $MKDIR /tmp/$INTC_DIR
#    cd interclient_install_temp_dir
#    $CP * /tmp/$INTC_DIR
#    cd /tmp/$INTC_DIR
#    ./install.sh
#    cd $HERE
#    cd ..
#fi
# 40H0123 D END

# return to the original location from which this script was called
cd $START_LOCATION
$ECHO "\nDone installing HiCommand Tuning Manager - Server Part 1"    #  50H0113 C 51H0094 C
$ECHO "To complete installation, install HiCommand Tuning Manager - Server Part 2 next"    #  50H0113 C
htmInstallLog "HTM-CD1 install complete\n" 	# 40H0401 C
