#! /bin/sh

main() {

##### 初期設定 #####
OS_LANG=UTF-8
OPENSTANDIA_INSTALLER_VER=sample
STACK_XML=stack-${OPENSTANDIA_INSTALLER_VER}.xml
STACK_NAME=サンプルスタック
ANT_DIR=apache-ant-1.7.0
SCRIPTS_DIR=scripts
CHECK_ANT_NO=2
KICK_EXE_NO=4
KICK_SHELL_NO=6
UNZIP_TEST_NO=8
REPLACE_TEST_NO=10
SELECT_CONFIG_NO=12
DEPEND_DEST_NO=14
DEPEND_SRC_NO=16
CHECK_EXEC_NO=18
CHECK_CONNECTED_DB_NO=20
DIFF_MD5_NO=22
INVENTORY_NO=24
INVENTORY2_NO=26


##### 初期処理 #####
umask 022
CURRENT_DIR=`pwd`
BASEDIR=`dirname $0`
if [ "${CURRENT_DIR}" = "/" ]; then
	CURRENT_DIR=${BASEDIR}
else
	CURRENT_DIR=${CURRENT_DIR}/${BASEDIR}
fi
_ANT_HOME=${ANT_HOME}
ANT_HOME=${CURRENT_DIR}/lib/${ANT_DIR}
export ANT_HOME
_PATH=${PATH}
PATH=${ANT_HOME}/bin:${CURRENT_DIR}/bin:${PATH}
export PATH
_SCRIPTS_DIR=${SCRIPTS_DIR}
SCRIPTS_DIR=${CURRENT_DIR}/${SCRIPTS_DIR}/
export SCRIPTS_DIR
export STACK_XML

chmod 755 "${ANT_HOME}/bin/ant" > /dev/nul
set_lang_func


##### 実行ユーザー権限チェック #####
sh ${CURRENT_DIR}/bin/CheckAuthority.sh
if [ $? -ne 0 ]; then
	echo 実行ユーザーがrootでないため処理を続行できません。
	end_func
fi


##### javaインストールチェック #####
sh ${CURRENT_DIR}/bin/CheckInstalledJava.sh
if [ $? -ne 0 ]; then
	echo javaがインストールされていないかもしくは、javaにパスが通っていないため処理を続行できません。
	end_func
fi


##### OpenStandiaインストールチェック #####
sh ${CURRENT_DIR}/bin/CheckInstalledApplication.sh ${STACK_NAME}
if [ $? -ne 0 ]; then
	DEFAULT_MODE=1
else
	DEFAULT_MODE=3
fi


##### 画面表示 #####
clear
echo ${STACK_NAME}
echo OpenStandiaInstallerによるサンプルです。
echo 
echo 処理を選択してください。
echo 1 : インストール
echo 2 : アンインストール
echo 3 : アップデート
echo [${DEFAULT_MODE}]

read MODE_NO
if [ "${MODE_NO}" = "" ]; then
	MODE_NO=${DEFAULT_MODE}
fi
if [ "${MODE_NO}" = "1" ]; then
	MODE=install
	MODE_STR=インストール
fi
if [ "${MODE_NO}" = "2" ]; then
	MODE=uninstall
	MODE_STR=アンインストール
fi
if [ "${MODE_NO}" = "3" ]; then
	MODE=update
	MODE_STR=アップデート
fi


##### 構成情報の確認 #####
clear
echo 構成情報の確認をします...
# check-ant
source GetProductInfo.sh ${CHECK_ANT_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
CHECK_ANT_NAME=${PRODUCT_NAME}
CHECK_ANT_VER=${PRODUCT_VER}
CHECK_ANT_IS_INSTALLED=${IS_INSTALLED}
CHECK_ANT_IS_VIEW=${IS_VIEW}
echo -n .

# kick-exe
source GetProductInfo.sh ${KICK_EXE_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
KICK_EXE_NAME=${PRODUCT_NAME}
KICK_EXE_VER=${PRODUCT_VER}
KICK_EXE_IS_INSTALLED=${IS_INSTALLED}
KICK_EXE_IS_VIEW=${IS_VIEW}
echo -n .

# kick-shell
source GetProductInfo.sh ${KICK_SHELL_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
KICK_SHELL_NAME=${PRODUCT_NAME}
KICK_SHELL_VER=${PRODUCT_VER}
KICK_SHELL_IS_INSTALLED=${IS_INSTALLED}
KICK_SHELL_IS_VIEW=${IS_VIEW}
echo -n .

# unzip-test
source GetProductInfo.sh ${UNZIP_TEST_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
UNZIP_TEST_NAME=${PRODUCT_NAME}
UNZIP_TEST_VER=${PRODUCT_VER}
UNZIP_TEST_IS_INSTALLED=${IS_INSTALLED}
UNZIP_TEST_IS_VIEW=${IS_VIEW}
echo -n .

# replace-test
source GetProductInfo.sh ${REPLACE_TEST_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
REPLACE_TEST_NAME=${PRODUCT_NAME}
REPLACE_TEST_VER=${PRODUCT_VER}
REPLACE_TEST_IS_INSTALLED=${IS_INSTALLED}
REPLACE_TEST_IS_VIEW=${IS_VIEW}
echo -n .

# select-config
source GetProductInfo.sh ${SELECT_CONFIG_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
SELECT_CONFIG_NAME=${PRODUCT_NAME}
SELECT_CONFIG_VER=${PRODUCT_VER}
SELECT_CONFIG_IS_INSTALLED=${IS_INSTALLED}
SELECT_CONFIG_IS_VIEW=${IS_VIEW}
echo -n .

# depend-dest
source GetProductInfo.sh ${DEPEND_DEST_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
DEPEND_DEST_NAME=${PRODUCT_NAME}
DEPEND_DEST_VER=${PRODUCT_VER}
DEPEND_DEST_IS_INSTALLED=${IS_INSTALLED}
DEPEND_DEST_IS_VIEW=${IS_VIEW}
echo -n .

# depend-src
source GetProductInfo.sh ${DEPEND_SRC_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
DEPEND_SRC_NAME=${PRODUCT_NAME}
DEPEND_SRC_VER=${PRODUCT_VER}
DEPEND_SRC_IS_INSTALLED=${IS_INSTALLED}
DEPEND_SRC_IS_VIEW=${IS_VIEW}
echo -n .

# check-exec
source GetProductInfo.sh ${CHECK_EXEC_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
CHECK_EXEC_NAME=${PRODUCT_NAME}
CHECK_EXEC_VER=${PRODUCT_VER}
CHECK_EXEC_IS_INSTALLED=${IS_INSTALLED}
CHECK_EXEC_IS_VIEW=${IS_VIEW}
echo -n .

# check-connected-db
source GetProductInfo.sh ${CHECK_CONNECTED_DB_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
CHECK_CONNECTED_DB_NAME=${PRODUCT_NAME}
CHECK_CONNECTED_DB_VER=${PRODUCT_VER}
CHECK_CONNECTED_DB_IS_INSTALLED=${IS_INSTALLED}
CHECK_CONNECTED_DB_IS_VIEW=${IS_VIEW}
echo -n .

# diff-md5
source GetProductInfo.sh ${DIFF_MD5_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
DIFF_MD5_NAME=${PRODUCT_NAME}
DIFF_MD5_VER=${PRODUCT_VER}
DIFF_MD5_IS_INSTALLED=${IS_INSTALLED}
DIFF_MD5_IS_VIEW=${IS_VIEW}
echo -n .

# inventory
source GetProductInfo.sh ${INVENTORY_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
INVENTORY_NAME=${PRODUCT_NAME}
INVENTORY_VER=${PRODUCT_VER}
INVENTORY_IS_INSTALLED=${IS_INSTALLED}
INVENTORY_IS_VIEW=${IS_VIEW}
echo -n .

# inventory2
source GetProductInfo.sh ${INVENTORY2_NO}
source CheckViewProduct.sh ${MODE} ${IS_INSTALLED}
INVENTORY2_NAME=${PRODUCT_NAME}
INVENTORY2_VER=${PRODUCT_VER}
INVENTORY2_IS_INSTALLED=${IS_INSTALLED}
INVENTORY2_IS_VIEW=${IS_VIEW}
echo -n .


##### インストール全体前処理 #####
echo 
ant -Dmode=${MODE} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install-before.xml"
if [ $? -ne 0 ]; then error_func; fi


##### 問い合わせ #####
INSTALLED_NO=
clear
# check-ant
if [ "${CHECK_ANT_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${CHECK_ANT_NO}
	ant -Dno=${CHECK_ANT_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_CHECK_ANT=n
	else
		read -p "Antのバージョンを表示するサンプル(${CHECK_ANT_NAME} ${CHECK_ANT_VER})を実行しますか？(y/n) [y]" INSTALL_CHECK_ANT
		if [ "${INSTALL_CHECK_ANT}" = "" ]; then
			INSTALL_CHECK_ANT=y
		fi
	fi
else
	INSTALL_CHECK_ANT=n
fi
if [ "${INSTALL_CHECK_ANT}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# kick-exe
if [ "${KICK_EXE_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${KICK_EXE_NO}
	ant -Dno=${KICK_EXE_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_KICK_EXE=n
	else
		read -p "実行ファイルを実行するサンプル(${KICK_EXE_NAME} ${KICK_EXE_VER})を実行しますか？(y/n) [y]" INSTALL_KICK_EXE
		if [ "${INSTALL_KICK_EXE}" = "" ]; then
			INSTALL_KICK_EXE=y
		fi
	fi
else
	INSTALL_KICK_EXE=n
fi
if [ "${INSTALL_KICK_EXE}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# kick-shell
if [ "${KICK_SHELL_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${KICK_SHELL_NO}
	ant -Dno=${KICK_SHELL_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_KICK_SHELL=n
	else
		read -p "シェルファイルを実行するサンプル(${KICK_SHELL_NAME} ${KICK_SHELL_VER})を実行しますか？(y/n) [y]" INSTALL_KICK_SHELL
		if [ "${INSTALL_KICK_SHELL}" = "" ]; then
			INSTALL_KICK_SHELL=y
		fi
	fi
else
	INSTALL_KICK_SHELL=n
fi
if [ "${INSTALL_KICK_SHELL}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# unzip-test
if [ "${UNZIP_TEST_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${UNZIP_TEST_NO}
	ant -Dno=${UNZIP_TEST_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_UNZIP_TEST=n
	else
		read -p "ZIPファイルを解凍するサンプル(${UNZIP_TEST_NAME} ${UNZIP_TEST_VER})を実行しますか？(y/n) [y]" INSTALL_UNZIP_TEST
		if [ "${INSTALL_UNZIP_TEST}" = "" ]; then
			INSTALL_UNZIP_TEST=y
		fi
	fi
else
	INSTALL_UNZIP_TEST=n
fi
if [ "${INSTALL_UNZIP_TEST}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# replace-test
if [ "${REPLACE_TEST_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${REPLACE_TEST_NO}
	ant -Dno=${REPLACE_TEST_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_REPLACE_TEST=n
	else
		read -p "文字列置換をするサンプル(${REPLACE_TEST_NAME} ${REPLACE_TEST_VER})を実行しますか？(y/n) [y]" INSTALL_REPLACE_TEST
		if [ "${INSTALL_REPLACE_TEST}" = "" ]; then
			INSTALL_REPLACE_TEST=y
		fi
	fi
else
	INSTALL_REPLACE_TEST=n
fi
if [ "${INSTALL_REPLACE_TEST}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# select-config
if [ "${SELECT_CONFIG_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${SELECT_CONFIG_NO}
	ant -Dno=${SELECT_CONFIG_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_SELECT_CONFIG=n
	else
		read -p "設定ファイルを選択させるサンプル(${SELECT_CONFIG_NAME} ${SELECT_CONFIG_VER})を実行しますか？(y/n) [y]" INSTALL_SELECT_CONFIG
		if [ "${INSTALL_SELECT_CONFIG}" = "" ]; then
			INSTALL_SELECT_CONFIG=y
		fi
	fi
else
	INSTALL_SELECT_CONFIG=n
fi
if [ "${INSTALL_SELECT_CONFIG}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi
INSTALL_SELECT_CONFIG_CONF=1
if [ "${INSTALL_SELECT_CONFIG}" = "y" ]; then
	echo 設定ファイルを選択してください。
	echo 1 : 1番目の設定
	echo 2 : 2番目の設定
	echo 3 : 3番目の設定
	echo 4 : 4番目の設定
	echo 5 : 5番目の設定
	read INSTALL_SELECT_CONFIG_CONF
fi

# depend-dest
if [ "${DEPEND_DEST_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${DEPEND_DEST_NO}
	ant -Dno=${DEPEND_DEST_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_DEPEND_DEST=n
	else
		read -p "依存先(${DEPEND_DEST_NAME} ${DEPEND_DEST_VER})を${MODE_STR}しますか？(y/n) [y]" INSTALL_DEPEND_DEST
		if [ "${INSTALL_DEPEND_DEST}" = "" ]; then
			INSTALL_DEPEND_DEST=y
		fi
	fi
else
	INSTALL_DEPEND_DEST=n
fi
if [ "${INSTALL_DEPEND_DEST}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# depend-src
if [ "${DEPEND_SRC_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${DEPEND_SRC_NO}
	ant -Dno=${DEPEND_SRC_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_DEPEND_SRC=n
	else
		read -p "依存元(${DEPEND_SRC_NAME} ${DEPEND_SRC_VER})を${MODE_STR}しますか？(y/n) [y]" INSTALL_DEPEND_SRC
		if [ "${INSTALL_DEPEND_SRC}" = "" ]; then
			INSTALL_DEPEND_SRC=y
		fi
	fi
else
	INSTALL_DEPEND_SRC=n
fi
if [ "${INSTALL_DEPEND_SRC}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# check-exec
if [ "${CHECK_EXEC_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${CHECK_EXEC_NO}
	ant -Dno=${CHECK_EXEC_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_CHECK_EXEC=n
	else
		read -p "実行前に実行確認をするサンプル(${CHECK_EXEC_NAME} ${CHECK_EXEC_VER})を実行しますか？(y/n) [y]" INSTALL_CHECK_EXEC
		if [ "${INSTALL_CHECK_EXEC}" = "" ]; then
			INSTALL_CHECK_EXEC=y
		fi
	fi
else
	INSTALL_CHECK_EXEC=n
fi
if [ "${INSTALL_CHECK_EXEC}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi
INSTALL_CHECK_EXEC_CONF=1
if [ "${INSTALL_CHECK_EXEC}" = "y" ]; then
	echo 設定ファイルを選択してください。
	echo 1 : 実行していい
	echo 2 : 実行してはダメ
	read INSTALL_CHECK_EXEC_CONF
fi

# check-connected-db
if [ "${CHECK_CONNECTED_DB_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${CHECK_CONNECTED_DB_NO}
	ant -Dno=${CHECK_CONNECTED_DB_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_CHECK_CONNECTED_DB=n
	else
		read -p "DB接続チェック(${CHECK_CONNECTED_DB_NAME} ${CHECK_CONNECTED_DB_VER})を実行しますか？(y/n) [y]" INSTALL_CHECK_CONNECTED_DB
		if [ "${INSTALL_CHECK_CONNECTED_DB}" = "" ]; then
			INSTALL_CHECK_CONNECTED_DB=y
		fi
	fi
else
	INSTALL_CHECK_CONNECTED_DB=n
fi
if [ "${INSTALL_CHECK_CONNECTED_DB}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# diff-md5
if [ "${DIFF_MD5_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${DIFF_MD5_NO}
	ant -Dno=${DIFF_MD5_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_DIFF_MD5=n
	else
		read -p "MD5によりファイル比較をする(${DIFF_MD5_NAME} ${DIFF_MD5_VER})を実行しますか？(y/n) [y]" INSTALL_DIFF_MD5
		if [ "${INSTALL_DIFF_MD5}" = "" ]; then
			INSTALL_DIFF_MD5=y
		fi
	fi
else
	INSTALL_DIFF_MD5=n
fi
if [ "${INSTALL_DIFF_MD5}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# inventory
if [ "${INVENTORY_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${INVENTORY_NO}
	ant -Dno=${INVENTORY_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_INVENTORY=n
	else
		read -p "インベントリーサンプル(${INVENTORY_NAME} ${INVENTORY_VER})の${MODE_STR}を実行しますか？(y/n) [y]" INSTALL_INVENTORY
		if [ "${INSTALL_INVENTORY}" = "" ]; then
			INSTALL_INVENTORY=y
		fi
	fi
else
	INSTALL_INVENTORY=n
fi
if [ "${INSTALL_INVENTORY}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi

# inventory2
if [ "${INVENTORY2_IS_VIEW}" = "y" ]; then
	SELECTED_NO=${INSTALLED_NO},${INVENTORY2_NO}
	ant -Dno=${INVENTORY2_NO} -Dmode=${MODE} -DinstalledNo="${SELECTED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml" check-installed 1>/dev/nul 2>/dev/nul
	if [ $? -ne 0 ]; then
		INSTALL_INVENTORY2=n
	else
		read -p "インベントリーサンプル(${INVENTORY2_NAME} ${INVENTORY2_VER})の${MODE_STR}を実行しますか？(y/n) [y]" INSTALL_INVENTORY2
		if [ "${INSTALL_INVENTORY2}" = "" ]; then
			INSTALL_INVENTORY2=y
		fi
	fi
else
	INSTALL_INVENTORY2=n
fi
if [ "${INSTALL_INVENTORY2}" = "y" ]; then
	INSTALLED_NO=${SELECTED_NO}
fi


##### ダウンロード実行 #####
echo 
echo ダウンロード処理を開始します...
if [ "${INSTALL_CHECK_ANT}" = "y" ]; then
	ant -Dno=${CHECK_ANT_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_KICK_EXE}" = "y" ]; then
	ant -Dno=${KICK_EXE_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_KICK_SHELL}" = "y" ]; then
	ant -Dno=${KICK_SHELL_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_UNZIP_TEST}" = "y" ]; then
	ant -Dno=${UNZIP_TEST_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_REPLACE_TEST}" = "y" ]; then
	ant -Dno=${REPLACE_TEST_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_SELECT_CONFIG}" = "y" ]; then
	ant -Dno=${SELECT_CONFIG_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_DEPEND_DEST}" = "y" ]; then
	ant -Dno=${DEPEND_DEST_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_DEPEND_SRC}" = "y" ]; then
	ant -Dno=${DEPEND_SRC_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_CHECK_EXEC}" = "y" ]; then
	ant -Dno=${CHECK_EXEC_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_CHECK_CONNECTED_DB}" = "y" ]; then
	ant -Dno=${CHECK_CONNECTED_DB_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_DIFF_MD5}" = "y" ]; then
	ant -Dno=${DIFF_MD5_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_INVENTORY}" = "y" ]; then
	ant -Dno=${INVENTORY_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_INVENTORY2}" = "y" ]; then
	ant -Dno=${INVENTORY2_NO} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}download.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi


##### インストール実行 #####
echo 
echo ${MODE_STR}処理を開始します...
if [ "${INSTALL_CHECK_ANT}" = "y" ]; then
	ant -Dno=${CHECK_ANT_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_KICK_EXE}" = "y" ]; then
	ant -Dno=${KICK_EXE_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_KICK_SHELL}" = "y" ]; then
	ant -Dno=${KICK_SHELL_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_UNZIP_TEST}" = "y" ]; then
	ant -Dno=${UNZIP_TEST_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_REPLACE_TEST}" = "y" ]; then
	ant -Dno=${REPLACE_TEST_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_SELECT_CONFIG}" = "y" ]; then
	ant -Dno=${SELECT_CONFIG_NO} -Dsub=${INSTALL_SELECT_CONFIG_CONF} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_DEPEND_DEST}" = "y" ]; then
	ant -Dno=${DEPEND_DEST_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_DEPEND_SRC}" = "y" ]; then
	ant -Dno=${DEPEND_SRC_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_CHECK_EXEC}" = "y" ]; then
	ant -Dno=${CHECK_EXEC_NO} -Dsub=${INSTALL_CHECK_EXEC_CONF} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_CHECK_CONNECTED_DB}" = "y" ]; then
	ant -Dno=${CHECK_CONNECTED_DB_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_DIFF_MD5}" = "y" ]; then
	ant -Dno=${DIFF_MD5_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_INVENTORY}" = "y" ]; then
	ant -Dno=${INVENTORY_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi
if [ "${INSTALL_INVENTORY2}" = "y" ]; then
	ant -Dno=${INVENTORY2_NO} -Dmode=${MODE} -DinstalledNo="${INSTALLED_NO}" -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install.xml"
	if [ $? -ne 0 ]; then error_func; fi
fi


##### インストール全体後処理 #####
echo 
ant -Dmode=${MODE} -DstackXml=${STACK_XML} -f "${SCRIPTS_DIR}install-after.xml"
if [ $? -ne 0 ]; then error_func; fi


##### 後処理 #####
end_func

}


##### 終了処理 #####
finally_func () {
	ANT_HOME=${_ANT_HOME}
	export ANT_HOME
	PATH=${_PATH}
	export PATH
	SCRIPTS_DIR=${_SCRIPTS_DIR}
	export SCRIPTS_DIR

	echo ${MODE_STR}処理を終了しました...
}


##### 正常終了 #####
end_func () {
	finally_func
	exit 0
}


##### 異常終了 #####
error_func () {
	echo ${MODE_STR}処理の途中で異常が発生しました...
	finally_func
	exit 1
}


##### 文字コード設定 #####
set_lang_func () {
	_OS_LANG=`echo ${LANG} | awk -F '.' '{print $2;}'`
	if [ "${_OS_LANG}" = "" ]; then
		echo 処理なし > /dev/nul
	else
		OS_LANG=${_OS_LANG}
	fi
}

main $*
