Install/OnPrem/XP/Scaled/Reporting/Install-REP.ps1

. "$PSScriptRoot\..\..\..\..\InstallParams.ps1"
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.reporting.hostName
$hostNames = @($siteName)
$license = $global:Configuration.license
$sqlServer = $global:Configuration.sql.serverName
$sqlSitecorePassword = $global:Configuration.sql.sitecorePassword
$installDir = $global:Configuration.reporting.installDir
$serviceApiKey = $global:Configuration.reporting.serviceApiKey
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *rep.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "sitecore-XP1-rep.json" -PackageName $package -DefaultValue "$PSScriptRoot\sitecore-XP1-rep.json"

$serverCert = BuildSitecoreServerCertName -Prefix $prefix

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

$sitecoreParams = @{
    Path                   = $sifConfiguration
    Package                = $package.FullName
    LicenseFile            = $license
    Sitename               = $siteName
    SSLCert                = $serverCert
    SqlDbPrefix            = $prefix
    SqlCoreUser            = "$($prefix)_coreuser"
    SqlCorePassword        = $sqlSitecorePassword
    SqlMasterUser          = "$($prefix)_masteruser"
    SqlMasterPassword      = $sqlSitecorePassword
    SqlWebUser             = "$($prefix)_webuser"
    SqlWebPassword         = $sqlSitecorePassword
    SqlReportingUser       = "$($prefix)_reportinguser"
    SqlReportingPassword   = $sqlSitecorePassword
    SqlServer              = $sqlServer
    ReportingServiceApiKey = $serviceApiKey 
    InstallDirectory       = $installDir
}
Install-SitecoreConfiguration @sitecoreParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert

Write-Output "Install Sitecore Reporting done."