From c1a76cd9129a41f49d1f898094f64d6b7b8b9eb4 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Wed, 9 Mar 2022 10:03:21 +0000 Subject: [PATCH 1/2] Add some backward compats code for IsWindows and IsLinux --- CloneTentacleInstance.ps1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CloneTentacleInstance.ps1 b/CloneTentacleInstance.ps1 index 7fb6305..3f79b8a 100644 --- a/CloneTentacleInstance.ps1 +++ b/CloneTentacleInstance.ps1 @@ -28,6 +28,37 @@ $ErrorActionPreference = "Stop" . ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusRepository.ps1")) . ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusFakeFactory.ps1")) +if(-not (Get-Variable -Name "IsWindows" -ErrorAction SilentlyContinue)) { + Write-Verbose "`$IsWindows doesnt exist, determining value and creating variable."; + $IsWindows = $False + + if($PSVersionTable.PSEdition -ieq "Desktop") { + $IsWindows = $True; + } + else { + if (Get-Member -inputObject $PSVersionTable -Name "Platform" -MemberType Properties) { + if($PSVersionTable.Platform -ieq "Win32NT") { + $IsWindows = $True + } + } + } +} + +if(-not (Get-Variable -Name "IsLinux" -ErrorAction SilentlyContinue)) { + Write-Verbose "`$IsLinux doesnt exist, determining value and creating variable." + $IsLinux = $False + if(Get-Member -InputObject $PSVersionTable -Name "Platform" -MemberType Properties) { + if($PSVersionTable.Platform -ieq "Unix") { + $IsLinux = $True + } + } +} + +# Safety check to make sure the calculation doesnt result in both variables being the same value. +if($IsWindows -eq $IsLinux) { + throw "Calculation for OS caused both `$IsWindows and `$IsLinux to be the same value!" +} + if ($null -eq $DestinationOctopusServerThumbprint) { Throw "The parameter DestinationOctopusServerThumbprint is required. You can get this by going to configuration -> thumbprint in the destination Octopus Deploy instance." From 80d515c50cad42593fa8a59162215170c5a8ed27 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Wed, 9 Mar 2022 14:08:49 +0000 Subject: [PATCH 2/2] Simplified backwards compat code --- CloneTentacleInstance.ps1 | 45 ++++++--------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/CloneTentacleInstance.ps1 b/CloneTentacleInstance.ps1 index 3f79b8a..8ec2e3d 100644 --- a/CloneTentacleInstance.ps1 +++ b/CloneTentacleInstance.ps1 @@ -28,37 +28,6 @@ $ErrorActionPreference = "Stop" . ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusRepository.ps1")) . ([System.IO.Path]::Combine($PSScriptRoot, "src", "DataAccess", "OctopusFakeFactory.ps1")) -if(-not (Get-Variable -Name "IsWindows" -ErrorAction SilentlyContinue)) { - Write-Verbose "`$IsWindows doesnt exist, determining value and creating variable."; - $IsWindows = $False - - if($PSVersionTable.PSEdition -ieq "Desktop") { - $IsWindows = $True; - } - else { - if (Get-Member -inputObject $PSVersionTable -Name "Platform" -MemberType Properties) { - if($PSVersionTable.Platform -ieq "Win32NT") { - $IsWindows = $True - } - } - } -} - -if(-not (Get-Variable -Name "IsLinux" -ErrorAction SilentlyContinue)) { - Write-Verbose "`$IsLinux doesnt exist, determining value and creating variable." - $IsLinux = $False - if(Get-Member -InputObject $PSVersionTable -Name "Platform" -MemberType Properties) { - if($PSVersionTable.Platform -ieq "Unix") { - $IsLinux = $True - } - } -} - -# Safety check to make sure the calculation doesnt result in both variables being the same value. -if($IsWindows -eq $IsLinux) { - throw "Calculation for OS caused both `$IsWindows and `$IsLinux to be the same value!" -} - if ($null -eq $DestinationOctopusServerThumbprint) { Throw "The parameter DestinationOctopusServerThumbprint is required. You can get this by going to configuration -> thumbprint in the destination Octopus Deploy instance." @@ -422,17 +391,17 @@ function Get-TentacleDirectories $tentacleDirectory = @{} - if ($IsWindows) + if ($IsLinux) { - $tentacleDirectory.HomeDirectory = "C:\Octopus\$ClonedInstanceName" - $tentacleDirectory.AppDirectory = "C:\Octopus\$ClonedInstanceName\Applications" - $tentacleDirectory.ConfigFile = "C:\Octopus\$ClonedInstanceName\Tentacle\Tentacle.config" + $tentacleDirectory.HomeDirectory = "/etc/octopus/default/$ClonedInstanceName" + $tentacleDirectory.AppDirectory = "/home/Octopus/$ClonedInstanceName/Applications/" + $tentacleDirectory.ConfigFile = "/etc/octopus/default/$ClonedInstanceName/tentacle-default.config" } else { - $tentacleDirectory.HomeDirectory = "/etc/octopus/default/$ClonedInstanceName" - $tentacleDirectory.AppDirectory = "/home/Octopus/$ClonedInstanceName/Applications/" - $tentacleDirectory.ConfigFile = "/etc/octopus/default/$ClonedInstanceName/tentacle-default.config" + $tentacleDirectory.HomeDirectory = "C:\Octopus\$ClonedInstanceName" + $tentacleDirectory.AppDirectory = "C:\Octopus\$ClonedInstanceName\Applications" + $tentacleDirectory.ConfigFile = "C:\Octopus\$ClonedInstanceName\Tentacle\Tentacle.config" } return $tentacleDirectory