
SET TRAC_LIGHT_HOME=%1
SET PATH=%TRAC_LIGHT_HOME%\CollabNetSVN;python;bin;%PATH%
SET PYTHONHOME=
SET PYTHONPATH=

REM TracXMLRPCの互換性によるアップグレードの失敗防止
if exist "%TRAC_LIGHT_HOME%\python\lib\site-packages\TracXMLRPC-1.*" del /q "%TRAC_LIGHT_HOME%\python\lib\site-packages\TracXMLRPC-1.*"
if exist "%TRAC_LIGHT_HOME%\python\lib\site-packages\json.py*" del /q "%TRAC_LIGHT_HOME%\python\lib\site-packages\json.py*"

if not DEFINED TL_PROJECT_HOME set TL_PROJECT_HOME=%~1\projects
if not exist "%TL_PROJECT_HOME%" mkdir %TL_PROJECT_HOME% 
if not exist "%TL_PROJECT_HOME%\trac" mkdir "%TL_PROJECT_HOME%\trac"
if not exist "%TL_PROJECT_HOME%\svn" mkdir "%TL_PROJECT_HOME%\svn"
if not exist "%TL_PROJECT_HOME%\maven" if exist "%TRAC_LIGHT_HOME%\maven" mkdir "%TL_PROJECT_HOME%\maven"
if not exist "%TL_PROJECT_HOME%\report" if exist "%TRAC_LIGHT_HOME%\maven" mkdir "%TL_PROJECT_HOME%\report"

REM ==== Pythonモジュールのインストール ====
cd python-lib

REM ==== Tracのインストール ====
cd genshi
if exist build rmdir /S /Q build
..\..\python\python.exe setup.py install

cd ..\docutils
..\..\python\python.exe setup.py install

cd ..\feedparser
..\..\python\python.exe setup.py install

cd ..\Pygments
..\..\python\python.exe setup.py install

cd ..\pyExcelerator
..\..\python\python.exe setup.py install

cd ..\configobj
..\..\python\python.exe setup.py install

cd ..\xlrd
..\..\python\python.exe setup.py install

cd ..\simplejson
..\..\python\python.exe setup.py install

cd ..\trac
if exist build rmdir /S /Q build
..\..\python\python.exe setup.py install

if not exist ..\..\CollabNetSVN\httpd\htdocs\trac_common mkdir ..\..\CollabNetSVN\httpd\htdocs\trac_common
xcopy trac\htdocs ..\..\CollabNetSVN\httpd\htdocs\trac_common /e/c/f/h/y

cd ..\svn

if not exist ..\..\python\Lib\site-packages\svn mkdir ..\..\python\Lib\site-packages\svn
xcopy svn ..\..\python\Lib\site-packages\svn /e/c/f/h/y
if not exist ..\..\python\Lib\site-packages\libsvn mkdir ..\..\python\Lib\site-packages\libsvn
xcopy libsvn ..\..\python\Lib\site-packages\libsvn /e/c/f/h/y
copy ..\..\CollabNetSVN\ssleay32.dll ..\..\python\Lib\site-packages\libsvn
copy ..\..\CollabNetSVN\libeay32.dll ..\..\python\Lib\site-packages\libsvn
xcopy ..\..\CollabNetSVN\libsvn_* ..\..\CollabNetSVN\httpd\modules /y

copy /y ..\..\python\Lib\site-packages\libsvn\_client.dll ..\..\python\Lib\site-packages\libsvn\_client.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_core.dll ..\..\python\Lib\site-packages\libsvn\_core.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_delta.dll ..\..\python\Lib\site-packages\libsvn\_delta.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_diff.dll ..\..\python\Lib\site-packages\libsvn\_diff.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_fs.dll ..\..\python\Lib\site-packages\libsvn\_fs.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_ra.dll ..\..\python\Lib\site-packages\libsvn\_ra.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_repos.dll ..\..\python\Lib\site-packages\libsvn\_repos.pyd
copy /y ..\..\python\Lib\site-packages\libsvn\_wc.dll ..\..\python\Lib\site-packages\libsvn\_wc.pyd

cd ..\..


REM ==== Tracプラグインのインストール ====
cd plugins\svn

@REM === 設定系プラグイン ===
cd acct_mgr
..\..\..\python\python.exe setup.py install

cd ..\customfieldadmin
..\..\..\python\python.exe setup.py install

cd ..\iniadmin
..\..\..\python\python.exe setup.py install

cd ..\svnauthzadminplugin
..\..\..\python\python.exe setup.py install

cd ..\usermanager
..\..\..\python\python.exe setup.py install

cd ..\authz_policy
..\..\..\python\python.exe setup.py install

cd ..\privatewikiplugin
..\..\..\python\python.exe setup.py install

cd ..\xdocview
..\..\..\python\python.exe setup.py install

cd ..\workfloweditorplugin
..\..\..\python\python.exe setup.py install


@REM === 装飾系 ====
cd ..\macropost
..\..\..\python\python.exe setup.py install

cd ..\addcomment
..\..\..\python\python.exe setup.py install

cd ..\ganttcalendar
..\..\..\python\python.exe setup.py install

cd ..\decorator
..\..\..\python\python.exe setup.py install

cd ..\completeuser
..\..\..\python\python.exe setup.py install

cd ..\discussion
..\..\..\python\python.exe setup.py install

cd ..\tocmacro
..\..\..\python\python.exe setup.py install

cd ..\autowikifyplugin
..\..\..\python\python.exe setup.py install

@REM cd ..\tractags
@REM ..\..\..\python\python.exe setup.py install

cd ..\tracwysiwyg
..\..\..\python\python.exe setup.py install

cd ..\sectioneditplugin
..\..\..\python\python.exe setup.py install

cd ..\lightningtheme
..\..\..\python\python.exe setup.py install

cd ..\themeengineplugin
..\..\..\python\python.exe setup.py install

cd ..\ticketsubmitpolicyplugin
..\..\..\python\python.exe setup.py install

cd ..\ticketclone
..\..\..\python\python.exe setup.py install

@REM === その他 ====
cd ..\TraM
..\..\..\python\python.exe setup.py install

cd ..\xmlrpcplugin
..\..\..\python\python.exe setup.py install

cd ..\stractistics
..\..\..\python\python.exe setup.py install

cd ..\tracreposearch
..\..\..\python\python.exe setup.py install

cd ..\hudsontracplus
..\..\..\python\python.exe setup.py install

cd ..\advancedticketworkflow
..\..\..\python\python.exe setup.py install

cd ..\batchmodify
..\..\..\python\python.exe setup.py install

cd ..\ticketdelete
..\..\..\python\python.exe setup.py install

cd ..\peerreviewplugin
..\..\..\python\python.exe setup.py install

cd ..\tracnav
..\..\..\python\python.exe setup.py install

cd ..\querychart
..\..\..\python\python.exe setup.py install

cd ..\excelreport
..\..\..\python\python.exe setup.py install

cd ..\ExcelReportExport
..\..\..\python\python.exe setup.py install

cd ..\ticketimportplugin
..\..\..\python\python.exe setup.py install

cd ..\timingandestimationplugin
..\..\..\python\python.exe setup.py install

cd ..\searchhyperestraier
..\..\..\python\python.exe setup.py install

cd ..\mailarchiveplugin
..\..\..\python\python.exe setup.py install

cd ..\masterticketsplugin
..\..\..\python\python.exe setup.py install

cd ..\wikirenameplugin
..\..\..\python\python.exe setup.py install

cd ..\newwikipagebutton
..\..\..\python\python.exe setup.py install

cd ..\tracdragdropplugin
..\..\..\python\python.exe setup.py install


cd ..\..\..

REM ==== 環境固有の設定 ====
python\python.exe install\replace.py %1 install\replace\start.bat.in start.bat
python\python.exe install\replace.py %1 install\replace\create-project.bat.in bin\create-project.bat"
python\python.exe install\replace.py %1 install\replace\post-commit.bat.in bin\post-commit.bat"
python\python.exe install\replace.py %1 install\replace\pre-revprop-change.bat bin\pre-revprop-change.bat"
python\python.exe install\replace.py %1 install\replace\setenv.bat.in bin\setenv.bat
python\python.exe install\replace.py %1 install\replace\create-servercert.bat.in bin\create-servercert.bat
python\python.exe install\replace.py %1 install\replace\trac-admin.bat.in  bin\trac-admin.bat

python\python.exe install\replace.py %1 install/replace/library-pom.xml.in install/repository/LibraryProject/trunk/pom.xml.temp
python\python.exe install\replace-projecthome.py "%TL_PROJECT_HOME%" install/repository/LibraryProject/trunk/pom.xml.temp install/repository/LibraryProject/trunk/pom.xml
del install\repository\LibraryProject\trunk\pom.xml.temp

python\python.exe install\replace.py %1 install/replace/web-pom.xml.in install/repository/WebProject/trunk/pom.xml.temp
python\python.exe install\replace-projecthome.py "%TL_PROJECT_HOME%" install/repository/WebProject/trunk/pom.xml.temp install/repository/WebProject/trunk/pom.xml
del install\repository\WebProject\trunk\pom.xml.temp

python\python.exe install\replace.py %1 install/sitecustomize.py python/Lib/site-packages/sitecustomize.py
python\python.exe install\replace.py %1 install/replace/trac.cgi.in CollabNetSVN/httpd/cgi-bin/trac.cgi

python\python.exe install\replace.py %1 install/replace/hudson.bat.in hudson\hudson.bat

if exist "python\share\trac\conf\trac.ini" goto skipTracIni
mkdir python\share\trac\conf
python\python.exe install\replace.py %1 install/replace/trac.ini.in python/share/trac/conf/trac.ini.temp2
python\python.exe install\replace-projecthome.py "%TL_PROJECT_HOME%" python/share/trac/conf/trac.ini.temp2 python/share/trac/conf/trac.ini.temp
del python\share\trac\conf\trac.ini.temp2

if not exist hudson\hudson.war bin\sed.exe s\hudsontrac\#hudsontrac\ python\share\trac\conf\trac.ini.temp > python\share\trac\conf\trac.ini 
if exist hudson\hudson.war copy python\share\trac\conf\trac.ini.temp  python\share\trac\conf\trac.ini
del python\share\trac\conf\trac.ini.temp 

goto tracIniEnd
:skipTracIni
python\python.exe install\replace.py %1 install/replace/trac.ini.in python/share/trac/conf/trac.ini.temp2
python\python.exe install\replace-projecthome.py "%TL_PROJECT_HOME%" python/share/trac/conf/trac.ini.temp2 python/share/trac/conf/trac.ini.temp
del python\share\trac\conf\trac.ini.temp2

if not exist hudson\hudson.war bin\sed.exe s\hudsontrac\#hudsontrac\ python\share\trac\conf\trac.ini.temp > python\share\trac\conf\trac.ini
if exist hudson\hudson.war copy python\share\trac\conf\trac.ini.temp  python\share\trac\conf\trac.ini
del python\share\trac\conf\trac.ini.temp 

:tracIniEnd

REM ==== プロジェクトの作成 ====
call bin\create-project.bat SampleProject

REM ==== SampleProjectのSVNリポジトリの初期化 ====
bin\bash.exe install/setuprepository.sh "%TL_PROJECT_HOME%"

REM ==== Allプロジェクトの作成 ====
call bin\create-project.bat all
python\python.exe install\replace.py %1 install/replace/trac.ini.all "%TL_PROJECT_HOME%\trac\all\conf\trac.ini.temp"
python\python.exe install\replace-projecthome.py "%TL_PROJECT_HOME%" "%TL_PROJECT_HOME%\trac\all\conf\trac.ini.temp" "%TL_PROJECT_HOME%\trac\all\conf\trac.ini"
del "%TL_PROJECT_HOME%\trac\all\conf\trac.ini.temp"

call bin\trac-admin.bat "%TL_PROJECT_HOME%\trac\all" upgrade

REM ==== htdigest,svnauthz ====
if not exist "%TL_PROJECT_HOME%\trac.htdigest" copy install\trac.htdigest "%TL_PROJECT_HOME%"
if not exist "%TL_PROJECT_HOME%\svnauthz" copy install\svnauthz "%TL_PROJECT_HOME%"

REM ==== copy hudson ====
if not exist "%TL_PROJECT_HOME%\hudson" if exist "%TRAC_LIGHT_HOME%\hudson" mkdir "%TL_PROJECT_HOME%\hudson" & xcopy "%TRAC_LIGHT_HOME%\install\hudson" "%TL_PROJECT_HOME%\hudson" /e/c/f/h/y

