Install/OnPrem/XM/AllInOne/Install-Sitecore.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\..\..\..\..\Common\WebAdministration-Module.psm1" -Force
Import-Module "$PSScriptRoot\..\..\Install-Module.psm1" -Force
$ErrorActionPreference = "Stop"

$prefix = $global:Configuration.prefix
$hostNames = $global:Configuration.sitecore.hostNames
$siteName = $hostNames[0]
$installDir = $global:Configuration.sitecore.installDir
$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
$package = Get-ChildItem -Path "$SAFInstallPackageDir\*" -Include *single.scwdp.zip*
$sifConfiguration = GetSIFConfiguration -Name "sitecore-xm0.json" -PackageName $package -DefaultValue "$PSScriptRoot\sitecore-xm0.json"

$serverCert = BuildSitecoreServerCertName -Prefix $prefix

$sitecoreParams = @{
    Path                = $sifConfiguration
    Package             = $package
    LicenseFile         = $license
    SiteName            = $siteName
    SqlServer           = $sqlServer
    SqlAdminUser        = $sqlUser
    SqlAdminPassword    = $sqlAdminPassword
    SqlDbPrefix         = $prefix
    SqlCoreUser         = "$($prefix)_coreuser"
    SqlCorePassword     = $sqlSitecorePassword
    SqlMasterUser       = "$($prefix)_masteruser"
    SqlMasterPassword   = $sqlSitecorePassword
    SqlWebUser          = "$($prefix)_webuser"
    SqlWebPassword      = $sqlSitecorePassword
    SqlFormsUser        = "$($prefix)_formsuser"
    SqlFormsPassword    = $sqlSitecorePassword
    SSLCert             = $serverCert
    SolrCorePrefix      = $prefix
    SolrUrl             = $solrURL
    InstallDirectory    = $installDir
}

$dbs = @("Core", "Master", "Web", "ExperienceForms")
DeleteDatabases -SqlServer $sqlServer -Prefix $prefix -Databases $dbs -Username $sqlUser -Password $sqlAdminPassword
Install-SitecoreConfiguration @sitecoreParams
AddWebBindings -SiteName $siteName -HostNames $hostNames
AddWebBindings -SiteName $siteName -HostNames $hostNames -SSLCert $serverCert