Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6727a94
Check for OS-Bitness rather than Processor Architecture
rahulrajaram Apr 21, 2019
6db1e26
Extract logic to determine Python installation URL into a function
rahulrajaram Apr 21, 2019
307c0db
Modify verbiage indicating Python will be installed silently
rahulrajaram Apr 21, 2019
74407d5
Rename $python -> $PythonInstaller in install-python.ps1
rahulrajaram Apr 21, 2019
a90eb41
Exit install-python.ps1 with non-0 code if MSI download fails
rahulrajaram Apr 21, 2019
ee21ee5
Extract logic to install Python into a function
rahulrajaram Apr 21, 2019
9079800
Avoid closing existing shell after installation completion
rahulrajaram Apr 21, 2019
c27746b
Bring up Python MSI rather than install in the background
rahulrajaram Apr 21, 2019
d40f64d
Remove previously downloaded Python MSI exe before new attempt to dow…
rahulrajaram Apr 21, 2019
9576d5c
Update PATH current session after installation
rahulrajaram Apr 21, 2019
8078c03
Rename Download-Python -> Get-PythonMSI
rahulrajaram Apr 21, 2019
59bb41e
Rename Assert-IsPythonRequired -> Get-PythonExecutable/Change return …
rahulrajaram Apr 21, 2019
b3b5433
Handle user-triggered exits from the installer specially
rahulrajaram Apr 21, 2019
751b53e
Rename install-python.ps1 -> .\scripts\install-python.ps1
rahulrajaram Apr 21, 2019
e71f0c1
Create a function to echo step titles
rahulrajaram Apr 21, 2019
ea539f7
Highlight success/failure messages printed by install-python.ps1 in g…
rahulrajaram Apr 21, 2019
db8262f
Install virtualenv after completing python installation
rahulrajaram Apr 21, 2019
69759fe
Create a PS1/BAT script to install Python and the EBCLI
rahulrajaram Apr 21, 2019
7cb76dc
Exit Python installation script following installation failures
rahulrajaram Apr 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions install-python.ps1

This file was deleted.

1 change: 1 addition & 0 deletions scripts/bundled_installer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Powershell.exe -executionpolicy remotesigned -File "%~dp0\bundled_installer.ps1"
57 changes: 57 additions & 0 deletions scripts/bundled_installer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function Write-OutputWithInvertedColors([String] $Message) {
Write-Host $Message -ForegroundColor Black -BackgroundColor White
}

function Get-HomePath() {
if (Test-Path Env:\USERPROFILE) {
return $env:USERPROFILE
} elseif (Test-Path Env:\HOMEDRIVE -and Env:\HOMEPATH) {
return $env:HOMEDRIVE + $env:HOMEPATH
} elseif (Test-Path Env:\LOCALAPPDATA) {
return $env:LOCALAPPDATA
} elseif (Test-Path Env:\APPDATA) {
return $env:APPDATA
} else {
Write-Host "Cannot determine user's home directory." -ForegroundColor Red
Exit 1
}
}

function Exit-OnFailure() {
if ($LASTEXITCODE -ne 0) {
Write-Host "Exiting due to failure" -ForegroundColor Red
exit 1
}
}

function Update-UserEnvironmentPath {
$env:Path =
[System.Environment]::GetEnvironmentVariable("Path","Machine") +
";" +
[System.Environment]::GetEnvironmentVariable("Path","User")
}

function Write-StepTitle([String] $Message) {
$equals = "=" * 46
Write-Host ""
Write-OutputWithInvertedColors $equals
Write-OutputWithInvertedColors $Message
Write-OutputWithInvertedColors $equals
}
Write-StepTitle "I. Installing Python "
powershell "$PSScriptRoot\install-python.ps1"
Exit-OnFailure
Update-UserEnvironmentPath

Write-StepTitle "II. Creating self-contained EBCLI installation"
$HomeDir = Get-HomePath
Write-Host "Installing the EBCLI in $HomeDir\.ebcli-virtual-env"
python "$PSScriptRoot\ebcli_installer.py" --virtualenv-executable "$PSScriptRoot\virtualenv\bin\virtualenv.exe" --hide-export-recommendation --location $HomeDir
Exit-OnFailure

$PathExporter = "$HomeDir\.ebcli-virtual-env\executables\path_exporter.vbs"
if ([System.IO.File]::Exists($PathExporter)) {
Write-StepTitle "III. Exporting `eb` PATH's "
& "$HomeDir\.ebcli-virtual-env\executables\path_exporter.vbs"
Update-UserEnvironmentPath
}
83 changes: 83 additions & 0 deletions scripts/install-python.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
$PythonInstaller = "$PSScriptRoot\python3.7.3.exe"
$StepNumber = 1

function Write-StepTitle([String] $StepMessage) {
$StepMessage="$Script:StepNumber. $StepMessage"
$MessageLength=$StepMessage.length
$RepeatedStars = "*" * $MessageLength
Write-Host ""
Write-Host $RepeatedStars
Write-Host $StepMessage
Write-Host $RepeatedStars
$Script:StepNumber = $Script:StepNumber + 1
}

function Get-PythonExecutable {
Write-StepTitle "Looking for existing Python 3.7.3 installation."
return Get-WmiObject -Namespace "root/cimv2" -Class Win32_Product -Filter "Name Like 'Python 3.7.3 Executables%'"
}

function Get-PythonInstallationTarget {
if ([Environment]::Is64BitOperatingSystem) {
Write-StepTitle "Downloading x64 version of Python."
return "https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64-webinstall.exe"
} else {
Write-StepTitle "Downloading x86 version of Python."
return "https://www.python.org/ftp/python/3.7.3/python-3.7.3-webinstall.exe"
}
}

function Get-PythonMSI {
if ([System.IO.File]::Exists($PythonInstaller)) {
Remove-Item $PythonInstaller
}
$url = Get-PythonInstallationTarget
$client = New-Object System.Net.WebClient
try {
$client.DownloadFile($url, $PythonInstaller)
} catch {
Write-Host "Failed to download Python. The following exception was raised:" -ForegroundColor Red
Write-Host $_.exception -ForegroundColor Red

Exit 1
}
}

function Install-Python {
Write-StepTitle "Installing Python. Do not close this window."
Write-Host "Installing Python. Do not close this window."
$install = Start-Process $PythonInstaller -ArgumentList "InstallAllUsers=1 PrependPath=1" -PassThru -wait
if ($install.ExitCode -eq 0) {
Write-Host "Installation completed successfully." -ForegroundColor Green
} elseif ($install.ExitCode -eq 1602) {
Write-Host "Installer was exited by the user." -ForegroundColor Red
Exit 1
} else {
Write-Host "Installation failed with exit code $install.ExitCode" -ForegroundColor Red
Exit 1
}
}

function Update-UserEnvironmentPath {
Write-StepTitle "Updating Environment PATH of this shell."
$env:Path =
[System.Environment]::GetEnvironmentVariable("Path","Machine") +
";" +
[System.Environment]::GetEnvironmentVariable("Path","User")
}

function Install-Virtualenv {
Write-StepTitle "Installing virtualenv"
Invoke-Expression "pip install virtualenv --target $PSScriptRoot\virtualenv --upgrade"
}

$PythonExecutable = Get-PythonExecutable
if ($PythonExecutable.count -eq 0) {
Get-PythonMSI
Install-Python
Update-UserEnvironmentPath
Remove-Item $PythonInstaller
} else {
Write-Host "Python 3.7.3 is already installed." -ForegroundColor Green
}
Install-Virtualenv