github.com/datreeio/datree@v1.9.22-rc/windows_install.ps1 (about)

     1  #Requires -Version 5
     2  
     3  $old_erroractionpreference = $erroractionpreference
     4  $erroractionpreference = 'stop' # quit if anything goes wrong
     5  
     6  if (($PSVersionTable.PSVersion.Major) -lt 5) {
     7      Write-Output "PowerShell 5 or later is required to run Datree."
     8      Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell"
     9      break
    10  }
    11  
    12  # show notification to change execution policy:
    13  $allowedExecutionPolicy = @('Unrestricted', 'RemoteSigned', 'ByPass')
    14  if ((Get-ExecutionPolicy).ToString() -notin $allowedExecutionPolicy) {
    15      Write-Output "PowerShell requires an execution policy in [$($allowedExecutionPolicy -join ", ")] to run Datree."
    16      Write-Output "For example, to set the execution policy to 'RemoteSigned' please run :"
    17      Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'"
    18      break
    19  }
    20  
    21  $osArchitecture = if([Environment]::Is64BitProcess) { 'x86_64' } else { '386' }
    22  $DOWNLOAD_URL = (Invoke-WebRequest -Uri 'https://api.github.com/repos/datreeio/datree/releases/latest' -UseBasicParsing | select-string -Pattern "https://github.com/datreeio/datree/releases/download/\d+\.\d+\.\d+/datree-cli_\d+\.\d+\.\d+_windows_$osArchitecture.zip").Matches.Value
    23  $OUTPUT_BASENAME = "datree-latest"
    24  $OUTPUT_BASENAME_WITH_POSTFIX = "$OUTPUT_BASENAME.zip"
    25  
    26  Write-Host 'Installing Datree...'
    27  Write-Host ''
    28  Invoke-WebRequest -Uri $DOWNLOAD_URL -OutFile $OUTPUT_BASENAME_WITH_POSTFIX -UseBasicParsing
    29  Write-Host "[V] Downloaded Datree" -ForegroundColor DarkGreen
    30  
    31  Expand-Archive -Path $OUTPUT_BASENAME_WITH_POSTFIX -DestinationPath $OUTPUT_BASENAME -Force | Out-Null
    32  
    33  $localAppDataPath = $env:LOCALAPPDATA
    34  $datreePath = Join-Path "$localAppDataPath" 'datree'
    35  New-Item -ItemType Directory -Force -Path $datreePath | Out-Null
    36  
    37  Copy-Item "$OUTPUT_BASENAME/*" -Destination "$datreePath/" -Recurse -Force | Out-Null
    38  
    39  Remove-Item -Recurse $OUTPUT_BASENAME
    40  Remove-Item $OUTPUT_BASENAME_WITH_POSTFIX
    41  
    42  $dotDatreePath = "$home/.datree"
    43  mkdir -Force $dotDatreePath | Out-Null
    44  $k8sDemoPath = Join-Path "$dotDatreePath" "k8s-demo.yaml"
    45  
    46  Invoke-WebRequest -Uri "https://get.datree.io/k8s-demo.yaml" -OutFile $k8sDemoPath -UseBasicParsing
    47  
    48  Write-Host "[V] Finished Installation" -ForegroundColor DarkGreen
    49  Write-Host ""
    50  Write-Host "To run datree globally, please follow these steps:" -ForegroundColor Cyan
    51  Write-Host ""
    52  Write-Host "    1. Run the following command as administrator: ``setx PATH `"`$env:path;$datreePath`" -m``"
    53  Write-Host ""
    54  Write-Host "    2. Close and reopen your terminal."
    55  Write-Host ""
    56  Write-Host "For more information, please visit https://datree.io" -ForegroundColor Cyan
    57  Write-Host ""
    58  Write-Host "    Usage: datree test `$home/.datree/k8s-demo.yaml" -ForegroundColor DarkGreen
    59  Write-Host ""
    60  Write-Host "    Run 'datree completion -h' to learn how to generate shell autocompletions"
    61  Write-Host ""