#!/bin/sh
# ---------------------------------------------- #

##### env param set #############################
# define command
#arp=/sbin/arp
awk=/bin/awk
cat=/bin/cat
#chkconfig=/sbin/chkconfig
chmod=/bin/chmod
chown=/bin/chown
clear=/usr/bin/clear
cmp=/usr/bin/cmp
cp=/bin/cp
cut=/bin/cut
echo=/bin/echo
touch=/bin/touch
#env=/usr/bin/env
grep=/bin/grep
java=${JAVA_HOME}/bin/java
ls=/bin/ls
ln=/bin/ln
mkdir=/bin/mkdir
#mount=/bin/mount
mv=/bin/mv
#ping=/bin/ping
#postgresql="/etc/rc.d/init.d/postgresql"
#postgresql_smx="/etc/rc.d/init.d/postgresql-smx"
ps=/bin/ps
psql=/usr/bin/psql
pwd=/bin/pwd
rm=/bin/rm
rpm=/bin/rpm
#scp=/usr/bin/scp
sed=/bin/sed
shutdown=/sbin/shutdown
sync=/bin/sync
tar=/bin/tar
tr=/usr/bin/tr
#umount=/bin/umount
unzip=/usr/bin/unzip
wc=/usr/bin/wc
zip=/usr/bin/zip
tee=/usr/bin/tee
date=/bin/date
ssh=/usr/bin/ssh
service=/sbin/service

smx_backup_cmd=${INST_HOME}/backup.sh


# define line
LF='
'

# Patch information
TO_VER="3.3.2"
TO_MOD_VER="3.3.2"
FROM_VER="3.3.0,3.3.1"
SCOPE_VER="3.3.2"   # MAX 8
SCOPE_FROM_VER="3.3.0 3.3.1"
VER_HIST_NAME="ver-3_3_2_patch"

# Module file
MODULE_PKG_FILE=${INST_HOME}/module_ver-$TO_MOD_VER.tar.gz

# Module extract directory
MODULE_DIR=${INST_HOME}/module

# Backup infomartion
#BACKUP_DIR=/backup/data
BACKUP_DIR=/backup/data/patch_backup_before_ver-$TO_MOD_VER
BACKUP_PKG_FILE=${BACKUP_DIR}/module_ver-$TO_MOD_VER.tar
BACKUP_DELETE_FILE=${BACKUP_DIR}/delete_module_ver-$TO_MOD_VER.tar
BACKUP_CRON_FILE=${BACKUP_DIR}/cron_ver-$TO_MOD_VER.tar
BACKUP_VERSION=${BACKUP_DIR}/SMX_VERSION-$TO_MOD_VER.tar
BACKUP_WIN=${BACKUP_DIR}/winlogon_module-$TO_MOD_VER.tar.gz
BACKUP_PKG_FILE_BAK=${BACKUP_DIR}/module_ver-$TO_MOD_VER.tar.bak

# Salvage information
SALVAGE_DIR=$BACKUP_DIR
SALVAGE_PKG_FILE=${SALVAGE_DIR}/module_ver-$TO_MOD_VER-salvege.tar


# deploy and backup module_list
LIST_FILE_NAME=list.txt

# PS OPTION
PS_OPT="-efww"

# TAR OPTION
ZT_OPT="-ztvf"
ZX_OPT="-zxvf"
ZC_OPT="-zcvf"
T_OPT="-tvf"
X_OPT="-xvf"
U_OPT="-uvf"
DEL_OPT="--delete"
D_OPT="-df"
F_OPT="-f"

# Process check CMD string
AUTH_CMD="nanako.param=/opt/cse/smx/auth/servlet/api/"
ADMIN_CMD="nanako.param=/opt/cse/smx/admin/servlet/api/"
GSB_CMD="nanako.param=/opt/cse/smx/gsb/servlet/api/ "
ISB_CMD="nanako.param=/opt/cse/smx/isb/servlet/api/ "
ISB_CMD2="catalina.base=/opt/cse/smx/isb/servlet "
RADIUS_CMD="/usr/local/sbin/radiusd"
PGSQL_CMD="/usr/bin/postmaster"
PGPOOL_CMD="/usr/bin/pgpool"
EZS_CMD="nanako.param=/opt/cse/smx/setup/servlet/api/"
CRON_CMD="crond"

# SECURE MATRIX command string
AUTH_START="${service} smx-auth start"
ADMIN_START="${service} smx-admin start"
GSB_START="${service} smx-gsb start"
ISB_START="${service} smx-isb start"
RADIUS_START="${service} radiusd start"
PGSQL_START="${service} postgresql-smx start"
PGPOOL_START="${service} pgpool-smx start"
BASEFILTER_START="${service} base_filter start"
CRON_START="${service} crond start"
EZS_START="${service} smx-setup start"

AUTH_STOP="${service} smx-auth stop"
ADMIN_STOP="${service} smx-admin stop"
GSB_STOP="${service} smx-gsb stop"
ISB_STOP="${service} smx-isb stop"
RADIUS_STOP="${service} radiusd stop"
PGSQL_STOP="${service} postgresql-smx stop"
PGPOOL_STOP="${service} pgpool-smx stop"
CRON_STOP="${service} crond stop"
EZS_STOP="${service} smx-setup stop"

AUTH_RESTART="${service} smx-auth restart"
ADMIN_RESTART="${service} smx-admin restart"
GSB_RESTART="${service} smx-gsb restart"
ISB_RESTART="${service} smx-isb restart"
RADIUS_RESTART="${service} radiusd restart"
PGSQL_RESTART="${service} postgresql-smx restart"
PGPOOL_RESTART="${service} pgpool-smx restart"
BASEFILTER_RESTART="${service} base_filter restart"
CRON_RESTART="${service} crond restart"
EZS_RESTART="${service} smx-setup restart"

# service stop all
STOP_ALL_CMD="service_stop_all.sh"
# service start all
START_ALL_CMD="service_start_all.sh"

# WEB-INF/lib path
AUTH_LIB_FILE=/opt/cse/smx/auth/servlet/webapps/auth/WEB-INF/lib
GSB_LIB_FILE=/opt/cse/smx/gsb/servlet/webapps/ROOT/WEB-INF/lib
ISB_LIB_FILE=/opt/cse/smx/isb/servlet/webapps/isb/WEB-INF/lib

# define user_info
SMXD_USER=smxd
#SMXD_HOME=`su - $SMXD_USER -c "$env | $grep ^HOME | $sed -e s/^HOME=//g"`
SMXD_HOME=/home/smxd

SMX_INST=${SMXD_HOME}/installer
INST_TMP=${SMX_INST}/tmp

POSTGRES_USER=postgres
PGSQL_USER=postgres
TEMPL=template1

# postgres only directory
OPT_DB=/opt/cse/smx/db
OPT_DB_BIN=${OPT_DB}/bin

# pgpool.conf
PGPOOL_CONF=/usr/etc/pgpool.conf
PGCHP=recovery_password
PGCHPSQL="ALTER USER $POSTGRES_USER WITH PASSWORD"
SN_PG_PORT=5432
CL_PG_PORT=9432
ONLINE_RECOVERY_SQL=/usr/etc/pgpool-recovery.sql

# SMX patch and update history
SMX_HIST=${SMXD_HOME}/installer/history.txt

# define temp
TMP_FILE=${INST_HOME}/tmp_file$$

# when miss deploy, file temp
DEPLOY_ERR_FILE=${INST_HOME}/deploy_err.tmp

# salvage temp file
SALVAGE_LIST_FILE=${INST_HOME}/salvage_list.tmp

# new file list
ADDED_LIST_FILE=${INST_HOME}/added_files.lst

# smx setup_info
SETUP_PROPERTIES_FILE=/home/smxd/installer/setup.props
BAK_SETUP_PROPERTIES_FILE=${SETUP_PROPERTIES_FILE}.bak

# sed file 
REPLACE_XML_FILE=${INST_HOME}/replace.xml
INSERT_XML_FILE=${INST_HOME}/insert.xml

# define logfile
LOG_FILE=${INST_HOME}/log/install.log
ERR_LOG_FILE=${INST_HOME}/log/err.log

# install_info
INSTALL_INI=${INST_HOME}/install.ini

# configure version_infofile
INSTALL_INFO_INI_FILE=${INST_HOME}/install_information.ini

# securematrix_infomartion
SMX_INFO_TXT_FILE=/opt/cse/smx/common/bin/securematrix_infomartion.txt
UNKNOWN_WORD="UNKNOWN"

# for Configure extract
SMX_INSTALLER_HOME=${SMXD_HOME}/installer
INSTALLERS_INSTALL_INFO_INI_FILE=${SMX_INSTALLER_HOME}/install_information.ini

# monitor/service_list
# search Radius 
SMX_SERVICE_LIST_FILE=/opt/cse/smx/common/bin/monitor/service_list

# JSP compile filepath
ADMIN_JSP=/opt/cse/smx/admin/servlet/work/Catalina/localhost/smx_admin
ROOT_JSP=/opt/cse/smx/gsb/servlet/work/Catalina/localhost/_
SMXSLL_JSP=/opt/cse/smx/gsb/servlet/work/Catalina/localhost/smx_sll
ISB_JSP=/opt/cse/smx/isb/servlet/work/Catalina/localhost/isb

# clusterManager path
CLUSTER_MAN_CMD=/opt/cse/smx/admin/bin/util/clusterManager.sh
# clusterManager logpath
CLUSTER_MAN_LOG=/var/log/cse/smx/admin/clusterManager.log

# ----- middle_ware update_list ---------------------------------------------- ## RPM list files (for install & uninstall)
RPM_LIST_FILE_NAME=rpm_list.txt

# RPM list files (for install)
DELETE_RPM4INST_FILENAME=deleteRPM4inst.txt
INSTALL_RPM4INST_FILENAME=installRPM4inst.txt

# RPM list files (for uninstall)
DELETE_RPM4UNINST_FILENAME=deleteRPM4uninst.txt
INSTALL_RPM4UNINST_FILENAME=installRPM4uninst.txt
# ---------------------------------------------------------------------------- #

# ----- AUTH_FQDN FILE --------------------------------------------- #
# admin.properties 
ADMIN_PROPERTIES_FILE=${SMX_ADMIN_HOME}/servlet/webapps/admin/WEB-INF/classes/admin.properties
# ---------------------------------------------------------------------------- #

# ----- GSB_FQDN FILE ---------------------------------------------- #
# gsb.properties 
GSB_PROPERTIES_FILE=${SMX_GSB_HOME}/servlet/webapps/ROOT/WEB-INF/classes/gsb.properties
# ---------------------------------------------------------------------------- #

# ----- ISB_FQDN FILE ---------------------------------------------- #
# isb.properties
ISB_PROPERTIES_FILE=${SMX_ISB_HOME}/servlet/webapps/isb/WEB-INF/classes/isb.properties
# ---------------------------------------------------------------------------- #

# postgres user
PGSQL_HOME=/var/lib/pgsql
PGSQL_SSH_DIR=${PGSQL_HOME}/.ssh
PGSQL_SSH_KEY_FILENAME=id_rsa
PGSQL_SSH_PUB_FILENAME=${PGSQL_SSH_KEY_FILENAME}.pub
PGSQL_SSH_KEY_FILE=${PGSQL_SSH_DIR}/${PGSQL_SSH_KEY_FILENAME}
PGSQL_SSH_PUB_FILE=${PGSQL_SSH_DIR}/${PGSQL_SSH_PUB_FILENAME}
PGSQL_AUTHORIZED_KEYS=${PGSQL_SSH_DIR}/authorized_keys2

# known_hosts
SSHD_CONFIG4HOST_REGIST=${SMX_INST}/sshd_config4host_regist
TMP_SSHD_CONFIG4HOST_REGIST=/tmp/sshd_config4host_regist$$

# nkf path
NKF_PATH=${INST_HOME}/nkf

# dummy SMX setting
FIXEDDMYPATH=/opt/cse/smx/admin/bin/util/fixedDummyMatrix.sh

# winlogon download zip, auth_define.sh, configure.sh
WIN_XP_DOWNLOAD_MODULE=SmxWinAuthClient*.zip
WIN_VISTA_DOWNLOAD_MODULE=smx_winlogonvista_*_module.zip
AUTH_DEFINE_FILE=auth_define.sh
CONF_SH_FILENAME=configure.sh
WIN_XP_DOWNLOAD_NEWMODULE=SmxWinAuthClient_2_6_1.zip
WIN_VISTA_DOWNLOAD_NEWMODULE=smx_winlogonvista_v111_module.zip

# property files of winlogon settings (admin)
ADMIN_PROP_DIR=/opt/cse/smx/admin/servlet/webapps/admin/WEB-INF/classes/
ADMIN_PROP_WIN_SET_EN=windowsAuth_en.properties
ADMIN_PROP_WIN_SET_JA=windowsAuth_ja.properties
ADMIN_PROP_WIN_SET_SJIS=windowsAuth.SJIS

# WindowsLogon module path
WIN_DOWNLOAD_PATH=/opt/cse/smx/admin/servlet/webapps/admin/client
WIN_MODULE=SmxWinAuthClient*.zip
WIN_FILE_PATH=/home/smxd/installer/package/winauth
WIN_MSI=SECUREMATRIXforWindows
WIN_XP_FILE_PATH=/home/smxd/installer/package/winauth/XP
WIN_VISTA_FILE_PATH=/home/smxd/installer/package/winauth/VISTA
WIN_XP_OLDMODULE=SECUREMATRIXforWindows_*.msi
WIN_VISTA_OLDMODULE=SECUREMATRIXforWindowsVista_*.msi
WIN_XP_MODULE=SECUREMATRIXforWindows_2.6.1.msi
WIN_VISTA_MODULE=SECUREMATRIXforWindowsVista_1.1.1.msi
WIN_DLL_MODULE=SmxGina.dll
WIN_XP_CONF=SmxGina.ini
WIN_VISTA_CONF=config.xml
WIN_XP_CONF_ORG=SmxGina.ini.org
WIN_VISTA_CONF_ORG=config.org
WIN_XP_CONF_INST=SmxGinaInstall.ini
WIN_XP_ERR_MSG=SmxGinaErrMsgJp.ini
WIN_XP_SMX_TOOL=smxtool.exe

# MSG PROP
MSG_UTF8_PROP=${INST_HOME}/msg_utf-8.properties
MSG_EUC_PROP=${INST_HOME}/msg_euc.properties

# iphone path
IPHONE_ROOT_PATH=/opt/cse/smx/gsb/servlet/webapps/ROOT/parts/iphone
IPHONE_SMX_SLL_PATH=/opt/cse/smx/gsb/servlet/webapps/smx_sll/parts/iphone

# client.conf directory
CLIENTS_CONF=/usr/local/etc/raddb/clients.conf

# radiusd.conf directory
RADIUSD_CONF1=/usr/local/etc/raddb/radiusd.conf
RADIUSD_CONF2=/home/smxd/installer/tmp/usr/local/etc/raddb/radiusd.conf

# JSP generated directories that needs to be deleted
# Auth
JSP_OUT_ADMIN_DIR_DEL=/opt/cse/smx/admin/servlet/work/Catalina/localhost/smx_admin
# GSB
JSP_OUT_GSB_DIR_DEL=/opt/cse/smx/gsb/servlet/work/Catalina/localhost/_
JSP_OUT_GSB_SLL_DIR_DEL=/opt/cse/smx/gsb/servlet/work/Catalina/localhost/smx_sll
# ISB
JSP_OUT_ISB_DIR_DEL=/opt/cse/smx/isb/servlet/work/Catalina/localhost/isb
# EasySetup (AGI)
JSP_OUT_EZS_DIR_DEL=/opt/cse/smx/setup/servlet/work/Catalina/localhost/_

# auth_define.sh full path
AUTH_DEF_SH_DIR=/home/smxd/installer/auth_define.sh
