Last active
November 14, 2018 13:36
-
-
Save pawelpabich/edaacd9b0bdd0443010b6db20882676e to your computer and use it in GitHub Desktop.
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
param([string] $Version, [string] $StorageAccount, [string] $StorageUser, [string] $StoragePassword) | |
$ErrorActionPreference = "Stop" | |
Set-StrictMode -Version Latest; | |
New-Item -ItemType Directory -Force -Path C:\Temp | |
function Log($Message) | |
{ | |
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss,fff" | |
$newLine = [System.Environment]::NewLine | |
$logEntry = "$timestamp $Message $newLine" | |
Write-Host $logEntry | |
Add-Content -Path "C:\Temp\Log.txt" -Value $logEntry | |
} | |
$installerName = "Octopus.$Version.msi" | |
$serverDownloadPath = "https://octopus-testing.s3.amazonaws.com/server/Octopus.$Version-x64.msi" | |
function Download-File | |
{ | |
param ( | |
[string]$url, | |
[string]$saveAs | |
) | |
Log "Downloading $url to $saveAs" | |
$downloader = new-object System.Net.WebClient | |
$downloader.DownloadFile($url, $saveAs) | |
} | |
function Install-Server | |
{ | |
Log "Beginning Octopus Server installation" | |
$pathspec = "$env:SystemDrive\\OctopusTest" | |
if(Test-Path -path $pathspec) | |
{ | |
Remove-Item $pathspec -recurse -force | |
} | |
$serverDownloadSavePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\\$installerName") | |
if ((test-path $serverDownloadSavePath) -ne $true) | |
{ | |
Log "Downloading latest Octopus Server MSI from '$serverDownloadPath' to '$serverDownloadSavePath'..." | |
Download-File $serverDownloadPath $serverDownloadSavePath | |
} | |
else | |
{ | |
Log "Skipping download of latest Octopus Server MSI as '$serverDownloadSavePath' already exists" | |
} | |
Log "Installing MSI" | |
$msiExitCode = (Start-Process -FilePath "msiexec.exe" -ArgumentList "/i $installerName /quiet /l*v C:\\ServerMsiInstallation.log" -Wait -Passthru).ExitCode | |
Log "Octopus Server MSI installer returned exit code $msiExitCode" | |
Log "Removing msi from '$serverDownloadSavePath'" | |
Remove-Item -Path $serverDownloadSavePath -Force | |
} | |
function Setup-VM | |
{ | |
& netsh.exe firewall add portopening TCP 80 "Octopus Server" | |
& netsh.exe firewall add portopening TCP 443 "Octopus Server" | |
& netsh.exe firewall add rule name="Tentacles" dir=in action=allow protocol=TCP localport=10000-15000 | |
$serverDownloadSavePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\\PSTools.zip") | |
if ((test-path $serverDownloadSavePath) -ne $true) | |
{ | |
Log "Downloading tools 'https://download.sysinternals.com/files/PSTools.zip' to '$serverDownloadSavePath'..." | |
Download-File -url "https://download.sysinternals.com/files/PSTools.zip" -saveAs $serverDownloadSavePath | |
$folder = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(".\\PSTools") | |
Expand-Archive $serverDownloadSavePath -DestinationPath $folder | |
} | |
else | |
{ | |
Log "Skipping downloading tools '$serverDownloadSavePath' already exists" | |
} | |
& .\PsTools\PsExec64.exe -accepteula -s cmdkey /add:$StorageAccount /user:$StorageUser /pass:$StoragePassword | |
} | |
Log "Octopus is not installed. Installing $Version" | |
Setup-VM | |
Install-Server | |
Log "Server deployment finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment