@echo off
setlocal

REM ##### 初期設定 #####
set OPENSTANDIA_INSTALLER_VER=sample
set STACK_XML=stack-%OPENSTANDIA_INSTALLER_VER%.xml
set STACK_NAME=サンプルスタック
set ANT_DIR=apache-ant-1.7.0
set SCRIPTS_DIR=scripts
set CHECK_ANT_NO=1
set KICK_EXE_NO=3
set KICK_SHELL_NO=5
set UNZIP_TEST_NO=7
set REPLACE_TEST_NO=9
set SELECT_CONFIG_NO=11
set DEPEND_DEST_NO=13
set DEPEND_SRC_NO=15
set CHECK_EXEC_NO=17
set CHECK_CONNECTED_DB_NO=19
set DIFF_MD5_NO=21
set INVENTORY_NO=23
set INVENTORY2_NO=25


REM ##### 初期処理 #####
set CURRENT_DIR=%~dp0
if NOT "%CURRENT_DIR:~-1%" == "\" (
	set CURRENT_DIR=%CURRENT_DIR%\
)
set ANT_HOME=%CURRENT_DIR%lib\%ANT_DIR%
set PATH=%ANT_HOME%\bin;%CURRENT_DIR%bin;%PATH%
set SCRIPTS_DIR=%CURRENT_DIR%%SCRIPTS_DIR%
if NOT "%SCRIPTS_DIR:~-1%" == "\" (
	set SCRIPTS_DIR=%SCRIPTS_DIR%\
)


REM ##### 実行ユーザー権限チェック #####
call "%CURRENT_DIR%bin\CheckAuthority.bat"
if errorlevel 1 (
	echo 実行ユーザーにAdministrators権限がないため処理を続行できません。
	goto end
)


REM ##### javaインストールチェック #####
call "%CURRENT_DIR%bin\CheckInstalledJava.bat"
if errorlevel 1 (
	echo javaがインストールされていないため処理を続行できません。
	goto end
)


REM ##### OpenStandiaインストールチェック #####
call CheckInstalledApplication.bat %STACK_NAME%
if errorlevel 1 (
	set DEFAULT_MODE=1
) else (
	set DEFAULT_MODE=3
)


REM ##### 画面表示 #####
cls
echo %STACK_NAME%
echo OpenStandiaInstallerによるサンプルです。
echo.
echo 処理を選択してください。
echo 1 : インストール
echo 2 : アンインストール
echo 3 : アップデート
echo [%DEFAULT_MODE%]
set MODE_NO=%DEFAULT_MODE%
set /p MODE_NO=
if "%MODE_NO%" == "1" (
	set MODE=install
	set MODE_STR=インストール
)
if "%MODE_NO%" == "2" (
	set MODE=uninstall
	set MODE_STR=アンインストール
)
if "%MODE_NO%" == "3" (
	set MODE=update
	set MODE_STR=アップデート
)


REM ##### 構成情報の確認 #####
cls
echo 構成情報の確認をします...
REM check-ant
call GetProductInfo.bat %CHECK_ANT_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set CHECK_ANT_NAME=%PRODUCT_NAME%
set CHECK_ANT_VER=%PRODUCT_VER%
set CHECK_ANT_IS_INSTALLED=%IS_INSTALLED%
set CHECK_ANT_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM kick-exe
call GetProductInfo.bat %KICK_EXE_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set KICK_EXE_NAME=%PRODUCT_NAME%
set KICK_EXE_VER=%PRODUCT_VER%
set KICK_EXE_IS_INSTALLED=%IS_INSTALLED%
set KICK_EXE_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM kick-shell
call GetProductInfo.bat %KICK_SHELL_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set KICK_SHELL_NAME=%PRODUCT_NAME%
set KICK_SHELL_VER=%PRODUCT_VER%
set KICK_SHELL_IS_INSTALLED=%IS_INSTALLED%
set KICK_SHELL_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM unzip-test
call GetProductInfo.bat %UNZIP_TEST_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set UNZIP_TEST_NAME=%PRODUCT_NAME%
set UNZIP_TEST_VER=%PRODUCT_VER%
set UNZIP_TEST_IS_INSTALLED=%IS_INSTALLED%
set UNZIP_TEST_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM replace-test
call GetProductInfo.bat %REPLACE_TEST_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set REPLACE_TEST_NAME=%PRODUCT_NAME%
set REPLACE_TEST_VER=%PRODUCT_VER%
set REPLACE_TEST_IS_INSTALLED=%IS_INSTALLED%
set REPLACE_TEST_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM select-config
call GetProductInfo.bat %SELECT_CONFIG_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set SELECT_CONFIG_NAME=%PRODUCT_NAME%
set SELECT_CONFIG_VER=%PRODUCT_VER%
set SELECT_CONFIG_IS_INSTALLED=%IS_INSTALLED%
set SELECT_CONFIG_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM depend-dest
call GetProductInfo.bat %DEPEND_DEST_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set DEPEND_DEST_NAME=%PRODUCT_NAME%
set DEPEND_DEST_VER=%PRODUCT_VER%
set DEPEND_DEST_IS_INSTALLED=%IS_INSTALLED%
set DEPEND_DEST_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM depend-src
call GetProductInfo.bat %DEPEND_SRC_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set DEPEND_SRC_NAME=%PRODUCT_NAME%
set DEPEND_SRC_VER=%PRODUCT_VER%
set DEPEND_SRC_IS_INSTALLED=%IS_INSTALLED%
set DEPEND_SRC_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM check-exec
call GetProductInfo.bat %CHECK_EXEC_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set CHECK_EXEC_NAME=%PRODUCT_NAME%
set CHECK_EXEC_VER=%PRODUCT_VER%
set CHECK_EXEC_IS_INSTALLED=%IS_INSTALLED%
set CHECK_EXEC_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM check-connected-db
call GetProductInfo.bat %CHECK_CONNECTED_DB_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set CHECK_CONNECTED_DB_NAME=%PRODUCT_NAME%
set CHECK_CONNECTED_DB_VER=%PRODUCT_VER%
set CHECK_CONNECTED_DB_IS_INSTALLED=%IS_INSTALLED%
set CHECK_CONNECTED_DB_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM diff-md5
call GetProductInfo.bat %DIFF_MD5_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set DIFF_MD5_NAME=%PRODUCT_NAME%
set DIFF_MD5_VER=%PRODUCT_VER%
set DIFF_MD5_IS_INSTALLED=%IS_INSTALLED%
set DIFF_MD5_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM inventory
call GetProductInfo.bat %INVENTORY_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set INVENTORY_NAME=%PRODUCT_NAME%
set INVENTORY_VER=%PRODUCT_VER%
set INVENTORY_IS_INSTALLED=%IS_INSTALLED%
set INVENTORY_IS_VIEW=%IS_VIEW%
set /p x=.<nul

REM inventory2
call GetProductInfo.bat %INVENTORY2_NO%
call CheckViewProduct.bat %MODE% %IS_INSTALLED%
set INVENTORY2_NAME=%PRODUCT_NAME%
set INVENTORY2_VER=%PRODUCT_VER%
set INVENTORY2_IS_INSTALLED=%IS_INSTALLED%
set INVENTORY2_IS_VIEW=%IS_VIEW%
set /p x=.<nul


REM ##### インストール全体前処理 #####
echo.
call ant -Dmode=%MODE% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install-before.xml"
if errorlevel 1 goto error


REM ##### 問い合わせ #####
cls
set INSTALLED_NO=
REM check-ant
if "%CHECK_ANT_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%CHECK_ANT_NO%
	call ant -Dno=%CHECK_ANT_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_CHECK_ANT=n
	) else (
		set INSTALL_CHECK_ANT=y
		set /p INSTALL_CHECK_ANT="Antのバージョンを表示するサンプル(%CHECK_ANT_NAME% %CHECK_ANT_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_CHECK_ANT=n
)
if "%INSTALL_CHECK_ANT%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM kick-exe
if "%KICK_EXE_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%KICK_EXE_NO%
	call ant -Dno=%KICK_EXE_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_KICK_EXE=n
	) else (
		set INSTALL_KICK_EXE=y
		set /p INSTALL_KICK_EXE="実行ファイルを実行するサンプル(%KICK_EXE_NAME% %KICK_EXE_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_KICK_EXE=n
)
if "%INSTALL_KICK_EXE%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM kick-shell
if "%KICK_SHELL_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%KICK_SHELL_NO%
	call ant -Dno=%KICK_SHELL_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_KICK_SHELL=n
	) else (
		set INSTALL_KICK_SHELL=y
		set /p INSTALL_KICK_SHELL="バッチファイルを実行するサンプル(%KICK_SHELL_NAME% %KICK_SHELL_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_KICK_SHELL=n
)
if "%INSTALL_KICK_SHELL%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM unzip-test
if "%UNZIP_TEST_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%UNZIP_TEST_NO%
	call ant -Dno=%UNZIP_TEST_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_UNZIP_TEST=n
	) else (
		set INSTALL_UNZIP_TEST=y
		set /p INSTALL_UNZIP_TEST="ZIPファイルを解凍するサンプル(%UNZIP_TEST_NAME% %UNZIP_TEST_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_UNZIP_TEST=n
)
if "%INSTALL_UNZIP_TEST%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM replace-test
if "%REPLACE_TEST_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%REPLACE_TEST_NO%
	call ant -Dno=%REPLACE_TEST_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_REPLACE_TEST=n
	) else (
		set INSTALL_REPLACE_TEST=y
		set /p INSTALL_REPLACE_TEST="文字列置換をするサンプル(%REPLACE_TEST_NAME% %REPLACE_TEST_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_REPLACE_TEST=n
)
if "%INSTALL_REPLACE_TEST%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

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

REM depend-dest
if "%DEPEND_DEST_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%DEPEND_DEST_NO%
	call ant -Dno=%DEPEND_DEST_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_DEPEND_DEST=n
	) else (
		set INSTALL_DEPEND_DEST=y
		set /p INSTALL_DEPEND_DEST="依存先(%DEPEND_DEST_NAME% %DEPEND_DEST_VER%)を%MODE_STR%しますか？(y/n) [y]"
	)
) else (
	set INSTALL_DEPEND_DEST=n
)
if "%INSTALL_DEPEND_DEST%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM depend-src
if "%DEPEND_SRC_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%DEPEND_SRC_NO%
	call ant -Dno=%DEPEND_SRC_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_DEPEND_SRC=n
	) else (
		set INSTALL_DEPEND_SRC=y
		set /p INSTALL_DEPEND_SRC="依存元(%DEPEND_SRC_NAME% %DEPEND_SRC_VER%)を%MODE_STR%しますか？(y/n) [y]"
	)
) else (
	set INSTALL_DEPEND_SRC=n
)
if "%INSTALL_DEPEND_SRC%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM check-exec
if "%CHECK_EXEC_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%CHECK_EXEC_NO%
	call ant -Dno=%CHECK_EXEC_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_CHECK_EXEC=n
	) else (
		set INSTALL_CHECK_EXEC=y
		set /p INSTALL_CHECK_EXEC="実行前に実行確認をするサンプル(%CHECK_EXEC_NAME% %CHECK_EXEC_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_CHECK_EXEC=n
)
if "%INSTALL_CHECK_EXEC%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)
set INSTALL_CHECK_EXEC_CONF=0
if "%INSTALL_CHECK_EXEC%" == "y" (
	echo 実行確認の結果を選択してください。
	echo 1 : 実行していい
	echo 2 : 実行してはダメ
	set /p INSTALL_CHECK_EXEC_CONF=
)

REM check-connected-db
if "%CHECK_CONNECTED_DB_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%CHECK_CONNECTED_DB_NO%
	call ant -Dno=%CHECK_CONNECTED_DB_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_CHECK_CONNECTED_DB=n
	) else (
		set INSTALL_CHECK_CONNECTED_DB=y
		set /p INSTALL_CHECK_CONNECTED_DB="DB接続チェック(%CHECK_CONNECTED_DB_NAME% %CHECK_CONNECTED_DB_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_CHECK_CONNECTED_DB=n
)
if "%INSTALL_CHECK_CONNECTED_DB%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM diff-md5
if "%DIFF_MD5_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%DIFF_MD5_NO%
	call ant -Dno=%DIFF_MD5_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_DIFF_MD5=n
	) else (
		set INSTALL_DIFF_MD5=y
		set /p INSTALL_DIFF_MD5="MD5によりファイル比較をする(%DIFF_MD5_NAME% %DIFF_MD5_VER%)を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_DIFF_MD5=n
)
if "%INSTALL_DIFF_MD5%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM inventory
if "%INVENTORY_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%INVENTORY_NO%
	call ant -Dno=%INVENTORY_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_INVENTORY=n
	) else (
		set INSTALL_INVENTORY=y
		set /p INSTALL_INVENTORY="インベントリーサンプル(%INVENTORY_NAME% %INVENTORY_VER%)の%MODE_STR%を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_INVENTORY=n
)
if "%INSTALL_INVENTORY%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)

REM inventory2
if "%INVENTORY2_IS_VIEW%" == "y" (
	set SELECTED_NO=%INSTALLED_NO%,%INVENTORY2_NO%
	call ant -Dno=%INVENTORY2_NO% -Dmode=%MODE% -DinstalledNo="%SELECTED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml" check-installed 1>nul 2>nul
	if errorlevel 1 (
		set INSTALL_INVENTORY2=n
	) else (
		set INSTALL_INVENTORY2=y
		set /p INSTALL_INVENTORY2="インベントリーサンプル(%INVENTORY2_NAME% %INVENTORY2_VER%)の%MODE_STR%を実行しますか？(y/n) [y]"
	)
) else (
	set INSTALL_INVENTORY2=n
)
if "%INSTALL_INVENTORY2%" == "y" (
	set INSTALLED_NO=%SELECTED_NO%
)


REM ##### ダウンロード実行 #####
echo.
echo ダウンロード処理を開始します...
if "%INSTALL_CHECK_ANT%" == "y" (
	call ant -Dno=%CHECK_ANT_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_KICK_EXE%" == "y" (
	call ant -Dno=%KICK_EXE_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_KICK_SHELL%" == "y" (
	call ant -Dno=%KICK_SHELL_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_UNZIP_TEST%" == "y" (
	call ant -Dno=%UNZIP_TEST_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_REPLACE_TEST%" == "y" (
	call ant -Dno=%REPLACE_TEST_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_SELECT_CONFIG%" == "y" (
	call ant -Dno=%SELECT_CONFIG_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_DEPEND_DEST%" == "y" (
	call ant -Dno=%DEPEND_DEST_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_DEPEND_SRC%" == "y" (
	call ant -Dno=%DEPEND_SRC_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_CHECK_EXEC%" == "y" (
	call ant -Dno=%CHECK_EXEC_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_CHECK_CONNECTED_DB%" == "y" (
	call ant -Dno=%CHECK_CONNECTED_DB_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_DIFF_MD5%" == "y" (
	call ant -Dno=%DIFF_MD5_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_INVENTORY%" == "y" (
	call ant -Dno=%INVENTORY_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_INVENTORY2%" == "y" (
	call ant -Dno=%INVENTORY2_NO% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%download.xml"
	if errorlevel 1 goto error
)


REM ##### インストール実行 #####
echo.
echo %MODE_STR%処理を開始します...
if "%INSTALL_CHECK_ANT%" == "y" (
	call ant -Dno=%CHECK_ANT_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_KICK_EXE%" == "y" (
	call ant -Dno=%KICK_EXE_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_KICK_SHELL%" == "y" (
	call ant -Dno=%KICK_SHELL_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_UNZIP_TEST%" == "y" (
	call ant -Dno=%UNZIP_TEST_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_REPLACE_TEST%" == "y" (
	call ant -Dno=%REPLACE_TEST_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_SELECT_CONFIG%" == "y" (
	call ant -Dno=%SELECT_CONFIG_NO% -Dsub=%INSTALL_SELECT_CONFIG_CONF% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_DEPEND_DEST%" == "y" (
	call ant -Dno=%DEPEND_DEST_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_DEPEND_SRC%" == "y" (
	call ant -Dno=%DEPEND_SRC_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_CHECK_EXEC%" == "y" (
	call ant -Dno=%CHECK_EXEC_NO% -Dsub=%INSTALL_CHECK_EXEC_CONF% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_CHECK_CONNECTED_DB%" == "y" (
	call ant -Dno=%CHECK_CONNECTED_DB_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_DIFF_MD5%" == "y" (
	call ant -Dno=%DIFF_MD5_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_INVENTORY%" == "y" (
	call ant -Dno=%INVENTORY_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)
if "%INSTALL_INVENTORY2%" == "y" (
	call ant -Dno=%INVENTORY2_NO% -Dmode=%MODE% -DinstalledNo="%INSTALLED_NO%" -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install.xml"
	if errorlevel 1 goto error
)


REM ##### インストール全体後処理 #####
echo.
call ant -Dmode=%MODE% -DstackXml=%STACK_XML% -f "%SCRIPTS_DIR%install-after.xml"
if errorlevel 1 goto error

goto end
REM ##### 異常終了 #####
:error
echo %MODE_STR%処理の途中で異常が発生しました...


REM ##### 処理終了 #####
:end
echo %MODE_STR%処理を終了しました...

endlocal
