generated from sitecorelabs/xmcloud-foundation-head
-
Notifications
You must be signed in to change notification settings - Fork 2
/
upFunctions.ps1
39 lines (31 loc) · 1.31 KB
/
upFunctions.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
function Validate-LicenseExpiry {
param (
[string]$EnvFileName =".env",
[string]$LicenseFolderKey= "HOST_LICENSE_FOLDER"
)
if (-not (Test-Path $EnvFileName)) {
Write-Host "The specified .env file does not exist."
return
}
$licenseFolder = $null
Get-Content $EnvFileName | ForEach-Object {
$line = $_ -split '='
if ($line.Count -eq 2 -and $line[0].Trim() -eq $LicenseFolderKey) {
$licenseFolder = $line[1].Trim()
}
}
$licenseXmlPath = Join-Path $licenseFolder "license.xml"
if (-not (Test-Path $licenseXmlPath)) {
throw "license.xml file does not exist in the specified folder ($licenseXmlPath)."
}
$xml = [xml](Get-Content $licenseXmlPath)
$expiration = $xml.SelectNodes("//expiration")[0].InnerText
$expirationDate =[System.DateTime]::ParseExact($expiration, "yyyyMMddThhmmss", [System.Globalization.CultureInfo]::InvariantCulture)
Write-Host "Expiration" $expirationDate
if ($expirationDate -lt (Get-Date)) {
throw "Your Sitecore license has expired, please update your license file $licenseXmlPath"
} else {
$daysLeft = ($expirationDate - (Get-Date)).Days
Write-Host "The license is valid. $daysLeft days left until expiration." -ForegroundColor Green
}
}