@setlocal

@if "%H-TRAC-ROOT%"=="" (call tracvars.cmd)
@set DBNAME=sqlite:db/trac.db

@echo.
@echo ==== SQLite-based environment creation tool
@echo.



@if not "%1" == "" (set ENVNAME=%1 && goto ENVSET)

@echo Please enter the environment name:
@set /p ENVNAME=
@echo.

@if "%ENVNAME%" == "" (echo Error: You must set an environment name. && echo. && goto EXIT)

:ENVSET

@echo == Environment name: %ENVNAME%
@echo.



@echo == Creating environment ...
@echo.

@trac-admin "%H-TRAC-DATA%\%ENVNAME%" initenv "%ENVNAME%" %DBNAME%

@echo == Granting admin rights to the anonymous user ...
@echo.

@trac-admin "%H-TRAC-DATA%\%ENVNAME%" permission add anonymous TRAC_ADMIN

@echo == Enabling Mercurial plugin ...
@echo.

@trac-admin "%H-TRAC-DATA%\%ENVNAME%" config set components "tracext.hg.*" "enabled"

@echo == Enabling tags plugin ...
@echo.

@trac-admin "%H-TRAC-DATA%\%ENVNAME%" config set components "tractags.*" "enabled"

@echo == Database and wiki upgrade ...
@echo.

@trac-admin "%H-TRAC-DATA%\%ENVNAME%" upgrade
@echo.

@trac-admin "%H-TRAC-DATA%\%ENVNAME%" wiki upgrade
@echo.

@echo == done.
@echo.



:EXIT

@pause

@endlocal
