forked from alessandronivuori/ServerConfigurator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ps1
255 lines (221 loc) · 6.71 KB
/
install.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
<#
.SYNOPSIS
Enable/disable Sitecore configuration files
.DESCRIPTION
Enable/disables Sitecore configuration files depending on the role desired for the instance
.PARAMETER path
The path to the Sitecore instance (Website folder)
.PARAMETER serverType
The role the Sitecore instance should have. Must be one of "ContentDelivery", "ContentManagement", "Processing", "CMProcessing" or "Reporting"
.PARAMETER solr
Use Solr as search provider, instead of Lucene
.PARAMETER version
Use the Sitecore version specified. See available version xml files to know which versions are available. Use just the name of the file with no extension as name for the version.
.PARAMETER check
Check that the configuration on the instance matches the desired role
.PARAMETER ignoreWebsitePrefix
Don't use the website folder in the path, as specified in the Sitecore excel. Use this is your Website root has some other name and you are already including it in the path parameter.
.EXAMPLE
C:\PS> install.ps1 -path C:\inetpub\wwwroot\Sitecore -serverType CMProcessing -solr 0 -check 0 -version 8.2-rev-161221
.NOTES
Author: Alessandro Nivuori
Contributor: Diego Saavedra San Juan
Date: Many
#>
# Specify a path to the .config file if you do not wish to put the .config file in the same directory as the script
param(
[Parameter(Mandatory=$true)]
[string]$path, # The path to the Sitecore instance
[Parameter(Mandatory=$true)]
[string]$serverType, # The role for the Sitecore instance. Must be one of "ContentDelivery", "ContentManagement", "Processing", "CMProcessing" or "Reporting"
[Parameter(Mandatory=$true)]
[string]$version,
[Parameter(Mandatory=$false)]
[string]$searchProviderUsed="lucene", # Specify search provider to use. One of: Lucene, Solr or Azure
[Parameter(Mandatory=$false)]
[bool]$check=$false, # Check that the instance configuration matches the role desired
[Parameter(Mandatory=$false)]
[bool]$ignoreWebsitePrefix=$false # Don't use the website folder in the path, as specified in the Sitecore excel. Use this is your Website root has some other name and you are already including it in the path parameter.
)
[string]$configPath
$scriptDir = Split-Path (Resolve-Path $myInvocation.MyCommand.Path)
$configSettings = $null
# Assume there is no host console available until we can read the config file.
$hostScreenAvailable = $FALSE
$searchProvidersStrings = "Lucene is used", "Solr is used", "Azure is used"
function Read-InstallConfigFile([string]$configPath)
{
if ([string]::IsNullOrEmpty($configPath))
{
[xml]$configXml = Get-Content ($scriptDir + "\" + $version + ".xml")
}
else
{
if (Test-Path $configPath)
{
[xml]$configXml = Get-Content ($configPath)
}
else
{
Write-Host "Could not find configuration file at specified path: $configPath"
}
}
return $configXml
}
function Disable-File([string]$file)
{
$filename = Find-File $file
if ($filename)
{
$extension = [System.IO.Path]::GetExtension($filename)
if ($extension.equals(".config"))
{
if (![bool]($check))
{
Write-Host "Disabling Config File:"$filename
Rename-Item $filename ($filename+".disabled")
}
else
{
Write-Host "Config File:"$filename" should be disabled" -ForegroundColor "Red"
}
}
if ($extension.equals(".disabled"))
{
Write-Host "ALREADY DISABLED:"$filename -ForegroundColor "Green"
}
}
else
{
Write-Host "File NOT FOUND:"$file
}
}
function Enable-File([string]$file)
{
$filename = Find-File $file
if ($filename)
{
$extension = [System.IO.Path]::GetExtension($filename)
if ($extension.equals(".config"))
{
Write-Host "ALREADY ENABLED:"$filename -ForegroundColor "Green"
}
if ($extension.equals(".disabled"))
{
if (![bool]($check))
{
Write-Host "Enabling Disabled File:"$file
$enabledFile = $file -replace ".disabled$", ""
Rename-Item $filename $enabledFile
}
else
{
Write-Host "Config File:"$filename" should be enabled" -ForegroundColor "Red"
}
}
if ($extension.equals(".example"))
{
if (![bool]($check))
{
Write-Host "Enabling Example File:"$file
$enabledFile = $file -replace ".example$", ""
Rename-Item $filename $enabledFile
}
else
{
Write-Host "Config File:"$filename" should be enabled" -ForegroundColor "Red"
}
}
}
else
{
Write-Host "Config File:"$file" should be enabled but is NOT FOUND" -ForegroundColor "Red"
}
}
function Find-File([string]$file)
{
if (Test-Path $file)
{
return $file
}
$disabledFile = $file +".disabled"
if (Test-Path $disabledFile)
{
return $disabledFile
}
$enabledFile = $file -replace ".disabled$", ""
if (Test-Path $enabledFile)
{
return $enabledFile
}
$exampleFile = $file -replace ".example$", ""
if (Test-Path $exampleFile)
{
return $exampleFile
}
return ""
}
function Set-Config-File([string]$file)
{
if ($serverConfig.equals("Enable"))
{
Enable-File $file
}
if ($serverConfig.equals("Disable"))
{
Disable-File $file
}
}
function Set-Config-File-Using-SearchProvider([string]$file, [string]$searchProviderUsed)
{
if ($config.SearchProviderUsed.equals($searchProviderUsed))
{
Set-Config-File $file
}
if (!$config.SearchProviderUsed.equals($searchProviderUsed))
{
Disable-File $file
}
}
function Configure-Server([string]$path, $serverType)
{
[xml]$configXml = Read-InstallConfigFile $configPath
if ( $configXml -eq $null -or $configXml.HasChildNodes -eq $false )
{
Write-Host 'No configuration file found or empty, quitting'
exit 1
}
foreach($config in $configXml.Root.Config)
{
if ( $ignoreWebsitePrefix -eq $true )
{
$config.FilePath = $config.FilePath -replace "\\website", ""
}
$file = $path+"\"+$config.FilePath+"\"+$config.ConfigFileName
$serverConfig = ($config | Select -ExpandProperty $serverType)
if ([bool]($config.SearchProviderUsed) -and ( -not $config.SearchProviderUsed.equals("Base")))
{
if ($searchProviderUsed.ToLower() -match "solr")
{
Set-Config-File-Using-SearchProvider $file $searchProvidersStrings[1]
}
elseif ($searchProviderUsed.ToLower() -match "lucene")
{
Set-Config-File-Using-SearchProvider $file $searchProvidersStrings[0]
}
elseif ($searchProviderUsed.ToLower() -match "azure")
{
Set-Config-File-Using-SearchProvider $file $searchProvidersStrings[2]
}
else
{
Write-Error "Wrong search provider parameter: $searchProviderUsed"
}
}
else
{
Set-Config-File $file
}
}
}
Configure-Server $path $serverType [bool]$solr [bool]$check