Install/OnPrem/XP/Scaled/Processing/Install-PRC.ps1

. "$PSScriptRoot\..\..\..\..\InstallParams.ps1" -Force
. "$PSScriptRoot\..\..\..\Solr\SolrParams.ps1" -Force
Import-Module "$PSScriptRoot\..\..\..\..\..\SQL\SQL-Module.psm1" -Force
Import-Module "$PSScriptRoot\..\..\..\..\..\Common\SSL\SSL-Module.psm1" -Force
Import-Module "$PSScriptRoot\..\..\..\Install-Module.psm1" -Force
$ErrorActionPreference = "Stop"

$prefix = $global:Configuration.prefix
$siteName = $global:Configuration.processing.hostName
$hostNames = @($siteName)
$license = $global:Configuration.license
$sqlServer = $global:Configuration.sql.serverName
$sqlUser = $global:Configuration.sql.adminUsername
$sqlAdminPassword = $global:Configuration.sql.adminPassword
$sqlSitecorePassword = $global:Configuration.sql.sitecorePassword
$solrURL = $SolrServiceURL
$collectionService = $global:Configuration.xConnect.collectionServiceURL
$installDir = $global:Configuration.processing.installDir
$reportingServiceApiKey = $global:Configuration.reporting.serviceApiKey
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *prc.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "sitecore-XP1-prc.json" -PackageName $package -DefaultValue "$PSScriptRoot\sitecore-XP1-prc.json"

$clientCert = BuildSitecoreClientCertName -Prefix $prefix
$serverCert = BuildSitecoreServerCertName -Prefix $prefix

Write-Output "Install Sitecore Processing started..."

$dbs = @("Processing.Tasks")
DeleteDatabases -SqlServer $sqlServer -Prefix $prefix -Databases $dbs -Username $sqlUser -Password $sqlAdminPassword

$sitecoreParams = @{
    Path                       = $sifConfiguration
    Package                    = $package.FullName
    LicenseFile                = $license
    XConnectCert               = $clientCert
    SSLCert                    = $serverCert
    SqlDbPrefix                = $prefix
    SolrCorePrefix             = $prefix
    Sitename                   = $siteName
    SqlServer                  = $sqlServer
    SqlAdminUser               = $sqlUser
    SqlAdminPassword           = $sqlAdminPassword
    SqlCoreUser                = "$($prefix)_coreuser"
    SqlCorePassword            = $sqlSitecorePassword
    SqlMasterUser              = "$($prefix)_masteruser"
    SqlMasterPassword          = $sqlSitecorePassword
    SqlWebUser                 = "$($prefix)_webuser"
    SqlWebPassword             = $sqlSitecorePassword
    SqlReportingUser           = "$($prefix)_reportinguser"
    SqlReportingPassword       = $sqlSitecorePassword
    SqlReferenceDataUser       = "$($prefix)_referencedatauser"
    SqlReferenceDataPassword   = $sqlSitecorePassword
    SqlProcessingPoolsUser     = "$($prefix)_processingpoolsuser"
    SqlProcessingPoolsPassword = $sqlSitecorePassword
    SqlProcessingTasksUser     = "$($prefix)_processingtasksuser"
    SqlProcessingTasksPassword = $sqlSitecorePassword
    SolrUrl                    = $solrURL
    ReportingServiceApiKey     = $reportingServiceApiKey
    XConnectCollectionService  = $collectionService
    InstallDirectory           = $installDir
}

Install-SitecoreConfiguration @sitecoreParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert

Write-Output "Install Sitecore Processing done."