Function Install-WebApplication { <# .SYNOPSIS Install a Web Application to the appropriate place .DESCRIPTION Install a Web Application to the appropriate place. Will ensure appropriate app pool exists .PARAMETER WebAppName [string] The name of the web application. .PARAMETER SourcePath [string] The folder that contains the files. Typically a chocolatey path. .PARAMETER NeedsShared [switch] Indicates that the legacy utility requires the use of the ORB shared folder. This is a typical configuration for the truly legacy Alkami ORB utility projects. .PARAMETER IsClient [switch] Is this package installed to client? .PARAMETER IsAdmin [switch] Is this package installed to admin? .PARAMETER IsLegacy [switch] Is this package installed to the legacy site? (typically Default Web Site) .PARAMETER NoManagedCode [switch] Is this .net core, or Managed code? .PARAMETER AppPoolName [switch] App pool name. Required for .net core apps. That is, if -NoManagedCode is included. .INPUTS WebAppName and SourcePath are required. Requires one of IsClient or IsAdmin or IsLegacy .OUTPUTS Various diagnostic information about the install process .EXAMPLE Install-WebApplication -WebAppName BankService -SourcePath C:\Orb\BankService -IsLegacy #> [CmdletBinding(DefaultParameterSetName='IsClient')] Param( [Parameter(ParameterSetName='IsAdmin',Mandatory=$true, Position=0)] [Parameter(ParameterSetName='IsClient',Mandatory=$true, Position=0)] [Parameter(ParameterSetName='IsLegacy',Mandatory=$true, Position=0)] [string]$WebAppName, [Parameter(ParameterSetName='IsAdmin',Mandatory=$true, Position=1)] [Parameter(ParameterSetName='IsClient',Mandatory=$true, Position=1)] [Parameter(ParameterSetName='IsLegacy',Mandatory=$true, Position=1)] [string]$SourcePath, [Parameter(ParameterSetName='IsAdmin',Mandatory=$false)] [Parameter(ParameterSetName='IsClient',Mandatory=$false)] [Parameter(ParameterSetName='IsLegacy',Mandatory=$false)] [switch]$NeedsShared, [Parameter(ParameterSetName='IsClient',Mandatory=$true)] [switch]$IsClient, [Parameter(ParameterSetName='IsAdmin',Mandatory=$true)] [switch]$IsAdmin, [Parameter(ParameterSetName='IsLegacy',Mandatory=$true)] [switch]$IsLegacy, [switch]$NoManagedCode, [string]$AppPoolName ) process { $loglead = (Get-LogLeadName) if (!(Test-IsAdmin)){ throw "You are not running as administrator. Can not continue." } if($NoManagedCode){ if ([string]::IsNullOrWhiteSpace($AppPoolName)) { Write-Error "$logLead : When installing a .net core app, an App Pool Name is required." } } Write-Host "$loglead : $WebAppName being installed by $($env:username) on $($env:computername) at $(Get-Date)" ## Assumption: We never copy files for WebApplications being installed because the files already exist on disk ## Legacy: copied into C:\orb along with rest of deploy. Ex: BankService ## Not-Legacy: decompressed into choco-lib folder and linked to IIS from there: ex: CUFX ## Not-Legacy: may require shared folder link, see next block for $NeedsShared if (!(Test-Path $SourcePath)) { throw "Could not find the source path specified at $SourcePath"; } if ($NeedsShared -and (Test-PathIsInApprovedPackageLocation $SourcePath)) { ## This is in a choco or similar location. ## We should take the parent of our path and ensure that a "Shared" symlink exists at that point ## The purpose of this is for Alkami.Ioc resolver to find the parent path in the lookup ## This introduces a hard-limit that no package can be called Shared (unless it's the Legacy ORB "Shared" folder from the build process) $SharedTargetPath = (Join-Path (Split-Path $SourcePath -Parent) "Shared") if (!(Test-Path $SharedTargetPath)) { ## Create the symlink here $sharedOrbPath = Get-OrbSharedPath New-Symlink -path $sharedOrbPath -Destination $SharedTargetPath } } ## If this is a legacy app, and we are on a web-server, we can't install it ## If this is a client or admin app, and we are on not on a web-server, we can't install it. ## If this is a developer machine we can install it if (Test-IsDeveloperMachine) { Write-Host "$loglead : Running as developer, should allow anything to occur" } elseif ((Test-IsWebServer) -and $IsLegacy) { Write-Warning "$loglead : Can not install app-tier web applications on the web tier" return } elseif (!(Test-IsWebServer) -and ($IsClient -or $IsAdmin)) { Write-Warning "$loglead : Can not install web-tier web applications on the app tier" return } if($NoManagedCode){ if ($IsLegacy) { Install-AlkamiWebApplication -WebAppName $WebAppName -SourcePath $SourcePath -IsLegacy -NoManagedCode -AppPoolName $AppPoolName } elseif ($IsClient) { Install-AlkamiWebApplication -WebAppName $WebAppName -SourcePath $SourcePath -IsClient -NoManagedCode -AppPoolName $AppPoolName } elseif ($IsAdmin) { Install-AlkamiWebApplication -WebAppName $WebAppName -SourcePath $SourcePath -IsAdmin -NoManagedCode -AppPoolName $AppPoolName } } else{ if ($IsLegacy) { $legacyTargetPath = Join-Path -Path (Get-OrbPath) -ChildPath $WebAppName $legacySourcePath = Join-Path $SourcePath -ChildPath "Content\App\*" if (-not (Test-Path -Path $legacySourcePath)) { throw "$logLead : Could not find the expected path for the componentized WebApplication at [$legacySourcePath]. Did this package get built according to the Confluence documentation?" } if (-not (Test-Path -Path $legacyTargetPath)) { New-Item -ItemType Directory -Path $legacyTargetPath -Force } Copy-Item -Path $legacySourcePath -Destination $legacyTargetPath -Recurse -Force Install-AlkamiWebApplication -WebAppName $WebAppName -SourcePath $legacyTargetPath -IsLegacy } elseif ($IsClient) { Install-AlkamiWebApplication -WebAppName $WebAppName -SourcePath $SourcePath -IsClient } elseif ($IsAdmin) { Install-AlkamiWebApplication -WebAppName $WebAppName -SourcePath $SourcePath -IsAdmin } } } }