|
| 1 | +function Write-OutputWithInvertedColors([String] $Message) { |
| 2 | + Write-Host $Message -ForegroundColor Black -BackgroundColor White |
| 3 | +} |
| 4 | + |
| 5 | +function Get-HomePath() { |
| 6 | + if (Test-Path Env:\USERPROFILE) { |
| 7 | + return $env:USERPROFILE |
| 8 | + } elseif (Test-Path Env:\HOMEDRIVE -and Env:\HOMEPATH) { |
| 9 | + return $env:HOMEDRIVE + $env:HOMEPATH |
| 10 | + } elseif (Test-Path Env:\LOCALAPPDATA) { |
| 11 | + return $env:LOCALAPPDATA |
| 12 | + } elseif (Test-Path Env:\APPDATA) { |
| 13 | + return $env:APPDATA |
| 14 | + } else { |
| 15 | + Write-Host "Cannot determine user's home directory." -ForegroundColor Red |
| 16 | + Exit 1 |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +function Exit-OnFailure() { |
| 21 | + if ($LASTEXITCODE -ne 0) { |
| 22 | + Write-Host "Exiting due to failure" -ForegroundColor Red |
| 23 | + exit 1 |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +function Update-UserEnvironmentPath { |
| 28 | + $env:Path = |
| 29 | + [System.Environment]::GetEnvironmentVariable("Path","Machine") + |
| 30 | + ";" + |
| 31 | + [System.Environment]::GetEnvironmentVariable("Path","User") |
| 32 | +} |
| 33 | + |
| 34 | +function Write-StepTitle([String] $Message) { |
| 35 | + $equals = "=" * 46 |
| 36 | + Write-Host "" |
| 37 | + Write-OutputWithInvertedColors $equals |
| 38 | + Write-OutputWithInvertedColors $Message |
| 39 | + Write-OutputWithInvertedColors $equals |
| 40 | +} |
| 41 | +Write-StepTitle "I. Installing Python " |
| 42 | +powershell "$PSScriptRoot\install-python.ps1" |
| 43 | +Exit-OnFailure |
| 44 | +Update-UserEnvironmentPath |
| 45 | + |
| 46 | +Write-StepTitle "II. Creating self-contained EBCLI installation" |
| 47 | +$HomeDir = Get-HomePath |
| 48 | +Write-Host "Installing the EBCLI in $HomeDir\.ebcli-virtual-env" |
| 49 | +python "$PSScriptRoot\ebcli_installer.py" --virtualenv-executable "$PSScriptRoot\virtualenv\bin\virtualenv.exe" --hide-export-recommendation --location $HomeDir |
| 50 | +Exit-OnFailure |
| 51 | + |
| 52 | +$PathExporter = "$HomeDir\.ebcli-virtual-env\executables\path_exporter.vbs" |
| 53 | +if ([System.IO.File]::Exists($PathExporter)) { |
| 54 | + Write-StepTitle "III. Exporting `eb` PATH's " |
| 55 | + & "$HomeDir\.ebcli-virtual-env\executables\path_exporter.vbs" |
| 56 | + Update-UserEnvironmentPath |
| 57 | +} |
0 commit comments