Core/SitecoreInstall-Module.psm1

$ErrorActionPreference = "Stop"

function GetSitecoreInstallPipeline {
    if ($null -ne $SAFConfiguration.system.sitecoreMode) {
        return "install$($SAFConfiguration.system.hosting)$($SAFConfiguration.system.serverRole)-$($SAFConfiguration.system.sitecoreMode)"
    }
    else {
        return "install$($SAFConfiguration.system.hosting)$($SAFConfiguration.system.serverRole)"
    }
}

function GetSitecoreInstallPipelinesFile {
    $version = $SAFConfiguration.sitecore.version
    $majorMinorOnly = $version.Substring(0, ($version.LastIndexOf('.')))
    return "$SAFInstallSitecoreOnPremPipelines\$majorMinorOnly\Pipelines.json"
}

function ShowPostInstallSteps {
    Write-Output ""
    Write-Output ""
    Write-Output ""

    Write-Warning "POST-INSTALLATION STEPS (please, go through the following list manually)"

    
    Write-Warning "1. Rebuild the Search Indexes"
    Write-Warning "2. Rebuild the Link Database"

    if ($SAFConfiguration.system.sitecoreMode -eq "XP") {
        Write-Warning "3. Deploy Marketing Definitions"
    }
}

function InstallSitecore {
    [CmdletBinding()]
    Param
    (
        [switch]$Force
    )
    
    $pipelinesFile = GetSitecoreInstallPipelinesFile
    $pipelineName = GetSitecoreInstallPipeline
    RunPipeline -DefinitionFile $pipelinesFile -Name $pipelineName -Force:$Force -RunExtensions

    $role = $SAFConfiguration.system.serverRole
    if(($role -eq "AllInOneQuickly") -or ($role -eq "AllInOne") -or ($role -eq "AllInOneSitecore") -or ($role -eq "CM")) {
        ShowPostInstallSteps
    }
}

Export-ModuleMember -Function "InstallSitecore"