TITLE Pezar_Install v1.20
:: 1.10 dodato auto-RunAsAdministrator, cmd može da se skroluje, putanje: bpath ima na kraju \
:: 1.20 dodata instalacija AdoptOpenJDK, prelazi na unetu particiju da bi radile sve komande

:: set cmd shell window size
mode con: cols=150 lines=430
cls

@echo off

cacls "%systemroot%\system32\config\system" 1>nul 2>&1 || (powershell start -verb runas "%0" & exit /b)
set bpath=%~dp0
set /p partition="Uneste oznaku particije na kojoj ce baza biti instalirana: "

%partition%:

SET choice=
SET /p choice=Instaliraj AdoptOpenJDK? [N]: 
IF '%choice%'=='N' GOTO neinstalirajAdopt
IF '%choice%'=='n' GOTO neinstalirajAdopt

msiexec /i %bpath%requirements\OpenJDK8U-jre_x86-32_windows_hotspot_8u222b10.msi INSTALLLEVEL=2 /quiet

:neinstalirajAdopt

%bpath%requirements\postgresql-9.1.3-1-windows.exe --mode unattended --superaccount postgres --superpassword p324r --serverport 5432 --unattendedmodeui minimal  --datadir "%partition%:\PostgreSqlData"

set tmppath=%path%

IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)

   :64BIT
   echo 64-bit...
   set path=%PROGRAMFILES(X86)%\PostgreSQL\9.1\bin
   GOTO END

   :32BIT
   echo 32-bit...
   set path=%PROGRAMFILES%\PostgreSQL\9.1\bin
   GOTO END

:END

SET PGPASSWORD=p324r
psql.exe -U postgres -c "create user pezar with createrole superuser createdb replication password 'p324r';"

set path=%tmppath%
@echo on
icacls "%bpath%requirements\apache-activemq-5.5.1" /grant postgres:(OI)(CI)F /T /q
@echo off

cd %bpath%requirements\apache-activemq-5.5.1\bin\win32\
start /w InstallService.bat

sc config "ActiveMQ" obj= .\postgres password= p324r

SchTasks /Create /SC DAILY /TN PzBackup /TR %bpath%\requirements\PzBackup\PzBackup.bat /ST 00:00

netsh advfirewall firewall add rule name="Pezar PostgreSQL 5432" dir=in	action=allow protocol=TCP localport=5432
netsh advfirewall firewall add rule name="Pezar ActiveMQ 61616" dir=in action=allow protocol=TCP localport=61616
netsh advfirewall firewall add rule name="Pezar SymmetricDS 21415" dir=in action=allow protocol=TCP localport=21415

regedit /s %bpath%requirements\hide_postgres.reg

color 20
pause
@echo on

sc start ActiveMQ