Pipelines/Steps/Install/OnPrem/Sitecore/XM/Scaled/9.0/Install-CM.ps1

$ErrorActionPreference = "Stop"

$prefix = $SAFConfiguration.prefix
$license = $SAFConfiguration.license
$sqlServer = $SAFConfiguration.sql.serverName
$sqlUser = $SAFConfiguration.sql.adminUsername
$sqlAdminPassword = $SAFConfiguration.sql.adminPassword
$sqlSitecorePassword = $SAFConfiguration.sql.sitecorePassword
$solrURL = $SAFSolrServiceURL
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *cm.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "sitecore-XM1-cm.json" -ContextPath "$PSScriptRoot"

$serverCert = BuildSitecoreServerCertName -Prefix $prefix
$hostNames = $SAFConfiguration.sitecore.hostNames
$siteName = $hostNames[0]
$installDir = $SAFConfiguration.sitecore.installDir

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

$dbs = @("$($prefix)_Core", "$($prefix)_Master", "$($prefix)_Web", "$($prefix)_ExperienceForms")
DeleteDatabases -SqlServer $sqlServer -Databases $dbs -Username $sqlUser -Password $sqlAdminPassword

$sitecoreParams = @{
    Path              = $sifConfiguration
    Package           = $package.FullName
    LicenseFile       = $license
    SqlDbPrefix       = $prefix
    SqlServer         = $sqlServer
    SqlAdminUser      = $sqlUser
    SqlAdminPassword  = $sqlAdminPassword
    SqlCoreUser       = "$($prefix)_coreuser"
    SqlCorePassword   = $sqlSitecorePassword
    SqlMasterUser     = "$($prefix)_masteruser"
    SqlMasterPassword = $sqlSitecorePassword
    SqlWebUser        = "$($prefix)_webuser"
    SqlWebPassword    = $sqlSitecorePassword
    SqlFormsUser      = "$($prefix)_formsuser"
    SqlFormsPassword  = $sqlSitecorePassword
    SolrCorePrefix    = $prefix
    SolrUrl           = $solrURL
    Sitename          = $siteName
    SSLCert           = $serverCert
    InstallDirectory  = $installDir
}
Install-SitecoreConfiguration @sitecoreParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert
Write-Output "Install Sitecore CM done."