forked from Sitecore/Habitat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-xp0.ps1
339 lines (304 loc) · 12.3 KB
/
install-xp0.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#####################################################
#
# Install Sitecore
#
#####################################################
$ErrorActionPreference = 'Stop'
. $PSScriptRoot\settings.ps1
Write-Host "*******************************************************" -ForegroundColor Green
Write-Host " Installing Sitecore $SitecoreVersion" -ForegroundColor Green
Write-Host " Sitecore: $SitecoreSiteName" -ForegroundColor Green
Write-Host " xConnect: $XConnectSiteName" -ForegroundColor Green
Write-Host "*******************************************************" -ForegroundColor Green
function Install-Prerequisites {
#Verify SQL version
$SqlRequiredVersion = "13.0.4001"
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $SqlServer
if (-not $srv -or -not $srv.Version) {
throw "Could not find SQL Server '$SqlServer', check settings.ps1"
}
$minVersion = New-Object System.Version($RequiredSqlVersion)
if ($srv.Version.CompareTo($minVersion) -lt 0) {
throw "Invalid SQL version. Expected SQL 2016 SP1 (13.0.4001.0) or over."
}
#Verify Java version
$JRERequiredVersion = "1.8"
$minVersion = New-Object System.Version($JRERequiredVersion)
$foundVersion = $FALSE
$jrePath = "HKLM:\SOFTWARE\JavaSoft\Java Runtime Environment"
$jdkPath = "HKLM:\SOFTWARE\JavaSoft\Java Development Kit"
$jrePath9 = "HKLM:\SOFTWARE\JavaSoft\JRE"
$jdkPath9 = "HKLM:\SOFTWARE\JavaSoft\JDK"
if (Test-Path $jrePath) {
$path = $jrePath
}
elseif (Test-Path $jdkPath) {
$path = $jdkPath
}
elseif (Test-Path $jrePath9) {
$path = $jrePath9
}
elseif (Test-Path $jdkPath9) {
$path = $jdkPath9
}
else {
throw "Cannot find Java Runtime Environment or Java Development Kit on this machine."
}
$javaVersionStrings = Get-ChildItem $path | ForEach-Object { $parts = $_.Name.Split("\"); $parts[$parts.Count-1] }
foreach ($versionString in $javaVersionStrings) {
try {
$version = New-Object System.Version($versionString)
} catch {
continue
}
if ($version.CompareTo($minVersion) -ge 0) {
$foundVersion = $TRUE
}
}
if (-not $foundVersion) {
throw "Invalid Java version. Expected $minVersion or over."
}
# Verify Web Deploy
$webDeployPath = ([IO.Path]::Combine($env:ProgramFiles, 'iis', 'Microsoft Web Deploy V3', 'msdeploy.exe'))
if (!(Test-Path $webDeployPath)) {
throw "Could not find WebDeploy in $webDeployPath"
}
# Verify DAC Fx
# Verify Microsoft.SqlServer.TransactSql.ScriptDom.dll
try {
$assembly = [reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.TransactSql.ScriptDom")
if (-not $assembly) {
throw "error"
}
} catch {
throw "Could load the Microsoft.SqlServer.TransactSql.ScriptDom assembly. Please make sure it is installed and registered in the GAC"
}
#Enable Contained Databases
Write-Host "Enable contained databases" -ForegroundColor Green
try
{
Invoke-Sqlcmd -ServerInstance $SqlServer `
-Username $SqlAdminUser `
-Password $SqlAdminPassword `
-InputFile "$PSScriptRoot\build\database\containedauthentication.sql"
}
catch
{
write-host "Set Enable contained databases failed" -ForegroundColor Red
throw
}
# Verify Solr
Write-Host "Verifying Solr connection" -ForegroundColor Green
if (-not $SolrUrl.ToLower().StartsWith("https")) {
throw "Solr URL ($SolrUrl) must be secured with https"
}
$SolrRequest = [System.Net.WebRequest]::Create($SolrUrl)
$SolrResponse = $SolrRequest.GetResponse()
try {
If ($SolrResponse.StatusCode -ne 200) {
throw "Could not contact Solr on '$SolrUrl'. Response status was '$SolrResponse.StatusCode'"
}
}
finally {
$SolrResponse.Close()
}
Write-Host "Verifying Solr directory" -ForegroundColor Green
if(-not (Test-Path "$SolrRoot\server")) {
throw "The Solr root path '$SolrRoot' appears invalid. A 'server' folder should be present in this path to be a valid Solr distributive."
}
Write-Host "Verifying Solr service" -ForegroundColor Green
try {
$null = Get-Service $SolrService
} catch {
throw "The Solr service '$SolrService' does not exist. Perhaps it's incorrect in settings.ps1?"
}
#Verify .NET framework
$requiredDotNetFrameworkVersionValue = 394802
$requiredDotNetFrameworkVersion = "4.6.2"
$versionExists = Get-ChildItem "hklm:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" | Get-ItemPropertyValue -Name Release | % { $_ -ge $requiredDotNetFrameworkVersionValue }
if (-not $versionExists) {
throw "Please install .NET Framework $requiredDotNetFrameworkVersion or later"
}
}
function Install-Assets {
#Register Assets PowerShell Repository
if ((Get-PSRepository | Where-Object {$_.Name -eq $AssetsPSRepositoryName}).count -eq 0) {
Register-PSRepository -Name $AssetsPSRepositoryName -SourceLocation $AssetsPSRepository -InstallationPolicy Trusted
}
#Sitecore Install Framework dependencies
Import-Module WebAdministration
#Install SIF
$module = Get-Module -FullyQualifiedName @{ModuleName="SitecoreInstallFramework";ModuleVersion=$InstallerVersion}
if (-not $module) {
write-host "Installing the Sitecore Install Framework, version $InstallerVersion" -ForegroundColor Green
Install-Module SitecoreInstallFramework -RequiredVersion $InstallerVersion -Scope CurrentUser -Repository $AssetsPSRepositoryName
Import-Module SitecoreInstallFramework -RequiredVersion $InstallerVersion
}
#Verify that manual assets are present
if (!(Test-Path $AssetsRoot)) {
throw "$AssetsRoot not found"
}
#Verify license file
if (!(Test-Path $LicenseFile)) {
throw "License file $LicenseFile not found"
}
#Verify Sitecore package
if (!(Test-Path $SitecorePackage)) {
throw "Sitecore package $SitecorePackage not found"
}
#Verify xConnect package
if (!(Test-Path $XConnectPackage)) {
throw "XConnect package $XConnectPackage not found"
}
}
function Install-XConnect {
#Install xConnect Solr
try
{
Install-SitecoreConfiguration $XConnectSolrConfiguration `
-SolrUrl $SolrUrl `
-SolrRoot $SolrRoot `
-SolrService $SolrService `
-CorePrefix $SolutionPrefix
}
catch
{
write-host "XConnect SOLR Failed" -ForegroundColor Red
throw
}
#Generate xConnect client certificate
try
{
Install-SitecoreConfiguration $XConnectCertificateConfiguration `
-CertificateName $XConnectCert `
-CertPath $CertPath
}
catch
{
write-host "XConnect Certificate Creation Failed" -ForegroundColor Red
throw
}
#Install xConnect
try
{
Install-SitecoreConfiguration $XConnectConfiguration `
-Package $XConnectPackage `
-LicenseFile $LicenseFile `
-SiteName $XConnectSiteName `
-XConnectCert $XConnectCert `
-SqlDbPrefix $SolutionPrefix `
-SolrCorePrefix $SolutionPrefix `
-SqlAdminUser $SqlAdminUser `
-SqlAdminPassword $SqlAdminPassword `
-SqlServer $SqlServer `
-SqlCollectionUser $XConnectSqlCollectionUser `
-SqlCollectionPassword $XConnectSqlCollectionPassword `
-SolrUrl $SolrUrl
}
catch
{
write-host "XConnect Setup Failed" -ForegroundColor Red
throw
}
#Set rights on the xDB connection database
Write-Host "Setting Collection User rights" -ForegroundColor Green
try
{
$sqlVariables = "DatabasePrefix = $SolutionPrefix", "UserName = $XConnectSqlCollectionUser", "Password = $XConnectSqlCollectionPassword"
Invoke-Sqlcmd -ServerInstance $SqlServer `
-Username $SqlAdminUser `
-Password $SqlAdminPassword `
-InputFile "$PSScriptRoot\build\database\collectionusergrant.sql" `
-Variable $sqlVariables
}
catch
{
write-host "Set Collection User rights failed" -ForegroundColor Red
throw
}
}
function Install-Sitecore {
try
{
#Install Sitecore Solr
Install-SitecoreConfiguration $SitecoreSolrConfiguration `
-SolrUrl $SolrUrl `
-SolrRoot $SolrRoot `
-SolrService $SolrService `
-CorePrefix $SolutionPrefix
}
catch
{
write-host "Sitecore SOLR Failed" -ForegroundColor Red
throw
}
try
{
#Install Sitecore
Install-SitecoreConfiguration $SitecoreConfiguration `
-Package $SitecorePackage `
-LicenseFile $LicenseFile `
-SiteName $SitecoreSiteName `
-XConnectCert $XConnectCert `
-SqlDbPrefix $SolutionPrefix `
-SolrCorePrefix $SolutionPrefix `
-SqlAdminUser $SqlAdminUser `
-SqlAdminPassword $SqlAdminPassword `
-SqlServer $SqlServer `
-SolrUrl $SolrUrl `
-XConnectCollectionService "https://$XConnectSiteName" `
-XConnectReferenceDataService "https://$XConnectSiteName" `
-MarketingAutomationOperationsService "https://$XConnectSiteName" `
-MarketingAutomationReportingService "https://$XConnectSiteName"
}
catch
{
write-host "Sitecore Setup Failed" -ForegroundColor Red
throw
}
try
{
#Set web certificate on Sitecore site
Install-SitecoreConfiguration $SitecoreSSLConfiguration `
-SiteName $SitecoreSiteName
}
catch
{
write-host "Sitecore SSL Binding Failed" -ForegroundColor Red
throw
}
}
function Add-AppPool-Membership {
#Add ApplicationPoolIdentity to performance log users to avoid Sitecore log errors (https://kb.sitecore.net/articles/404548)
try
{
Add-LocalGroupMember "Performance Log Users" "IIS AppPool\$SitecoreSiteName"
Write-Host "Added IIS AppPool\$SitecoreSiteName to Performance Log Users" -ForegroundColor Green
}
catch
{
Write-Host "Warning: Couldn't add IIS AppPool\$SitecoreSiteName to Performance Log Users -- user may already exist" -ForegroundColor Yellow
}
try
{
Add-LocalGroupMember "Performance Monitor Users" "IIS AppPool\$SitecoreSiteName"
Write-Host "Added IIS AppPool\$SitecoreSiteName to Performance Monitor Users" -ForegroundColor Green
}
catch
{
Write-Host "Warning: Couldn't add IIS AppPool\$SitecoreSiteName to Performance Monitor Users -- user may already exist" -ForegroundColor Yellow
}
}
Install-Prerequisites
Install-Assets
Install-XConnect
Install-Sitecore
Add-AppPool-Membership
# TODO:
# Run optimization scripts
# Deploy-Habitat
# Deploy marketing definitions
# Rebuild indexes
# Rebuild links database
# Test-Setup