Files
zeekay 241625e7d9 rename: ziti → zt across all paths
- Repo names: ziti-* → zt-*
- Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt
- Docker images: hanzozt/ziti-* → hanzozt/zt-*
- C/Java/JS symbols: ziti_* → zt_*
- File and directory names updated
2026-02-18 18:34:19 -08:00

90 lines
3.2 KiB
PowerShell

<#
.SYNOPSIS
Gets the latest zt from github and adds it to your path
.DESCRIPTION
This script will:
- detect the latest version of zt
- download the latest version of zt into the folder of your choice, defaulting to $env:userprofile.zt\bin)
- unzip the downloaded file
- optionally add the extracted path to your path if executed with a "dot" as in: . getLatestZiti.ps1
.INPUTS
None.
.OUTPUTS
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
$frameworkDescription = [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
$arch=${env:PROCESSOR_ARCHITECTURE}.ToString().ToLower()
if($arch -match "x64") {
$arch = "amd64"
}
if($osDescription.ToLower() -match "windows") {
$matchFilter="zt-windows-$arch"
} elseif($osDescription.ToLower() -match "darwin") {
$matchFilter="zt-darwin-amd64"
#todo: replace $arch some day
} elseif($osDescription.ToLower() -match "linux") {
$matchFilter="zt-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/hanzozt/zt/releases/latest)
$version=($latestFromGitHub.tag_name)
$ztdl=($latestFromGitHub).assets | where {$_.browser_download_url -Match "$matchFilter.*"}
$downloadUrl=($ztdl.browser_download_url)
$name=$ztdl.name
$homeDirectory = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
$defaultFolder="$homeDirectory${dirSeparator}.zt${dirSeparator}bin"
$toDir=$(Read-Host "Where should zt be installed? [default: ${defaultfolder}]")
if($toDir.Trim() -eq "") {
$toDir=("${defaultfolder}")
}
$zipFile="${toDir}${dirSeparator}${name}"
if($(Test-Path -Path $zipFile -PathType Leaf)) {
Write-Output "The distribution has already been downloaded to $zipFile. Not downloading again"
} else {
New-Item -Force -ItemType Directory -Path "${toDir}"
Write-Output "Downloading file "
Write-Output " from: ${downloadUrl} "
Write-Output " to: ${zipFile}"
$SavedProgressPreference=$ProgressPreference
$ProgressPreference='SilentlyContinue'
iwr ${downloadUrl} -OutFile "$zipFile"
$ProgressPreference=$SavedProgressPreference
}
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}${dirSeparator}${version}${dirSeparator}zt"
Write-Output " "
$addToPath=$(Read-Host "Would you like to add zt to this session's path? [default: Y]")
if($addToPath.Trim() -eq "") {
$addToPath=("Y")
}
if($addToPath -ilike "y*") {
$env:PATH+="$pathSeparator${toDir}${dirSeparator}${version}"
Write-Output "zt added to your path!"
}