-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParTech.SimpleInstallScripts.psm1
174 lines (145 loc) · 6.34 KB
/
ParTech.SimpleInstallScripts.psm1
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
Set-StrictMode -Version 2.0
Function Invoke-EnsureAdmin() {
$elevated = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")
if ($elevated -eq $false)
{
throw "Please run this script as an administrator"
}
}
Function Register-SitecoreGallery() {
Get-PSRepository -Name "SitecoreGallery" -ErrorVariable ev1 -ErrorAction SilentlyContinue | out-null
If ($null -eq $ev1 -or $ev1.count -eq 0)
{
return
}
Write-Host "================= Installing Sitecore PowerShell Gallery =================" -foregroundcolor "green"
Get-PackageProvider -Name Nuget -ForceBootstrap
Register-PSRepository -Name "SitecoreGallery" `
-SourceLocation "https://sitecore.myget.org/F/sc-powershell/api/v2" `
-InstallationPolicy Trusted | Out-Null
Write-Host "PowerShell repository `"SitecoreGallery`" has been registered." -ForegroundColor Green
}
Function Install-SitecoreInstallFramework(
[string] $Version
) {
Register-SitecoreGallery
Write-Host "================= Installing Sitecore Install Framework =================" -foregroundcolor "green"
if (!$Version) {
[array] $sifModules = Find-Module -Name "SitecoreInstallFramework" -Repository "SitecoreGallery"
$latestSIFModule = $sifModules[-1]
$Version = $latestSIFModule.Version.ToString()
}
Install-Module -Name "SitecoreInstallFramework" -Repository "SitecoreGallery" -Force -Scope AllUsers -SkipPublisherCheck -AllowClobber -RequiredVersion $Version
}
Function Enable-ModernSecurityProtocols() {
Write-Host "================= Enabling modern security protocols =================" -foregroundcolor "green"
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
}
Function Install-SifPrerequisites(
[Parameter(Mandatory)] [string] $InstallRoot
) {
Write-Host "================= Installing SIF Prerequisites =================" -foregroundcolor "green"
$config = Resolve-Path "$InstallRoot\Prerequisites.json"
Install-SitecoreConfiguration $config
}
Function Install-Solr(
[Parameter(Mandatory)] [string] $SolrVersion,
[Parameter(Mandatory)] [string] $SolrHost,
[Parameter(Mandatory)] [string] $SolrPort
) {
Write-Host "================= Installing Solr Server =================" -foregroundcolor "green"
Try {
Push-Location $PSScriptRoot
$config = Resolve-Path "$PSScriptRoot\Solr-SingleDeveloper.json"
Install-SitecoreConfiguration $config `
-SolrVersion $SolrVersion `
-SolrDomain $SolrHost `
-SolrPort $SolrPort
} Finally {
Pop-Location
}
}
Function Install-AllPrerequisites(
[Parameter(Mandatory)] [string] $InstallRoot,
[Parameter(Mandatory)] [string] $DownloadBase,
[Parameter(Mandatory)] [string] $SolrVersion,
[Parameter(Mandatory)] [string] $SolrHost,
[Parameter(Mandatory)] [string] $SolrPort,
[Parameter(Mandatory)] [string] $SqlServer,
[Parameter(Mandatory)] [string] $SqlAdminUser,
[Parameter(Mandatory)] [string] $SqlAdminPassword,
[string] $SifVersion
) {
$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
Write-Host "================= Installing All Prerequisites =================" -foregroundcolor "green"
Invoke-EnsureAdmin
Install-SitecoreInstallFramework -Version $SifVersion
Install-SifPrerequisites -InstallRoot $InstallRoot
Invoke-CommandWithEffectiveParameters "Install-Solr" $PSBoundParameters
Invoke-CommandWithEffectiveParameters "Enable-ContainedDatabaseAuthentication" $PSBoundParameters
Write-Host "Successfully setup environment (time: $($elapsed.Elapsed.ToString()))"
}
Function Invoke-DownloadPackages (
[Parameter(Mandatory)] [string] $DownloadBase,
[Parameter(Mandatory)] [string] $InstallRoot,
[Parameter(Mandatory)] [string] $WdpsZipName,
[Parameter(Mandatory)] [string] $ConfigsZipName
) {
Write-Host "================= Downloading packages =================" -foregroundcolor "green"
New-Item -ItemType Directory -Force -Path $InstallRoot
$WdpsUrl = "$DownloadBase/$WdpsZipName"
$WdpsZip = "$InstallRoot\$WdpsZipName"
Invoke-DownloadIfNeeded $WdpsUrl $WdpsZip
Expand-Archive $WdpsZip -DestinationPath $InstallRoot -Force
$ConfigFilesZip = "$InstallRoot\$ConfigsZipName"
Expand-Archive $ConfigFilesZip -DestinationPath $InstallRoot -Force
Invoke-DownloadIfNeeded "$DownloadBase/license.xml" "$InstallRoot\license.xml"
}
Function Enable-ContainedDatabaseAuthentication
(
[Parameter(Mandatory)] [string] $SqlServer, # The DNS name or IP of the SQL Instance.
[Parameter(Mandatory)] [string] $SqlAdminUser, # A SQL user with sysadmin privileges.
[Parameter(Mandatory)] [string] $SqlAdminPassword # The password for $SQLAdminUser.
)
{
Write-Host "================= Enabling Contained Database Authentication =================" -foregroundcolor "green"
sqlcmd -S $SqlServer -U $SqlAdminUser -P $SqlAdminPassword -h-1 -Q "sp_configure 'contained database authentication', 1; RECONFIGURE;"
}
Function Invoke-DownloadIfNeeded
(
[Parameter(Mandatory)] [string] $source,
[Parameter(Mandatory)] [string] $target
)
{
Write-Host "Invoke-DownloadIfNeeded to $target"
if (Test-Path $target) {
Write-Debug "Already exists"
return
}
$client = (New-Object System.Net.WebClient)
$client.DownloadFile($source, $target)
}
Function ConvertTo-Hashtable {
[CmdletBinding()]
[OutputType('hashtable')]
param (
[Parameter(ValueFromPipeline)]
$InputObject
)
process {
$hash = [ordered]@{}
foreach ($property in $InputObject.PSObject.Properties) {
$hash[$property.Name] = $property.Value
}
Return $hash
}
}
Function Get-DefaultSitecoreParameters
{
param([parameter(Mandatory)] [string] $SitecoreVersion)
$DefaultsPath = "$PSScriptRoot\Defaults\$($SitecoreVersion).json"
If (!(Test-Path($DefaultsPath))) {
throw "Defaults not found: $DefaultsPath"
}
Return Get-Content -Raw -Path $DefaultsPath | ConvertFrom-Json | ConvertTo-Hashtable
}