Last active
July 28, 2017 13:15
-
-
Save istairbn/3188c76245601eb8cd5c26d0b5acd978 to your computer and use it in GitHub Desktop.
A PowerShell script to generate a Support Package for XL Release. Since the service needs to be stopped to collect the data before it can be zipped and shipped.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
<# | |
.SYNOPSIS | |
This script builds an XL Release support package. it is designed to be used when you run as a service, since Windows locks certain key files. | |
.PARAMETER PackageName | |
The name of the output zip | |
.PARAMETER TempName | |
The Name of the temporary file generated (defaults to GetDate) | |
.PARAMETER FoldersToCopy | |
The folders Xebia Labs want. | |
.PARAMETER FilesToStrip | |
The files from which you want to remove lines containing password. | |
.USAGE | |
Copy to your XL Release Directory and run from there. It will; | |
- Clean any previous packages | |
- Stop the XL Release service (assuming it uses the default name) | |
- Copy the folders to a temp location | |
- Restart the service (minimum downtime) | |
- Strip any lines from the files to strip that contain the word password | |
- Zip the contents up | |
- Remove the temp directory | |
#> | |
Param( | |
[String] $PackageName = "XL-ReleaseSupportPackage.zip", | |
[String] $TempName = (Get-Date).ToString("yyyyMMddHHmmss"), | |
[ValidateScript( { Test-Path $_ } )] | |
[String[]] $FoldersToCopy = @( | |
".\conf", | |
".\ext", | |
".\hotfix", | |
".\lib", | |
".\log", | |
".\plugins" | |
), | |
[String[]] $FilesToStrip = @( | |
"xl-release-server.conf" | |
) | |
) | |
If ( Test-Path $PackageName ) { | |
Write-Output "Removing previous package" | |
Remove-Item $PackageName -Force -Recurse | |
} | |
$Service = Get-Service -Name xl-release | |
If( $Service ){ | |
Write-Output "Stopping XL Release Service" | |
$Service | Stop-Service -Force | |
} | |
Else{ | |
Write-Verbose "No Service running" | |
} | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
Write-Output "Generating XL Release Diagnostics Package" | |
$Files = Get-Item -Path $FoldersToCopy | |
$TempFolder = New-Item -Path $TempName -ItemType Directory | |
Write-Output "Creating Temporary Folder named $TempName" | |
$Files | Copy-Item -Destination $TempFolder.FullName -Recurse | |
If($Service){ | |
Write-Output "Starting XL Release Service" | |
$Service | Start-Service | |
} | |
Else{ | |
Write-Verbose "No Service running" | |
} | |
Write-Output "Creating $PackageName" | |
$TempFiles = Get-ChildItem -Path $TempFolder.FullName -Recurse | |
ForEach( $File in $TempFiles ) { | |
If($FilesToStrip -contains $File.Name ) { | |
Write-Output "Stripping password lines from $($File.Name)" | |
$FileObj = Get-Content $File.FullName | |
$FileObj | Select-String -Pattern "password" -NotMatch | Out-File -FilePath $File.FullName | |
} | |
} | |
[System.IO.Compression.ZipFile]::CreateFromDirectory($TempFolder,$PackageName,"Optimal",$False) | |
Write-Output "Removing Temporary Folder" | |
Remove-Item $TempFolder -Recurse -Force | |
Write-Output "Support Package creation complete." | |
Write-Output "Please check that no passwords remain in the Zip file" | |
Write-Output "Then send to Xebia Labs for analysis." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment