1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string]
$installation_path,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string]
$dcos_url,
[string]
$add_path
)
if (-Not(Get-Command python -errorAction SilentlyContinue))
{
echo "The program 'python' could not be found. Make sure that 'python' is installed and that its directory is included in the PATH system variable."
exit 1
}
$PYTHON_VERSION = (python --version) 2>&1
if ($PYTHON_VERSION -match "[0-9]+.[0-9]+") {
$PYTHON_VERSION = $matches[0]
if (-Not (($PYTHON_VERSION -eq "2.7") -Or ($PYTHON_VERSION -eq "3.4"))) {
echo "Python must be version 2.7 or 3.4. Aborting."
exit 1
}
}
if (-Not(Get-Command pip -errorAction SilentlyContinue))
{
echo "The program 'pip' could not be found. Make sure that 'pip' is installed and that its directory (eg 'C:\Python27\Scripts') is included in the PATH system variable."
exit 1
}
$PIP_VERSION = (pip -V)
"$PIP_VERSION" -match "[0-9]+\.[0-9]+"
if ([double]$matches[0] -le 1.4) {
echo "Pip version must be greater than 1.4. Aborting."
exit 1
}
if (-Not(Get-Command virtualenv -errorAction SilentlyContinue))
{
echo "The program 'virtualenv' could not be found. Make sure that it has been installed with the 'pip' Python package program."
exit 1
}
$VIRTUAL_ENV_VERSION = (virtualenv --version)
$VIRTUAL_ENV_VERSION -match "[0-9]+"
if ($matches[0] -lt 12) {
echo "Virtualenv version must be 12 or greater. Aborting."
exit 1
}
if (-Not(Get-Command git -errorAction SilentlyContinue))
{
echo "The program 'git' could not be found. Make sure that 'git' is installed and that its directory is included in the PATH system variable."
exit 1
}
echo "Installing DCOS CLI from PyPI..."
echo ""
if (-Not([System.IO.Path]::IsPathRooted("$installation_path"))) {
$installation_path = Join-Path (pwd) $installation_path
}
if (-Not( Test-Path $installation_path)) {
mkdir $installation_path
}
& virtualenv $installation_path
& $installation_path\Scripts\activate
[int]$PYTHON_ARCHITECTURE=(python -c 'import struct;print( 8 * struct.calcsize(\"P\"))')
if ($PYTHON_ARCHITECTURE -eq 64) {
& $installation_path\Scripts\easy_install "http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20219/pywin32-219.win-amd64-py$PYTHON_VERSION.exe" 2>&1 | out-null
} else {
& $installation_path\Scripts\easy_install "http://downloads.sourceforge.net/project/pywin32/pywin32/Build%20219/pywin32-219.win32-py$PYTHON_VERSION.exe" 2>&1 | out-null
}
if ($env:DCOS_CLI_VERSION) {
& $installation_path\Scripts\pip install --quiet "dcoscli==$env:DCOS_CLI_VERSION"
} else {
& $installation_path\Scripts\pip install --quiet "dcoscli"
}
$env:Path="$env:Path;$installation_path\Scripts\"
$DCOS_CONFIG="$env:USERPROFILE\.dcos\dcos.toml"
if (-Not(Test-Path $DCOS_CONFIG)) {
mkdir "$env:USERPROFILE\.dcos"
New-Item $DCOS_CONFIG -type file
}
[Environment]::SetEnvironmentVariable("DCOS_CONFIG", "$DCOS_CONFIG", "User")
$env:DCOS_CONFIG = $DCOS_CONFIG
dcos config set core.reporting true
dcos config set core.dcos_url $dcos_url
dcos config set core.timeout 5
dcos config set package.cache $env:temp\dcos\package-cache
dcos config set package.sources '[\"https://github.com/mesosphere/universe/archive/version-1.x.zip\"]'
dcos package update
$ACTIVATE_PATH="$installation_path\Scripts\activate.ps1"
function AddToPath ($AddedLocation)
{
$Reg = "Registry::HKCU\Environment"
$OldPath = (Get-ItemProperty -Path "$Reg" -Name PATH).Path
$NewPath = $OldPath + ';' + $AddedLocation
Set-ItemProperty -Path "$Reg" -Name PATH –Value $NewPath
$script:ACTIVATE_PATH="activate.ps1"
}
function PromptAddToPath ($AddedLocation)
{
$message = "Modify your Environment to add DCOS to your PATH?"
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", `
"Yes, add DCOS to PATH."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", `
"No, do not add DCOS to PATH."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice("", $message, $options, 0)
if ($result -eq 0)
{
AddToPath "$AddedLocation"
}
}
switch -regex ($add_path)
{
"[Yy].*" {AddToPath "$installation_path\Scripts"; break}
"[Nn].*" {break}
default {PromptAddToPath "$installation_path\Scripts"}
}
echo "Finished installing and configuring DCOS CLI."
echo ""
echo "Run this command to set up your environment and to get started:"
echo "& $ACTIVATE_PATH; dcos help"
|