|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Finds or installs the Tar command on this system. |
| 4 | +.DESCRIPTION |
| 5 | + This script searches for Tar on this system. If not found, downloads and extracts Git to use its tar.exe. Prefers |
| 6 | + global installation locations even if Git has been downloaded into this repo. |
| 7 | +.PARAMETER GitVersion |
| 8 | + The version of the Git to install. If not set, the default value is read from global.json. |
| 9 | +.PARAMETER Force |
| 10 | + Overwrite the existing installation if one exists in this repo and Tar isn't installed globally. |
| 11 | +#> |
| 12 | +param( |
| 13 | + [string]$GitVersion, |
| 14 | + [switch]$Force |
| 15 | +) |
| 16 | + |
| 17 | +$ErrorActionPreference = 'Stop' |
| 18 | +$ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138 |
| 19 | + |
| 20 | +Set-StrictMode -Version 1 |
| 21 | + |
| 22 | +# Find tar. If not found, install Git to get it. |
| 23 | +$repoRoot = (Join-Path $PSScriptRoot "..\.." -Resolve) |
| 24 | +$installDir = "$repoRoot\.tools\Git\win-x64" |
| 25 | +$tarCommand = "$installDir\usr\bin\tar.exe" |
| 26 | +$finalCommand = "$repoRoot\.tools\tar.exe" |
| 27 | + |
| 28 | +Write-Host "Windows version and other information, because who knows" |
| 29 | +cmd.exe /c ver |
| 30 | +systeminfo.exe |
| 31 | + |
| 32 | +Write-Host "Processor Architecture: $env:PROCESSOR_ARCHITECTURE" |
| 33 | +Write-Host "Dumping environment" |
| 34 | +Get-ChildItem env:\ |
| 35 | + |
| 36 | +Write-Host "Checking $env:SystemRoot\System32\tar.exe" |
| 37 | +Get-ChildItem "$env:SystemRoot\System32\ta*.exe" |
| 38 | +if (Test-Path "$env:SystemRoot\System32\tar.exe") { |
| 39 | + Write-Host "Found $env:SystemRoot\System32\tar.exe" |
| 40 | + $tarCommand = "$env:SystemRoot\System32\tar.exe" |
| 41 | +} |
| 42 | +elseif (Test-Path "$env:ProgramFiles\Git\usr\bin\tar.exe") { |
| 43 | + $tarCommand = "$env:ProgramFiles\Git\usr\bin\tar.exe" |
| 44 | +} |
| 45 | +elseif (Test-Path "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe") { |
| 46 | + $tarCommand = "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe" |
| 47 | +} |
| 48 | +elseif (Test-Path "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe") { |
| 49 | + $tarCommand = "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe" |
| 50 | +} |
| 51 | +elseif ((Test-Path $tarCommand) -And (-Not $Force)) { |
| 52 | + Write-Verbose "Repo-local Git installation and $tarCommand already exist, skipping Git install." |
| 53 | +} |
| 54 | +else { |
| 55 | + if (-not $GitVersion) { |
| 56 | + $globalJson = Get-Content "$repoRoot\global.json" | ConvertFrom-Json |
| 57 | + $GitVersion = $globalJson.tools.Git |
| 58 | + } |
| 59 | + |
| 60 | + $Uri = "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/git/Git-${GitVersion}-64-bit.zip" |
| 61 | + |
| 62 | + Import-Module -Name (Join-Path $PSScriptRoot "..\common\native\CommonLibrary.psm1" -Resolve) |
| 63 | + $InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri -InstallDirectory "$installDir\" -Force:$Force -Verbose |
| 64 | + |
| 65 | + if ($InstallStatus -Eq $False) { |
| 66 | + Write-Error "Installation failed" |
| 67 | + exit 1 |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +Copy-Item "$tarCommand" "$finalCommand" -Verbose |
| 72 | +Write-Host "Tar now available at '$finalCommand'" |
| 73 | + |
| 74 | +if ($tarCommand -like '*\Git\*') { |
| 75 | + $null >.\.tools\tar.fromGit |
| 76 | +} |
0 commit comments