Skip to content

Commit ebf048b

Browse files
authored
Merge pull request #8 from aws/PowershellChanges
Powershell changes
2 parents 9424d4d + 7cb76dc commit ebf048b

File tree

4 files changed

+141
-54
lines changed

4 files changed

+141
-54
lines changed

install-python.ps1

Lines changed: 0 additions & 54 deletions
This file was deleted.

scripts/bundled_installer.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Powershell.exe -executionpolicy remotesigned -File "%~dp0\bundled_installer.ps1"

scripts/bundled_installer.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

scripts/install-python.ps1

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
$PythonInstaller = "$PSScriptRoot\python3.7.3.exe"
2+
$StepNumber = 1
3+
4+
function Write-StepTitle([String] $StepMessage) {
5+
$StepMessage="$Script:StepNumber. $StepMessage"
6+
$MessageLength=$StepMessage.length
7+
$RepeatedStars = "*" * $MessageLength
8+
Write-Host ""
9+
Write-Host $RepeatedStars
10+
Write-Host $StepMessage
11+
Write-Host $RepeatedStars
12+
$Script:StepNumber = $Script:StepNumber + 1
13+
}
14+
15+
function Get-PythonExecutable {
16+
Write-StepTitle "Looking for existing Python 3.7.3 installation."
17+
return Get-WmiObject -Namespace "root/cimv2" -Class Win32_Product -Filter "Name Like 'Python 3.7.3 Executables%'"
18+
}
19+
20+
function Get-PythonInstallationTarget {
21+
if ([Environment]::Is64BitOperatingSystem) {
22+
Write-StepTitle "Downloading x64 version of Python."
23+
return "https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64-webinstall.exe"
24+
} else {
25+
Write-StepTitle "Downloading x86 version of Python."
26+
return "https://www.python.org/ftp/python/3.7.3/python-3.7.3-webinstall.exe"
27+
}
28+
}
29+
30+
function Get-PythonMSI {
31+
if ([System.IO.File]::Exists($PythonInstaller)) {
32+
Remove-Item $PythonInstaller
33+
}
34+
$url = Get-PythonInstallationTarget
35+
$client = New-Object System.Net.WebClient
36+
try {
37+
$client.DownloadFile($url, $PythonInstaller)
38+
} catch {
39+
Write-Host "Failed to download Python. The following exception was raised:" -ForegroundColor Red
40+
Write-Host $_.exception -ForegroundColor Red
41+
42+
Exit 1
43+
}
44+
}
45+
46+
function Install-Python {
47+
Write-StepTitle "Installing Python. Do not close this window."
48+
Write-Host "Installing Python. Do not close this window."
49+
$install = Start-Process $PythonInstaller -ArgumentList "InstallAllUsers=1 PrependPath=1" -PassThru -wait
50+
if ($install.ExitCode -eq 0) {
51+
Write-Host "Installation completed successfully." -ForegroundColor Green
52+
} elseif ($install.ExitCode -eq 1602) {
53+
Write-Host "Installer was exited by the user." -ForegroundColor Red
54+
Exit 1
55+
} else {
56+
Write-Host "Installation failed with exit code $install.ExitCode" -ForegroundColor Red
57+
Exit 1
58+
}
59+
}
60+
61+
function Update-UserEnvironmentPath {
62+
Write-StepTitle "Updating Environment PATH of this shell."
63+
$env:Path =
64+
[System.Environment]::GetEnvironmentVariable("Path","Machine") +
65+
";" +
66+
[System.Environment]::GetEnvironmentVariable("Path","User")
67+
}
68+
69+
function Install-Virtualenv {
70+
Write-StepTitle "Installing virtualenv"
71+
Invoke-Expression "pip install virtualenv --target $PSScriptRoot\virtualenv --upgrade"
72+
}
73+
74+
$PythonExecutable = Get-PythonExecutable
75+
if ($PythonExecutable.count -eq 0) {
76+
Get-PythonMSI
77+
Install-Python
78+
Update-UserEnvironmentPath
79+
Remove-Item $PythonInstaller
80+
} else {
81+
Write-Host "Python 3.7.3 is already installed." -ForegroundColor Green
82+
}
83+
Install-Virtualenv

0 commit comments

Comments
 (0)