Sitecore.Automation.Framework.psm1
Import-Module "$PSScriptRoot\Common\Initialization-Module.psm1" -Force Import-Module "$PSScriptRoot\Common\Utils-Module.psm1" -Force $ErrorActionPreference = "Stop" Set-ExecutionPolicy Bypass -Scope Process -Force function SetGlobals { [CmdletBinding()] Param ( [bool]$Offline, [bool]$AutoConfirm, [string]$RunningCommand ) $global:Configuration = $null $global:Offline = $Offline $global:AutoConfirm = $AutoConfirm $global:RunningCommand = $RunningCommand $dir = Get-Location $global:RunningDirectory = $dir $global:Pipelines = Get-Content -Raw -Path "$PSScriptRoot\common\Pipelines.json" | ConvertFrom-Json } function LoadCofiguration { [CmdletBinding()] Param ( [string]$Config ) if (!(Test-Path $Config)) { throw "Please, provide Configuration JSON file." } $global:Configuration = (Get-Content -Raw -Path $Config) -replace '//.*' | Out-String | ConvertFrom-Json Split-Path $Config | Set-Location } function EnsureRunAsAdmin { ## Verify elevated ## https://superuser.com/questions/749243/detect-if-powershell-is-running-as-administrator $elevated = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544") if ($elevated -eq $false) { throw "In order to use SAF, please run this script elevated. If you are using Visual Studio Plug-in, please run Visual Studio as Administrator." } } function Initialize { Write-Output "`n`n------------------------------------------------------" Write-Output "--- Welcome to Sitecore Automation Framework (SAF) ---" Write-Output "------------------------------------------------------`n`n" EnsureRunAsAdmin Write-Warning "SAF initialization will start after 3 seconds..." Start-Sleep -s 3 if ($global:Offline -eq $false) { ConfigurePSGallery ConfigureChoco RefreshEnvironment } else { Write-Warning "SAF is running in offline mode. It won't use PSGallery and Chocolatey. That means you'll have more to do by yourself ;)" Start-Sleep -s 5 } Write-Warning "SAF initialization is done." } function Install-Sitecore { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "Install-Sitecore -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Install\OnPrem\Install-Module.psm1" -Force Initialize if ($Config.EndsWith("SitecoreInstallConfiguration.json")) { LoadCofiguration -Config $Config StartInstall -Force:$Force } elseif ($Config.EndsWith("SitecoreQuickInstallConfiguration.json")) { LoadCofiguration -Config $Config StartInstall -Force:$Force -Quickly } else { throw "Invalid JSON Configuration." } Write-Warning "SAF is DONE!" } function Uninstall-Sitecore { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "Uninstall-Sitecore -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Install\OnPrem\Uninstall-Module.psm1" -Force Initialize if (($Config.EndsWith("SitecoreInstallConfiguration.json")) -or ($Config.EndsWith("SitecoreQuickInstallConfiguration.json"))) { LoadCofiguration -Config $Config } else { throw "Invalid JSON Configuration." } StartUninstallSitecore -Force:$Force Write-Warning "SAF is DONE!" } function Install-Solr { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "Install-Solr -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Install\OnPrem\Solr\Solr-Module.psm1" -Force Initialize if (($Config.EndsWith("SitecoreSolrConfiguration.json")) -or ($Config.EndsWith("SitecoreQuickInstallConfiguration.json"))) { LoadCofiguration -Config $Config } else { throw "Invalid JSON Configuration." } StartInstall -Force:$Force Write-Warning "SAF is DONE!" } function New-SolrConfigSets { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "New-SolrConfigSets -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Install\OnPrem\Solr\Solr-Module.psm1" -Force Initialize if ($Config.EndsWith("SitecoreSolrConfiguration.json")) { LoadCofiguration -Config $Config } else { throw "Invalid JSON Configuration." } GenerateNewSolrConfigSets -Force:$Force Write-Warning "SAF is DONE!" } function New-SolrCoresViaHTTP { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "New-SolrCoresViaHTTP -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Install\OnPrem\Solr\Solr-Module.psm1" -Force Initialize if ($Config.EndsWith("SitecoreSolrConfiguration.json")) { LoadCofiguration -Config $Config } else { throw "Invalid JSON Configuration." } CreateNewSolrCoresViaHTTP -Force:$Force Write-Warning "SAF is DONE!" } function Uninstall-Solr { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "Uninstall-Solr -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Install\OnPrem\Uninstall-Module.psm1" -Force Initialize if (($Config.EndsWith("SitecoreSolrConfiguration.json")) -or ($Config.EndsWith("SitecoreQuickInstallConfiguration.json"))) { LoadCofiguration -Config $Config } else { throw "Invalid JSON Configuration." } StartUninstallSolr -Force:$Force Write-Warning "SAF is DONE!" } function New-SSLCerts { [CmdletBinding()] Param ( [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()] [string]$Config, [switch]$Force, [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "New-SSLCerts -Config '$Config' -Force:`$$Force -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Import-Module "$PSScriptRoot\Common\SSL\SSL-Module.psm1" -Force Initialize if ($Config.EndsWith("SAFSSLConfiguration.json")) { LoadCofiguration -Config $Config } else { throw "Invalid JSON Configuration." } StartSSLCertsPipeline -Pipeline "newSSLCerts" -Force:$Force Write-Warning "SAF is DONE!" } function Clear-SAFCache { [CmdletBinding()] Param ( [switch]$Offline, [switch]$AutoConfirm ) SetGlobals -Offline $Offline.IsPresent -AutoConfirm $AutoConfirm.IsPresent -RunningCommand "Clear-Cache -Offline:`$$Offline -AutoConfirm:`$$AutoConfirm" Initialize Write-Output "Clear cache started..." Import-Module "$PSScriptRoot\Common\Run-Pipelines.psm1" -Force RemoveTemp Write-Output "Cache is cleared." Write-Warning "SAF is DONE!" } Export-ModuleMember -Function "Install-Sitecore" Export-ModuleMember -Function "Uninstall-Sitecore" Export-ModuleMember -Function "Install-Solr" Export-ModuleMember -Function "New-SolrConfigSets" Export-ModuleMember -Function "New-SolrCoresViaHTTP" Export-ModuleMember -Function "Uninstall-Solr" Export-ModuleMember -Function "New-SSLCerts" Export-ModuleMember -Function "Clear-SAFCache" |