-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-setup-dev.ps1
400 lines (326 loc) · 24.5 KB
/
app-setup-dev.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
########################################################################
### BOOTSTRAP. Copy this section into each application setup script ###
### to make sure required functions are available. ###
########################################################################
$pathOfThisScript = Split-Path $MyInvocation.MyCommand.Path -Parent
$parentFolderOfThisScript = $pathOfThisScript | Split-Path -Parent
$scriptsProject = 'Escc.WebApplicationSetupScripts'
$functionsPath = "$pathOfThisScript\..\$scriptsProject\functions.ps1"
if (Test-Path $functionsPath) {
Write-Host "Checking $scriptsProject is up-to-date"
Push-Location "$pathOfThisScript\..\$scriptsProject"
git pull origin master
Pop-Location
Write-Host
.$functionsPath
} else {
if ($env:GIT_ORIGIN_URL) {
$repoUrl = $env:GIT_ORIGIN_URL -f $scriptsProject
git clone $repoUrl "$pathOfThisScript\..\$scriptsProject"
}
else
{
Write-Warning '$scriptsProject project not found. Please set a GIT_ORIGIN_URL environment variable on your system so that it can be downloaded.
Example: C:\>set GIT_ORIGIN_URL=https://example-git-server.com/{0}"
{0} will be replaced with the name of the repository to download.'
Exit
}
}
########################################################################
### END BOOTSTRAP. #####################################################
########################################################################
### 1. Setup website project ###
$projectName = "Escc.EastSussexGovUK.Umbraco.Web"
EnableDotNet40InIIS
CreateApplicationPool $projectName
CreateWebsite $projectName "$pathOfThisScript\$projectName"
CreateHTTPSBinding $projectName
RemoveHTTPBinding $projectName 80
# Give application pool account write access so that it can write temporary files
Write-Host "Granting Modify access to the application pool account"
$acl = Get-Acl "$pathOfThisScript\$projectName"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS AppPool\$projectName", "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule)
Set-Acl "$pathOfThisScript\$projectName" $acl
# Run NuGet restore on this project so that packages are available to copy files from
if (Get-Command "nuget.exe" -ErrorAction SilentlyContinue)
{
Write-Host "Restoring NuGet packages for $pathOfThisScript\$projectName"
& nuget restore "$pathOfThisScript\$projectName\packages.config" -PackagesDirectory "$pathOfThisScript\packages"
} else {
Write-Warning "Unable to restore NuGet packages because nuget.exe was not found in your path. If you get build errors, add nuget.exe to your path and run this script again."
}
# Get the installed versions of Umbraco and relevant packages
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\packages.config")
$umbracoVersion = $xml.SelectSingleNode("/packages/package[@id='UmbracoCms']").GetAttribute("version");
Write-Host "UmbracoCms $umbracoVersion detected"
$modelsBuilderVersion = $xml.SelectSingleNode("/packages/package[@id='Umbraco.ModelsBuilder']").GetAttribute("version");
Write-Host "Umbraco.ModelsBuilder $modelsBuilderVersion detected"
$formsVersion = $xml.SelectSingleNode("/packages/package[@id='UmbracoForms']").GetAttribute("version");
Write-Host "UmbracoForms $formsVersion detected"
$securityConfigVersion = $xml.SelectSingleNode("/packages/package[@id='Escc.Web.SecurityConfig']").GetAttribute("version");
Write-Host "Escc.Web.SecurityConfig $securityConfigVersion detected"
$egukSecurityConfigVersion = $xml.SelectSingleNode("/packages/package[@id='Escc.EastSussexGovUK.SecurityConfig']").GetAttribute("version");
Write-Host "Escc.EastSussexGovUK.SecurityConfig $egukSecurityConfigVersion detected"
$egukClientDependencyVersion = $xml.SelectSingleNode("/packages/package[@id='Escc.EastSussexGovUK.ClientDependency']").GetAttribute("version");
Write-Host "Escc.EastSussexGovUK.ClientDependency $egukClientDependencyVersion detected"
$propertyEditorsVersion = $xml.SelectSingleNode("/packages/package[@id='Escc.Umbraco.PropertyEditors']").GetAttribute("version");
Write-Host "Escc.Umbraco.PropertyEditors $propertyEditorsVersion detected"
$imageProcessorConfigVersion = $xml.SelectSingleNode("/packages/package[@id='ImageProcessor.Web.Config']").GetAttribute("version");
Write-Host "ImageProcessor.Web.Config $securityConfigVersion detected"
$uSyncCoreVersion = $xml.SelectSingleNode("/packages/package[@id='uSync.Core']").GetAttribute("version");
Write-Host "uSync.Core $uSyncCoreVersion detected"
$uSyncVersion = $xml.SelectSingleNode("/packages/package[@id='uSync']").GetAttribute("version");
Write-Host "uSync $uSyncVersion detected"
$uSyncSnapshotsVersion = $xml.SelectSingleNode("/packages/package[@id='uSync.Snapshots']").GetAttribute("version");
Write-Host "uSync.Snapshots $uSyncSnapshotsVersion detected"
# Copy files from the Umbraco package if missing
& robocopy "packages\UmbracoCms.$umbracoVersion\Content\" "$pathOfThisScript\$projectName\" /E /XC /XN /XO /XF *.transform *.xdt
CopyConfig "packages\UmbracoCms.$umbracoVersion\UmbracoFiles\web.config" "$projectName\web.config"
CopyConfig "packages\UmbracoCms.$umbracoVersion\Content\Views\web.config.transform" "$projectName\Views\web.config"
& robocopy "packages\Umbraco.ModelsBuilder.$modelsBuilderVersion\Content\App_Plugins\" "$pathOfThisScript\$projectName\App_Plugins\" /E /XC /XN /XO
& robocopy "packages\UmbracoForms.$formsVersion\content\App_Plugins\" "$pathOfThisScript\$projectName\App_Plugins\" /E /XC /XN /XO /XF *.xdt
& robocopy "packages\UmbracoForms.$formsVersion\content\Views\" "$pathOfThisScript\$projectName\Views\" /E /XC /XN /XO /XF *.xdt
# Transform the web.config with the XDT for the project
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config.xdt"
# If a debug-only transform for web.config is found, apply it
if (Test-Path "$pathOfThisScript\$projectName\Web.Debug.config")
{
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\Web.Debug.config"
}
# Apply security headers and content security policy to project
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\packages\Escc.Web.SecurityConfig.$securityConfigVersion\Content\web.config.install.xdt"
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\packages\Escc.EastSussexGovUK.SecurityConfig.$egukSecurityConfigVersion\Content\web.config.install.xdt"
# Update web.config with settings only appropriate for development
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\web.config")
# Remove the removeServerHeader attribute inserted by Escc.Web.SecurityConfig, which will cause the site to fail to load under IIS < 10 (likely in development)
$requestFilteringElement = $xml.SelectSingleNode("/configuration/system.webServer/security/requestFiltering")
$requestFilteringElement.RemoveAttribute("removeServerHeader")
# Remove the umbracoConfigurationStatus so that the Umbraco installer is triggered. If umbracoConfigurationStatus is set but umbracoDbDSN is not, you just get a login that doesn't work.
$umbracoDbDSNElement = $xml.SelectSingleNode("/configuration/connectionStrings/add[@name='umbracoDbDSN']")
$umbracoDbDSN = $umbracoDbDSNElement.GetAttribute("connectionString")
if (!$umbracoDbDSN) {
$xml.SelectSingleNode("/configuration/appSettings/add[@key='umbracoConfigurationStatus']").SetAttribute("value", "")
}
# Reset fcnMode to Single which is the recommended value for Umbraco. We use the Disabled setting on Azure to avoid application restarts, but in development you want it to restart when you modify files.
$xml.SelectSingleNode("/configuration/system.web/httpRuntime").SetAttribute("fcnMode", "Single")
# Set debug=true and disable custom errors and caching for development
$xml.SelectSingleNode("/configuration/system.web/compilation").SetAttribute("debug", "true")
$xml.SelectSingleNode("/configuration/system.web/customErrors").SetAttribute("mode", "Off")
$xml.SelectSingleNode("/configuration/system.webServer/httpErrors").SetAttribute("errorMode", "Detailed")
$xml.SelectSingleNode("/configuration/Escc.Umbraco/GeneralSettings/add[@key='HttpCachingEnabled']").SetAttribute("value", "false")
# Always set IsUmbracoBackOffice as development is unlikely to be load-balanced, but this ensures RegisterServerRoleEventHandler sets the web project as master and the API project as slave
if (!$xml.SelectSingleNode("/configuration/appSettings/add[@key='IsUmbracoBackOffice']"))
{
$isUmbracoBackOfficeElement = $xml.CreateElement("add")
$isUmbracoBackOfficeElement.SetAttribute("key", "IsUmbracoBackOffice")
$isUmbracoBackOfficeElement.SetAttribute("value", "true")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($isUmbracoBackOfficeElement)
}
# Set ApiUser and ApiKey to simple values for development. These are used by Escc.BasicAuthentication.WebApi when connecting to some custom Umbraco web apis.
if (!$xml.SelectSingleNode("/configuration/appSettings/add[@key='ApiUser']"))
{
$apiUserElement = $xml.CreateElement("add")
$apiUserElement.SetAttribute("key", "ApiUser")
$apiUserElement.SetAttribute("value", "dev")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiUserElement)
}
if (!$xml.SelectSingleNode("/configuration/appSettings/add[@key='ApiKey']"))
{
$apiUserElement = $xml.CreateElement("add")
$apiUserElement.SetAttribute("key", "ApiKey")
$apiUserElement.SetAttribute("value", "dev")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiUserElement)
}
$xml.Save("$pathOfThisScript\$projectName\web.temp.config")
copy "$pathOfThisScript\$projectName\web.temp.config" "$pathOfThisScript\$projectName\web.config"
del "$pathOfThisScript\$projectName\web.temp.config"
# Configure sitewide CSS and JS files for project
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\packages\Escc.EastSussexGovUK.ClientDependency.$egukClientDependencyVersion\Content\web.config.install.xdt"
# Copy files into /config if not already present
& robocopy "packages\UmbracoCms.$umbracoVersion\Content\Config" "$pathOfThisScript\$projectName\config" /E /XC /XN /XO /XF *.xdt
if ((Test-Path "$pathOfThisScript\$projectName\config\imageprocessor\cache.config") -eq 0)
{
& robocopy "packages\ImageProcessor.Web.Config.$imageProcessorConfigVersion\content\config\imageprocessor" "$pathOfThisScript\$projectName\config\imageprocessor" /E /XC /XN /XO
Get-ChildItem "$pathOfThisScript\$projectName\config\imageprocessor\*.config.transform" | Rename-Item -NewName { $_.Name.Replace('.config.transform','.config') }
}
TransformConfig "$pathOfThisScript\$projectName\config\imageprocessor\cache.config" "$pathOfThisScript\$projectName\config\imageprocessor\cache.config" "$pathOfThisScript\packages\UmbracoCms.$umbracoVersion\Content\Config\imageprocessor\cache.config.install.xdt"
TransformConfig "$pathOfThisScript\$projectName\config\imageprocessor\processing.config" "$pathOfThisScript\$projectName\config\imageprocessor\processing.config" "$pathOfThisScript\packages\UmbracoCms.$umbracoVersion\Content\Config\imageprocessor\processing.config.install.xdt"
CopyConfig "packages\uSync.Core.$uSyncCoreVersion\content\config\uSyncCore.Config" "$pathOfThisScript\$projectName\config\uSyncCore.Config"
& robocopy "packages\uSync.$uSyncVersion\content\" "$pathOfThisScript\$projectName\" /E /XC /XN /XO /XF *.xdt
& robocopy "packages\uSync.Snapshots.$uSyncSnapshotsVersion\content\" "$pathOfThisScript\$projectName\" /E /XC /XN /XO
TransformConfig "$pathOfThisScript\$projectName\config\dashboard.config" "$pathOfThisScript\$projectName\config\dashboard.config" "$pathOfThisScript\packages\uSync.$uSyncVersion\content\config\dashboard.config.install.xdt"
# Configure custom Examine indexes
TransformConfig "$pathOfThisScript\$projectName\config\ExamineIndex.config" "$pathOfThisScript\$projectName\config\ExamineIndex.config" "$pathOfThisScript\$projectName\RightsOfWayDeposits\ExamineIndex.config.xdt"
TransformConfig "$pathOfThisScript\$projectName\config\ExamineSettings.config" "$pathOfThisScript\$projectName\config\ExamineSettings.config" "$pathOfThisScript\$projectName\RightsOfWayDeposits\ExamineSettings.config.xdt"
TransformConfig "$pathOfThisScript\$projectName\config\ExamineIndex.config" "$pathOfThisScript\$projectName\config\ExamineIndex.config" "$pathOfThisScript\$projectName\RightsOfWayModifications\ExamineIndex.config.xdt"
TransformConfig "$pathOfThisScript\$projectName\config\ExamineSettings.config" "$pathOfThisScript\$projectName\config\ExamineSettings.config" "$pathOfThisScript\$projectName\RightsOfWayModifications\ExamineSettings.config.xdt"
# Configure file types which can be uploaded - use a whitelist rather than blacklist as it's more secure, and remove .xml from the blacklist to allow school term dates to be uploaded
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\config\umbracoSettings.config")
$contentElement = $xml.SelectSingleNode("/settings/content")
$contentElement.SelectSingleNode("disallowedUploadFiles")."#text" = "ashx,aspx,ascx,config,cshtml,vbhtml,asmx,air,axd,swf,html,htm,php,htaccess"
$allowedUploads = $contentElement.SelectSingleNode("allowedUploadFiles")
if (!$allowedUploads) {
$allowedUploads = $xml.CreateElement("allowedUploadFiles")
$allowedUploads.AppendChild($xml.CreateTextNode("csv,doc,docx,gif,jpg,pdf,png,ppsx,ppt,pptx,rtf,svg,xls,xlsm,xlsx,xml"))
$contentElement.AppendChild($allowedUploads)
}
$xml.Save("$pathOfThisScript\$projectName\config\umbracoSettings.temp.config")
copy "$pathOfThisScript\$projectName\config\umbracoSettings.temp.config" "$pathOfThisScript\$projectName\config\umbracoSettings.config"
del "$pathOfThisScript\$projectName\config\umbracoSettings.temp.config"
# Configure TinyMCE editor, including adding the blockquote button used only by 'Standard topic page'
TransformConfig "$pathOfThisScript\$projectName\config\tinyMceConfig.config" "$pathOfThisScript\$projectName\config\tinyMceConfig.config" "$pathOfThisScript\packages\Escc.Umbraco.PropertyEditors.$propertyEditorsVersion\Content\config\tinymceconfig.config.install.xdt"
# Create an /img virtual directory to load template elements from the tightly-coupled Escc.EastSussexGovUK.TemplateSource project
CheckApplicationExists "$pathOfThisScript\.." "Escc.EastSussexGovUK"
if (Test-Path "IIS:\Sites\$projectName\img")
{
Write-Host "Virtual directory img already exists"
}
else
{
Write-Host "Creating virtual directory img"
New-WebVirtualDirectory -Site $projectName -Name "img" -PhysicalPath "$pathOfThisScript\..\Escc.EastSussexGovUK\Escc.EastSussexGovUK.TemplateSource\img"
}
CopyConfig "$pathOfThisScript\$projectName\images\web.example.config" "$pathOfThisScript\$projectName\images\web.config"
### 2. Setup API project ###
$projectName = "Escc.EastSussexGovUK.Umbraco.Api"
CreateApplicationPool $projectName
CreateWebsite $projectName "$pathOfThisScript\$projectName"
CreateHTTPSBinding $projectName
RemoveHTTPBinding $projectName 80
# Give application pool account write access so that it can write temporary files
Write-Host "Granting Modify access to the application pool account"
$acl = Get-Acl "$pathOfThisScript\$projectName"
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("IIS AppPool\$projectName", "Modify", "ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($rule)
Set-Acl "$pathOfThisScript\$projectName" $acl
# Run NuGet restore on this project so that packages are available to copy files from
if (Get-Command "nuget.exe" -ErrorAction SilentlyContinue)
{
Write-Host "Restoring NuGet packages for $pathOfThisScript\$projectName"
& nuget restore "$pathOfThisScript\$projectName\packages.config" -PackagesDirectory "$pathOfThisScript\packages"
} else {
Write-Warning "Unable to restore NuGet packages because nuget.exe was not found in your path. If you get build errors, add nuget.exe to your path and run this script again."
}
# Get the installed Umbraco version
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\packages.config")
$umbracoVersion = $xml.SelectSingleNode("/packages/package[@id='UmbracoCms']").GetAttribute("version");
Write-Host "UmbracoCms $umbracoVersion detected"
$modelsBuilderVersion = $xml.SelectSingleNode("/packages/package[@id='Umbraco.ModelsBuilder']").GetAttribute("version");
Write-Host "Umbraco.ModelsBuilder $modelsBuilderVersion detected"
# Copy files from the Umbraco package if missing
& robocopy "packages\UmbracoCms.$umbracoVersion\Content\" "$pathOfThisScript\$projectName\" /E /XC /XN /XO /XF *.transform *.xdt
CopyConfig "packages\UmbracoCms.$umbracoVersion\UmbracoFiles\web.config" "$projectName\web.config"
CopyConfig "packages\UmbracoCms.$umbracoVersion\Content\Views\web.config.transform" "$projectName\Views\web.config"
& robocopy "packages\Umbraco.ModelsBuilder.$modelsBuilderVersion\Content\App_Plugins\" "$pathOfThisScript\$projectName\App_Plugins\" /E /XC /XN /XO
# Transform the web.config with the XDT for the project
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config.xdt"
# If a debug-only transform for web.config is found, apply it
if (Test-Path "$pathOfThisScript\$projectName\Web.Debug.config")
{
TransformConfig "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\web.config" "$pathOfThisScript\$projectName\Web.Debug.config"
}
# Update web.config with settings only appropriate for development
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\web.config")
# Remove the removeServerHeader attribute inserted by web.config.xdt, which will cause the site to fail to load under IIS < 10 (likely in development)
$requestFilteringElement = $xml.SelectSingleNode("/configuration/system.webServer/security/requestFiltering")
$requestFilteringElement.RemoveAttribute("removeServerHeader")
# Reset fcnMode to Single which is the recommended value for Umbraco. We use the Disabled setting on Azure to avoid application restarts, but in development you want it to restart when you modify files.
$xml.SelectSingleNode("/configuration/system.web/httpRuntime").SetAttribute("fcnMode", "Single")
# Set debug=true and disable custom errors for development
$xml.SelectSingleNode("/configuration/system.web/compilation").SetAttribute("debug", "true")
$xml.SelectSingleNode("/configuration/system.web/customErrors").SetAttribute("mode", "Off")
$xml.SelectSingleNode("/configuration/system.webServer/httpErrors").SetAttribute("errorMode", "Detailed")
# Set ApiUser and ApiKey to simple values for development. These are used by Escc.BasicAuthentication.WebApi when connecting to some custom Umbraco web apis.
if (!$xml.SelectSingleNode("/configuration/appSettings/add[@key='ApiUser']"))
{
$apiUserElement = $xml.CreateElement("add")
$apiUserElement.SetAttribute("key", "ApiUser")
$apiUserElement.SetAttribute("value", "dev")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiUserElement)
}
if (!$xml.SelectSingleNode("/configuration/appSettings/add[@key='ApiKey']"))
{
$apiUserElement = $xml.CreateElement("add")
$apiUserElement.SetAttribute("key", "ApiKey")
$apiUserElement.SetAttribute("value", "dev")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiUserElement)
}
# Leave media links in job adverts as absolute URLs, because they'll point at media on the live site but this application will point at a development account for media
if (!$xml.SelectSingleNode("/configuration/appSettings/add[@key='DoNotRemoveMediaDomainInJobAdverts']"))
{
$apiUserElement = $xml.CreateElement("add")
$apiUserElement.SetAttribute("key", "DoNotRemoveMediaDomainInJobAdverts")
$apiUserElement.SetAttribute("value", "true")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiUserElement)
}
$xml.Save("$pathOfThisScript\$projectName\web.temp.config")
copy "$pathOfThisScript\$projectName\web.temp.config" "$pathOfThisScript\$projectName\web.config"
del "$pathOfThisScript\$projectName\web.temp.config"
# Copy files into /config if not already present
& robocopy "packages\UmbracoCms.$umbracoVersion\Content\Config" "$pathOfThisScript\$projectName\config" /E /XC /XN /XO /XF *.xdt
if ((Test-Path "$pathOfThisScript\$projectName\config\imageprocessor\cache.config") -eq 0)
{
& robocopy "packages\ImageProcessor.Web.Config.$imageProcessorConfigVersion\content\config\imageprocessor" "$pathOfThisScript\$projectName\config\imageprocessor" /E /XC /XN /XO
Get-ChildItem "$pathOfThisScript\$projectName\config\imageprocessor\*.config.transform" | Rename-Item -NewName { $_.Name.Replace('.config.transform','.config') }
}
TransformConfig "$pathOfThisScript\$projectName\config\imageprocessor\cache.config" "$pathOfThisScript\$projectName\config\imageprocessor\cache.config" "$pathOfThisScript\packages\UmbracoCms.$umbracoVersion\Content\Config\imageprocessor\cache.config.install.xdt"
TransformConfig "$pathOfThisScript\$projectName\config\imageprocessor\processing.config" "$pathOfThisScript\$projectName\config\imageprocessor\processing.config" "$pathOfThisScript\packages\UmbracoCms.$umbracoVersion\Content\Config\imageprocessor\processing.config.install.xdt"
# Configure custom Examine indexes
TransformConfig "$pathOfThisScript\$projectName\config\ExamineIndex.config" "$pathOfThisScript\$projectName\config\ExamineIndex.config" "$pathOfThisScript\$projectName\Jobs\Examine\ExamineIndex.config.xdt"
TransformConfig "$pathOfThisScript\$projectName\config\ExamineSettings.config" "$pathOfThisScript\$projectName\config\ExamineSettings.config" "$pathOfThisScript\$projectName\Jobs\Examine\ExamineSettings.config.xdt"
### 3. Connect web application to API ###
$projectName = "Escc.EastSussexGovUK.Umbraco.Web"
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\web.config")
$apiBaseUrlElement = $xml.SelectSingleNode("/configuration/appSettings/add[@key='JobsApiBaseUrl']")
if (!$apiBaseUrlElement)
{
Write-Host Connecting web application to API
$apiPort = @(Get-WebBinding -Name "Escc.EastSussexGovUK.Umbraco.Api" -Protocol https)[0].BindingInformation -replace "[^0-9]", ""
$apiBaseUrlElement = $xml.CreateElement("add")
$apiBaseUrlElement.SetAttribute("key", "JobsApiBaseUrl")
$apiBaseUrlElement.SetAttribute("value", "https://localhost:$apiPort")
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiBaseUrlElement)
$xml.Save("$pathOfThisScript\$projectName\web.temp.config")
copy "$pathOfThisScript\$projectName\web.temp.config" "$pathOfThisScript\$projectName\web.config"
del "$pathOfThisScript\$projectName\web.temp.config"
}
$apiBaseUrl = $apiBaseUrlElement.GetAttribute("value")
### 4. Setup console apps ###
$projectName = "Escc.Jobs.SendAlerts"
CopyConfig "$projectName\app.example.config" "$projectName\app.config"
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\app.config")
$xml.SelectSingleNode("/configuration/appSettings/add[@key='JobsApiBaseUrl']").SetAttribute("value", $apiBaseUrl)
$xml.SelectSingleNode("/configuration/appSettings/add[@key='Frequency']").SetAttribute("value", "1")
$xml.SelectSingleNode("/configuration/appSettings/add[@key='Precondition']").SetAttribute("value", "")
$xml.Save("$pathOfThisScript\$projectName\app.temp.config")
copy "$pathOfThisScript\$projectName\app.temp.config" "$pathOfThisScript\$projectName\app.config"
del "$pathOfThisScript\$projectName\app.temp.config"
$projectName = "Escc.Jobs.UpdateIndexes"
CopyConfig "$projectName\app.example.config" "$projectName\app.config"
$xml = [xml](Get-Content "$pathOfThisScript\$projectName\app.config")
$xml.SelectSingleNode("/configuration/appSettings/add[@key='HostnameEnvironmentVariable']").SetAttribute("value", "")
$xml.SelectSingleNode("/configuration/appSettings/add[@key='ApiUser']").SetAttribute("value", "dev")
$xml.SelectSingleNode("/configuration/appSettings/add[@key='ApiPassword']").SetAttribute("value", "dev")
$apiBaseUrlElement = $xml.SelectSingleNode("/configuration/appSettings/add[@key='JobsApiBaseUrl']")
if (!$apiBaseUrlElement)
{
Write-Host Connecting Escc.Jobs.UpdateIndexes to API
$apiBaseUrlElement = $xml.CreateElement("add")
$apiBaseUrlElement.SetAttribute("key", "JobsApiBaseUrl")
$apiBaseUrlElement.SetAttribute("value", $apiBaseUrl)
$appSettings = $xml.SelectSingleNode("/configuration/appSettings")
$appSettings.AppendChild($apiBaseUrlElement)
}
$xml.Save("$pathOfThisScript\$projectName\app.temp.config")
copy "$pathOfThisScript\$projectName\app.temp.config" "$pathOfThisScript\$projectName\app.config"
del "$pathOfThisScript\$projectName\app.temp.config"
Write-Host
Write-Host "Done." -ForegroundColor "Green"