Merge pull request #265 from mesosphere/dcos-993

[ADD] DCOS-993 Install script functionality to optionally add dcos to path
This commit is contained in:
Sunil Shah
2015-09-22 15:15:42 -07:00
2 changed files with 104 additions and 8 deletions

View File

@@ -4,7 +4,53 @@ set -o errexit -o pipefail
usage() usage()
{ # Show usage information. { # Show usage information.
echo "$(basename "$(test -L "$0" && readlink "$0" || echo "$0")") <installation-path> <dcos-url>" echo "$(basename "$(test -L "$0" && readlink "$0" || echo "$0")") <installation-path> <dcos-url> [--add-path yes/no]"
}
post_install_message()
{
echo 'Finished installing and configuring DCOS CLI.'
echo ''
echo 'Run this command to set up your environment and to get started:'
echo "source $1 && dcos help"
}
RC_NAME=""
write_to_profile()
{
echo "" >> ~/"$2";
echo "# path to the DCOS CLI binary" >> ~/"$2";
echo "if [[ \"\$PATH\" != *\"$1\"* ]];" >> ~/"$2";
echo " then export PATH=\$PATH:$1;" >> ~/"$2";
echo "fi" >> ~/"$2";
}
add_dcos_path_to_profile()
{
UNAME=`uname`
case "$UNAME" in
Linux ) RC_NAME=".bashrc";;
Darwin ) RC_NAME=".bash_profile";;
CYGWIN* ) RC_NAME=".bashrc";;
MINGW* ) RC_NAME=".profile";;
* ) RC_NAME=".bashrc";;
esac
write_to_profile "$1" "$RC_NAME"
}
prompt_add_dcos_path_to_profile()
{
while true; do
echo ""
read -p "Modify your bash profile to add DCOS to your PATH? [yes/no] " ANSWER
echo ""
case "$ANSWER" in
[Yy]* ) add_dcos_path_to_profile "$1"; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
} }
check_pip_version() check_pip_version()
@@ -70,7 +116,22 @@ dcos config set package.cache ~/.dcos/cache
dcos config set package.sources '["https://github.com/mesosphere/universe/archive/version-1.x.zip"]' dcos config set package.sources '["https://github.com/mesosphere/universe/archive/version-1.x.zip"]'
dcos package update dcos package update
echo 'Finished installing and configuring DCOS CLI.' ADD_PATH=""
echo '' while [ $# -gt 0 ]; do
echo 'Run this command to set up your environment and to get started:' case "$1" in
echo "source $ENV_SETUP && dcos help" --add-path ) ADD_PATH="$2"; break;;
* ) shift;;
esac
done
case "$ADD_PATH" in
[Yy]* ) add_dcos_path_to_profile "$VIRTUAL_ENV_PATH/bin";;
[Nn]* ) ;;
* ) prompt_add_dcos_path_to_profile "$VIRTUAL_ENV_PATH/bin";;
esac
if [ -z "$RC_NAME" ]; then
post_install_message "$ENV_SETUP"
else
post_install_message "~/$RC_NAME"
fi

View File

@@ -1,9 +1,11 @@
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)] param([Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string] [string]
$installation_path, $installation_path,
[Parameter(Mandatory=$true,ValueFromPipeline=$true)] [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
[string] [string]
$dcos_url $dcos_url,
[string]
$add_path
) )
if (-Not(Get-Command python -errorAction SilentlyContinue)) if (-Not(Get-Command python -errorAction SilentlyContinue))
@@ -106,7 +108,40 @@ dcos config set package.sources '[\"https://github.com/mesosphere/universe/archi
dcos package update 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 "Finished installing and configuring DCOS CLI."
echo "" echo ""
echo "Run this command to set up your environment and to get started:" echo "Run this command to set up your environment and to get started:"
echo "& $installation_path\Scripts\activate.ps1; dcos help" echo "& $ACTIVATE_PATH; dcos help"