REM set paths
if not defined APACHE_PORT set APACHE_PORT=80
if not defined APACHE_HOSTNAME set APACHE_HOSTNAME=%computername%

textreplace -std ^
	-map @o4wroot@ %OSGEO4W_ROOT:\=/% ^
	-map @apache_hostname@ %APACHE_HOSTNAME% ^
	-map @apache_port_number@ %APACHE_PORT% ^
	-t apps/apache/conf/httpd.conf

REM create start menu links
if not %OSGEO4W_MENU_LINKS%==0 (
	if not exist "%OSGEO4W_STARTMENU%\Apache" mkdir "%OSGEO4W_STARTMENU%\Apache"
	xxmklink "%OSGEO4W_STARTMENU%\Apache\Install Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k install -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_STARTMENU%\Apache\Uninstall Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k uninstall -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_STARTMENU%\Apache\Start Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k install -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_STARTMENU%\Apache\Stop Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k start -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_STARTMENU%\Apache\Install Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k stop -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_STARTMENU%\Apache\Apache Monitor.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\ApacheMonitor.exe"
)

REM create desktop links
if not %OSGEO4W_DESKTOP_LINKS%==0 (
	if not exist "%OSGEO4W_DESKTOP%\Apache" mkdir "%OSGEO4W_DESKTOP%\Apache"
	xxmklink "%OSGEO4W_DESKTOP%\Apache\Install Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k install -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_DESKTOP%\Apache\Uninstall Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k uninstall -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_DESKTOP%\Apache\Start Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k install -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_DESKTOP%\Apache\Stop Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k start -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_DESKTOP%\Apache\Install Apache Web Service.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\httpd.exe" "-k stop -n ""Apache OSGeo4W Web Server"""
	xxmklink "%OSGEO4W_DESKTOP%\Apache\Apache Monitor.lnk" "%OSGEO4W_ROOT%\apps\apache\bin\ApacheMonitor.exe"
)

REM install and start the apache service
call apache-install.bat
exit /b 0
