
SET TRAC_LIGHT_HOME=C:\TracLight
SET TL_PROJECT_HOME=%TRAC_LIGHT_HOME%\projects
SET HG_PROJECT_HOME=%TL_PROJECT_HOME%\hg

python simplewget.py http://sourceforge.net/projects/mingw/files/Automated%%20MinGW%%20Installer/mingw-get-inst/mingw-get-inst-20100909/mingw-get-inst-20100909.exe
IF ERRORLEVEL 1 GOTO errormingw

start /WAIT mingw-get-inst-20100909.exe

REM fix cygwinccompiler.py to install mercurial
SET CYGWINCCOMPILER=%PYTHONHOME%\Lib\distutils\cygwinccompiler.py
copy /B %CYGWINCCOMPILER% %CYGWINCCOMPILER%.org
del %CYGWINCCOMPILER%c
sed "s/ld_version = StrictVersion(result.group(1))/ld_version = \"2.20.51\"/" %CYGWINCCOMPILER% > %CYGWINCCOMPILER%.tmp
sed "s/dllwrap_version = StrictVersion(result.group(1))/dllwrap_version = \"2.20.51\"/" %CYGWINCCOMPILER%.tmp > %CYGWINCCOMPILER%
del %CYGWINCCOMPILER%.tmp

REM install mercurial
SET PATH=%PATH%;C:\MinGW\bin;
copy distutils.cfg "%TRAC_LIGHT_HOME%\python\Lib\distutils\"
easy_install mercurial

svn co http://svn.edgewall.org/repos/trac/plugins/0.11/mercurial-plugin
cd mercurial-plugin
python setup.py install
cd ..
copy Mercurial.ini "%USERPROFILE%"

mkdir "%HG_PROJECT_HOME%"

copy create-hg-project.bat "%TRAC_LIGHT_HOME%\bin\"
copy trac.ini.hg.default "%TRAC_LIGHT_HOME%\install\"

start /WAIT cmd /c hg clone http://selenic.com/repo/hg-stable -r 1.5.4
cd hg-stable
copy /B hgwebdir.cgi+..\hgweb\hgwebdir.append hgwebdir.py.appended
sed  "s/from mercurial import demandimport/#from mercurial import demandimport/" hgwebdir.py.appended > "%HG_PROJECT_HOME%\hgwebdir.py"

cd ..\hgweb
copy hgweb.config "%HG_PROJECT_HOME%"

cd ..
python simplewget.py http://www.aminus.net/browser/modpython_gateway.py?format=raw
IF ERRORLEVEL 1 GOTO errorgateway

copy modpython_gateway.py "%HG_PROJECT_HOME%"

copy "%TRAC_LIGHT_HOME%\CollabNetSVN\httpd\conf\httpd.conf" "%TRAC_LIGHT_HOME%\CollabNetSVN\httpd\conf\httpd.conf.org"
copy /B "%TRAC_LIGHT_HOME%\CollabNetSVN\httpd\conf\httpd.conf.org"+hgweb\httpd.conf.append "%TRAC_LIGHT_HOME%\CollabNetSVN\httpd\conf\httpd.conf"

copy hgweb\hgrc.default "%TRAC_LIGHT_HOME%\install\"

copy hg-incoming-hook.bat "%TRAC_LIGHT_HOME%\bin\"

copy "%TRAC_LIGHT_HOME%\CollabNetSVN\httpd\htdocs\index.html" index.org.html
sed  "s/<li><a href=\"\/search\/index\.html\">/<li><a href=\"\/hg\/\">mercurialリポジトリ一覧<\/a><\/li>\n<li><a href=\"\/search\/index\.html\">/" index.org.html > "%TRAC_LIGHT_HOME%\CollabNetSVN\httpd\htdocs\index.html"

copy "%TRAC_LIGHT_HOME%\backup.bat" "%TRAC_LIGHT_HOME%\backup.bat.org"
copy /B "%TRAC_LIGHT_HOME%\backup.bat.org"+backup-hglight.bat "%TRAC_LIGHT_HOME%\backup.bat"

goto :EOF

:errormingw
echo MinGW download fail
pause
goto :EOF

:errorgateway
echo modpython_gateway.py download fail
pause
goto :EOF

