install-postgresql.ps1 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Function Install-PostgreSQL() {
  2. . .\resources\get-file.ps1
  3. . .\resources\get-database_password.ps1
  4. . .\resources\start-pgsql.ps1
  5. . .\resources\get-installed-app.ps1
  6. if (Get-Installed-App "PostgreSQL*") {
  7. Write-Host PostgreSQL is already installed
  8. return
  9. }
  10. if ($env:PROCESSOR_ARCHITECTURE -eq "x86") {
  11. $url = "https://get.enterprisedb.com/postgresql/postgresql-10.1-3-windows.exe"
  12. }
  13. else {
  14. $url = "https://get.enterprisedb.com/postgresql/postgresql-10.1-3-windows-x64.exe"
  15. }
  16. Write-Host Download PostgreSQL from $url -ForegroundColor Cyan
  17. $filename = Get-File $url
  18. Write-Host Install Postgresql -ForegroundColor Cyan
  19. Start-Process $filename "--mode unattended --superpassword $database_password" -Wait
  20. #Get-Service postgre*
  21. Write-Host "Create the database and users" -ForegroundColor Cyan
  22. Start-PSQL "CREATE DATABASE fusionpbx;";
  23. Start-PSQL "CREATE DATABASE freeswitch;";
  24. Start-PSQL "CREATE ROLE fusionpbx WITH SUPERUSER LOGIN PASSWORD '$database_password';"
  25. Start-PSQL "CREATE ROLE freeswitch WITH SUPERUSER LOGIN PASSWORD '$database_password';"
  26. Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE fusionpbx to fusionpbx;"
  27. Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE freeswitch to fusionpbx;"
  28. Start-PSQL "GRANT ALL PRIVILEGES ON DATABASE freeswitch to freeswitch;"
  29. #move pg_hba.conf
  30. Move-Item "C:\Program Files\PostgreSQL\10\data\pg_hba.conf" "C:\Program Files\PostgreSQL\10\data\BAK_pg_hba.conf"
  31. Copy-Item ".\resources\postgresql\pg_hba.conf" "C:\Program Files\PostgreSQL\10\data\" -recurse
  32. #reload
  33. C:\Windows\system32\cscript.exe //NoLogo "C:\Program Files\PostgreSQL\10\scripts\serverctl.vbs" reload
  34. }