
SET TRAC_LIGHT_HOME=C:\TracLight
SET PATH=%TRAC_LIGHT_HOME%\python;%TRAC_LIGHT_HOME%\CollabNetSVN;%TRAC_LIGHT_HOME%\bin;%PATH%

if not DEFINED TL_PROJECT_HOME set TL_PROJECT_HOME=%TRAC_LIGHT_HOME%\projects

SET PROJNAME=%1
if not "%1" == "" goto skip_input

echo プロジェクト名を入力してください。
echo (※プロジェクト名は半角英数字で入力してください。スペースと全角文字を入力しないでください)

SET /P PROJNAME=プロジェクト名: 

:skip_input


if exist "%TL_PROJECT_HOME%\hg\%PROJNAME%" goto :EOF

REM svnadmin create "%TL_PROJECT_HOME%\svn\%PROJNAME%"
start /WAIT cmd /c hg init "%TL_PROJECT_HOME%\hg\%PROJNAME%"

REM copy "%TRAC_LIGHT_HOME%\bin\post-commit.bat" "%TL_PROJECT_HOME%\svn\%PROJNAME%\hooks\post-commit.bat"
copy "%TRAC_LIGHT_HOME%\bin\hg-incoming-hook.bat" "%TL_PROJECT_HOME%\hg\%PROJNAME%\.hg\hg-incoming-hook.bat"
REM copy "%TRAC_LIGHT_HOME%\bin\pre-revprop-change.bat" "%TL_PROJECT_HOME%\svn\%PROJNAME%\hooks\pre-revprop-change.bat"

python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" initenv --inherit="%TRAC_LIGHT_HOME%\python\share\trac\conf\trac.ini" %PROJNAME% sqlite:db/trac.db hg "%TL_PROJECT_HOME%/hg/%PROJNAME%"

python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" upgrade
python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" permission add anonymous DISCUSSION_VIEW
python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" permission add authenticated DISCUSSION_APPEND TICKET_EDIT_CC CODE_REVIEW_DEV
python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" permission add admin TRAC_ADMIN CODE_REVIEW_MGR
python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" permission add developer authenticated 
python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" permission add leader MILESTONE_CREATE MILESTONE_MODIFY TICKET_ADMIN CODE_REVIEW_MGR


python "%TRAC_LIGHT_HOME%\python\scripts\trac-admin-script.py" "%TL_PROJECT_HOME%/trac/%PROJNAME%" permission add guest developer



bash.exe "%TRAC_LIGHT_HOME%/bin/addsvnconf.sh" "%TL_PROJECT_HOME%" %PROJNAME%
copy _tmp.ini "%TL_PROJECT_HOME%\trac\%PROJNAME%\conf\trac.ini"
del _tmp.ini
echo authz_module_name = %PROJNAME% >> "%TL_PROJECT_HOME%\trac\%PROJNAME%\conf\trac.ini"

type "%TRAC_LIGHT_HOME%\install\trac.ini.hg.default" >> "%TL_PROJECT_HOME%\trac\%PROJNAME%\conf\trac.ini"
copy "%TRAC_LIGHT_HOME%\install\authzpolicy.conf.default" "%TL_PROJECT_HOME%\trac\%PROJNAME%\conf\authzpolicy.conf"

xcopy "%TRAC_LIGHT_HOME%\install\trac-template" "%TL_PROJECT_HOME%\trac\%PROJNAME%" /e/c/f/h/y

sqlite3.exe -batch -init "%TRAC_LIGHT_HOME%\install\dbinit.sql"  "%TL_PROJECT_HOME%\trac\%PROJNAME%\db\trac.db" <nul

type "%TRAC_LIGHT_HOME%\install\hgrc.default" >> "%TL_PROJECT_HOME%\hg\%PROJNAME%\.hg\hgrc"
echo [hooks] >> "%TL_PROJECT_HOME%\hg\%PROJNAME%\.hg\hgrc"
echo incoming.trac=cmd /c "%TL_PROJECT_HOME%\hg\%PROJNAME%\.hg\hg-incoming-hook.bat" >> "%TL_PROJECT_HOME%\hg\%PROJNAME%\.hg\hgrc"

goto :EOF

:error
echo プロジェクト名が指定されていません。
echo Usage: create-project.bat [プロジェクト名]
echo on

