mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:16:30 +00:00
114 lines
3.9 KiB
PowerShell
114 lines
3.9 KiB
PowerShell
# Configuration
|
|
$rcloneRemote = "AzaionGoogleDrive:AzaionSuiteBuilds"
|
|
$rclone = "rclone" # Assuming rclone is available in the PATH.
|
|
|
|
function Write-Header($text) {
|
|
Write-Host "`n=== $text ===`n" -ForegroundColor Cyan
|
|
}
|
|
|
|
function Write-Info($text) {
|
|
Write-Host "[INFO] $text" -ForegroundColor Green
|
|
}
|
|
|
|
function Write-WarningMsg($text) {
|
|
Write-Host "[WARNING] $text" -ForegroundColor Yellow
|
|
}
|
|
|
|
function Write-ErrorMsg($text) {
|
|
Write-Host "[ERROR] $text" -ForegroundColor Red
|
|
}
|
|
|
|
function Get-SortableBuildKey($filename) {
|
|
# This regex is specifically for the AzaionSuite filenames
|
|
# It captures the four-part build number (year.month.day.build)
|
|
if ($filename -match 'AzaionSuite\.(?:Full|Iterative)\.Stage\.(\d{4})\.(\d+)\.(\d+)\.(\d+)\.(zip|exe)$') {
|
|
# Create a combined key that can be sorted chronologically
|
|
# Example: '202507030634'
|
|
$year = [int]$matches[1]
|
|
$month = [int]$matches[2]
|
|
$day = [int]$matches[3]
|
|
$buildNumber = [int]$matches[4]
|
|
return "$year-$month-$day-$buildNumber"
|
|
}
|
|
return "0000-00-00-0000"
|
|
}
|
|
|
|
Write-Header "Starting cleanup of older Full and Iterative installers on Google Drive"
|
|
|
|
Write-Info "Listing all files in: $rcloneRemote"
|
|
$allFilesRaw = & $rclone lsf --files-only $rcloneRemote
|
|
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-ErrorMsg "Failed to list files from Google Drive using rclone."
|
|
exit 1
|
|
}
|
|
|
|
$allFiles = $allFilesRaw -split "`n" | Where-Object { $_ -ne "" }
|
|
|
|
if ($allFiles.Count -eq 0) {
|
|
Write-WarningMsg "No files found in the remote folder."
|
|
exit 0
|
|
}
|
|
|
|
Write-Info "Files found on Google Drive:"
|
|
$allFiles | ForEach-Object { Write-Host " $_" }
|
|
|
|
# --- Full Installers ---
|
|
Write-Header 'Checking for old Full installers (AzaionSuite.Full.*.zip)'
|
|
$fullFiles = $allFiles | Where-Object { $_ -like "AzaionSuite.Full.*.zip" } |
|
|
Sort-Object { Get-SortableBuildKey $_ } -Descending
|
|
|
|
if ($fullFiles.Count -eq 0) {
|
|
Write-WarningMsg "No Full installer files found."
|
|
} else {
|
|
Write-Info "Matching Full installer files (sorted by date/build):"
|
|
$fullFiles | ForEach-Object { Write-Host " $_" }
|
|
|
|
if ($fullFiles.Count -le 5) {
|
|
Write-Info "5 or fewer Full installers found — nothing to delete."
|
|
} else {
|
|
$fullToDelete = $fullFiles | Select-Object -Skip 5
|
|
Write-WarningMsg "Full installers to delete:"
|
|
$fullToDelete | ForEach-Object { Write-Host " $_" }
|
|
|
|
foreach ($file in $fullToDelete) {
|
|
$res = & $rclone deletefile "$rcloneRemote/$file" 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Info "Deleted Full installer: $file"
|
|
} else {
|
|
Write-ErrorMsg "Failed to delete Full installer: $file. Error: $res"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# --- Iterative Installers ---
|
|
Write-Header 'Checking for old Iterative installers (AzaionSuite.Iterative.*.exe)'
|
|
$iterativeFiles = $allFiles | Where-Object { $_ -like "AzaionSuite.Iterative.*.exe" } |
|
|
Sort-Object { Get-SortableBuildKey $_ } -Descending
|
|
|
|
if ($iterativeFiles.Count -eq 0) {
|
|
Write-WarningMsg "No Iterative installer files found."
|
|
} else {
|
|
Write-Info "Matching Iterative installer files (sorted by date/build):"
|
|
$iterativeFiles | ForEach-Object { Write-Host " $_" }
|
|
|
|
if ($iterativeFiles.Count -le 5) {
|
|
Write-Info "5 or fewer Iterative installers found — nothing to delete."
|
|
} else {
|
|
$iterativeToDelete = $iterativeFiles | Select-Object -Skip 5
|
|
Write-WarningMsg "Iterative installers to delete:"
|
|
$iterativeToDelete | ForEach-Object { Write-Host " $_" }
|
|
|
|
foreach ($file in $iterativeToDelete) {
|
|
$res = & $rclone deletefile "$rcloneRemote/$file" 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Info "Deleted Iterative installer: $file"
|
|
} else {
|
|
Write-ErrorMsg "Failed to delete Iterative installer: $file. Error: $res"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Header "Cleanup script completed" |