InstallTar.ps1 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. $ErrorActionPreference = 'Stop'
  17. $ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
  18. Set-StrictMode -Version 1
  19. # Find tar. If not found, install Git to get it.
  20. $repoRoot = (Join-Path $PSScriptRoot "..\.." -Resolve)
  21. $installDir = "$repoRoot\.tools\Git\win-x64"
  22. $tarCommand = "$installDir\usr\bin\tar.exe"
  23. $finalCommand = "$repoRoot\.tools\tar.exe"
  24. Write-Host "Windows version and other information..."
  25. cmd.exe /c ver
  26. systeminfo.exe
  27. Write-Host "Processor Architecture: $env:PROCESSOR_ARCHITECTURE"
  28. Write-Host "Checking $env:SystemRoot\System32\tar.exe"
  29. Get-ChildItem "$env:SystemRoot\System32\ta*.exe"
  30. if (Test-Path "$env:SystemRoot\System32\tar.exe") {
  31. Write-Host "Found $env:SystemRoot\System32\tar.exe"
  32. $tarCommand = "$env:SystemRoot\System32\tar.exe"
  33. }
  34. elseif (Test-Path "$env:ProgramFiles\Git\usr\bin\tar.exe") {
  35. $tarCommand = "$env:ProgramFiles\Git\usr\bin\tar.exe"
  36. }
  37. elseif (Test-Path "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe") {
  38. $tarCommand = "${env:ProgramFiles(x86)}\Git\usr\bin\tar.exe"
  39. }
  40. elseif (Test-Path "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe") {
  41. $tarCommand = "$env:AGENT_HOMEDIRECTORY\externals\git\usr\bin\tar.exe"
  42. }
  43. elseif ((Test-Path $tarCommand) -And (-Not $Force)) {
  44. Write-Verbose "Repo-local Git installation and $tarCommand already exist, skipping Git install."
  45. }
  46. else {
  47. if (-not $GitVersion) {
  48. $globalJson = Get-Content "$repoRoot\global.json" | ConvertFrom-Json
  49. $GitVersion = $globalJson.tools.Git
  50. }
  51. $Uri = "https://netcorenativeassets.blob.core.windows.net/resource-packages/external/windows/git/Git-${GitVersion}-64-bit.zip"
  52. Import-Module -Name (Join-Path $PSScriptRoot "..\common\native\CommonLibrary.psm1" -Resolve)
  53. $InstallStatus = CommonLibrary\DownloadAndExtract -Uri $Uri -InstallDirectory "$installDir\" -Force:$Force -Verbose
  54. if ($InstallStatus -Eq $False) {
  55. Write-Error "Installation failed"
  56. exit 1
  57. }
  58. }
  59. New-Item "$repoRoot\.tools\" -ErrorAction SilentlyContinue -ItemType Directory
  60. Copy-Item "$tarCommand" "$finalCommand" -Verbose
  61. Write-Host "Tar now available at '$finalCommand'"
  62. if ($tarCommand -like '*\Git\*') {
  63. $null >.\.tools\tar.fromGit
  64. }