Skip to content

Commit

Permalink
Merge pull request #1376 from openziti/fix-getZiti-ps1
Browse files Browse the repository at this point in the history
update getZiti.ps1 for other platforms that just windows...
  • Loading branch information
dovholuknf authored Oct 2, 2023
2 parents ef7b6c4 + 8e4d7d9 commit 9eb97e5
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions quickstart/docker/image/getZiti.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,47 @@ None. If "dot sourced" this script will add the resultant directory to your path
.EXAMPLE
PS> . .\getZiti.ps1
#>
Add-Type -AssemblyName System.Runtime.InteropServices

$osDescription = [System.Runtime.InteropServices.RuntimeInformation]::OSDescription
$osArchitecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
$frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription

$arch=$osArchitecture.ToString().ToLower()
if($arch -match "x64") {
$arch = "amd64"
}

if($osDescription.ToLower() -match "windows") {
$matchFilter="ziti-windows-$arch"
} elseif($osDescription.ToLower() -match "darwin") {
$matchFilter="ziti-darwin-amd64"
#todo: replace $arch some day
} elseif($osDescription.ToLower() -match "linux") {
$matchFilter="ziti-linux-$arch"
} else {
Write-Error "An error occurred. os not detected from osDescription: $osDescription"
return
}
$dirSeparator = [System.IO.Path]::DirectorySeparatorChar
$pathSeparator = [System.IO.Path]::PathSeparator
$latestFromGitHub=(irm https://api.github.com/repos/openziti/ziti/releases/latest)
$version=($latestFromGitHub.tag_name)
$zitidl=($latestFromGitHub).assets | where {$_.browser_download_url -Match "ziti-windows.*zip"}
$zitidl=($latestFromGitHub).assets | where {$_.browser_download_url -Match "$matchFilter.*"}
$downloadUrl=($zitidl.browser_download_url)
$name=$zitidl.name
$defaultFolder="$env:USERPROFILE\.ziti\bin"
$toDir=$(Read-Host "Where folder should be used for ziti? [default: ${defaultfolder}]")
$homeDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
$defaultFolder="$homeDirectory${dirSeparator}.ziti${dirSeparator}bin"
$toDir=$(Read-Host "Where should ziti be installed? [default: ${defaultfolder}]")
if($toDir.Trim() -eq "") {
$toDir=("${defaultfolder}")
}

$zipFile="${toDir}\${name}"
$zipFile="${toDir}${dirSeparator}${name}"
if($(Test-Path -Path $zipFile -PathType Leaf)) {
Write-Output "The file has already been downloading. No need to download again"
} else {
mkdir "${toDir}" -ErrorAction SilentlyContinue
mkdir -p "${toDir}"
Write-Output "Downloading file "
Write-Output " from: ${downloadUrl} "
Write-Output " to: ${zipFile}"
Expand All @@ -43,17 +68,23 @@ if($(Test-Path -Path $zipFile -PathType Leaf)) {
$ProgressPreference=$SavedProgressPreference
}

Expand-Archive -Path $zipFile -DestinationPath "${toDir}\${version}" -ErrorAction SilentlyContinue
if($osDescription.ToLower() -match "windows") {
Expand-Archive -Path $zipFile -DestinationPath "${toDir}${dirSeparator}${version}" -ErrorAction SilentlyContinue
} else {
$env:LC_ALL = "en_US.UTF-8"
mkdir -p "${toDir}${dirSeparator}${version}"
tar -xvf $zipFile -C "${toDir}${dirSeparator}${version}"
}

Write-Output " "
Write-Output "Extracted binaries to ${toDir}\${version}\ziti"
Write-Output "Extracted binaries to ${toDir}${dirSeparator}${version}${dirSeparator}ziti"
Write-Output " "
$addToPath=$(Read-Host "Would you like to add ziti to this session's path? [default: Y]")
if($addToPath.Trim() -eq "") {
$addToPath=("Y")
}

if($addToPath -ilike "y*") {
$env:Path+=";${toDir}\${version}"
$env:PATH+="$pathSeparator${toDir}${dirSeparator}${version}"
Write-Output "ziti added to your path!"
}
}

0 comments on commit 9eb97e5

Please sign in to comment.