diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2016-01-07 17:22:43 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2016-01-07 17:22:43 -0500 |
commit | d0ec7839ed451aab0dbfde69a284b2f4243984a1 (patch) | |
tree | c3a981ab407318dd9e10c8fcc1051ec6f557b71c | |
parent | ce9f6f3fddd521f9eccd0481aa44d1e0fda60292 (diff) | |
download | stsci-conda-install-d0ec7839ed451aab0dbfde69a284b2f4243984a1.tar.gz |
-rwxr-xr-x | stsci-conda-install | 347 |
1 files changed, 247 insertions, 100 deletions
diff --git a/stsci-conda-install b/stsci-conda-install index 60ed0f7..825ce9b 100755 --- a/stsci-conda-install +++ b/stsci-conda-install @@ -8,6 +8,10 @@ #testing #export PATH=/home/jhunk/.local/bin:/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/home/jhunk/bin:/usr/local/sbin:/usr/sbin +# +# Begin global configuration +# + OS=`uname -s` PLATFORM=`uname -p` FETCH= @@ -27,7 +31,8 @@ STSCI_RELEASES=( conda-dev ) -# Update this as needed. We cannot simply rely on "2" or "3" conventions here because of how repos store data. +# Update this as needed. +# We cannot simply on setting "2" or "3" here because of how repos store data. PYTHON_VERSIONS=( 2.7 3.5 @@ -36,6 +41,36 @@ _VERSION=$(echo ${CONTINUUM_RELEASE} | awk '{print tolower($0)}') _INSTALL_PATH="$HOME/$_VERSION" INSTALL_PATH="$_INSTALL_PATH" INSTALL_ALTERNATE_PATH="$HOME/$_VERSION"_stsci +INSTALL_REQUIRED=0 +REINSTALL=0 + +# +# Begin function delarations +# + +function preamble +{ +cat << 'PREAMBLE' +################################################################################ + + ____ _____ ____ ___ + / ___||_ _|/ ___| ___ |_ _| + \___ \ | | \___ \ / __| | | + ___) | | | ___) || (__ | | + |____/ |_| |____/ \___||___| + + Space Telecope Science Institute + Distribution Installer + +################################################################################ + +If you have any questions or problems, please send an email to <help@stsci.edu> + +################################################################################ +PREAMBLE +echo "Press any key to continue..." +read accept +} function repo_alive { @@ -59,27 +94,35 @@ function repo_alive return $retval } -function check_reinstall +function check_conflicts { - # Note, we don't care about the "root" environment. People can install whatever they want. + # Note, we do not care about the user's "root" or various builtin environments. + # This does not restrict people from installing our software on their own terms. local conflict=0 local ENVIRONMENTS=`conda env list | egrep -v '#|^_|^root' | awk '{ print $1 }'` + echo "Scanning Conda environment for conflicts:" for environ in $ENVIRONMENTS do msg="NO CONFLICT" + # Check for metapackages in current $environ conda list -n "$environ" -f '^stsci$|^stsci-.*' &>/dev/null retval=$? if [[ $retval > 0 ]]; then + # Found nothing. continue else - for release in "${STSCI_RELEASES[@]}" + for python_version in "${PYTHON_VERSIONS[@]}" do - if [[ "stsci-$release" == $environ ]]; then - ((conflict++)) - fi + for release in "${STSCI_RELEASES[@]}" + do + if [[ "stsci-$release-$python_version" == $environ ]]; then + # Our environment is already installed. + ((conflict++)) + fi + done done fi @@ -95,114 +138,218 @@ function check_reinstall return $conflict } -case "$OS" in - Linux) - CONTINUUM_PLATFORM=Linux - FETCH="wget" - FETCH_ARGS="-c" - ;; - Darwin) - CONTINUUM_PLATFORM=MacOSX - FETCH="curl" - FETCH_ARGS="-O" - ;; -esac - -case "$PLATFORM" in - i*86) - CONTINUUM_ARCH=x86 - ;; -esac - -if [[ $CONTINUUM_ARCH != x86_64 ]]; then - echo "STScI does not support '$ARCH' packages." - exit 255 -fi +function init_specs +{ + case "$OS" in + Linux) + CONTINUUM_PLATFORM=Linux + FETCH="wget" + FETCH_ARGS="-c" + ;; + Darwin) + CONTINUUM_PLATFORM=MacOSX + FETCH="curl" + FETCH_ARGS="-O" + ;; + esac + + case "$PLATFORM" in + i*86) + CONTINUUM_ARCH=x86 + ;; + esac -if [ -z "$CONTINUUM_PLATFORM" ]; then - echo "STScI does not support '$OS'." - exit 254 -fi + INSTALLER="$CONTINUUM_RELEASE-$CONTINUUM_VERSION-$CONTINUUM_PLATFORM-$CONTINUUM_ARCH${CONTINUUM_EXT}" + CONTINUUM_URL="$CONTINUUM_BASE/$INSTALLER" +} -if [ ! -x "`which $FETCH`" ]; then - echo "Please install '$FETCH'. Unable to continue." - exit 253 -fi +function check_sanity +{ + if [[ $CONTINUUM_ARCH != x86_64 ]]; then + echo "STScI does not support '$ARCH' packages." + exit 255 + fi + + if [ -z "$CONTINUUM_PLATFORM" ]; then + echo "STScI does not support '$OS'." + exit 254 + fi + + if [ ! -x "`which $FETCH`" ]; then + echo "Please install '$FETCH'. Unable to continue." + exit 253 + fi +} -INSTALLER="$CONTINUUM_RELEASE-$CONTINUUM_VERSION-$CONTINUUM_PLATFORM-$CONTINUUM_ARCH${CONTINUUM_EXT}" -CONTINUUM_URL="$CONTINUUM_BASE/$INSTALLER" -# Check for presence of [mini|ana]conda -CONDA=`which conda 2>/dev/null` -if [ -x "$CONDA" ]; then - echo "An Anaconda installation is present on your system: $CONDA" - echo +function do_preinstall +{ + local CONDA=`which conda 2>/dev/null` - check_reinstall - found=$? - if [[ $found > 0 ]]; then - echo "To overwrite an existing installation: - ./$(basename $0) --reinstall" + # Pass 1 - If not on PATH, check if installed (by us) + if [ ! -x "$CONDA" ]; then + echo -n "Checking for inactive installation..." + if [[ -d $INSTALL_PATH ]]; then + echo "found (assimilating)" + echo + export PATH=$INSTALL_PATH/bin:$PATH + CONDA=`which conda 2>/dev/null` + else + echo "none found" + echo + INSTALL_REQUIRED=1 + fi + fi + + # Pass 2 - If on PATH, setup installer + if [ -x "$CONDA" ]; then + printf "An Anaconda installation is present on your system:\n\t$CONDA\n" echo - echo "To squelch this behavior and perform a fresh installation: - ./$(basename $0) --ignore-conflicts" - exit 4 + + /bin/echo -n "Do you wish to use your existing conda installation? (recommended) [Y/n]" + read choice + case "$choice" in + N*|n*) + INSTALL_PATH="$INSTALL_ALTERNATE_PATH" + INSTALL_REQUIRED=1 + ;; + *) + ;; + esac + + check_conflicts + found=$? + if [[ $found > 0 ]]; then + echo "Conflicts discovered: $found" + echo + echo "The following operation will:" + echo "* REMOVE all conflicting distributions" + echo "* REINSTALL all distributions" + echo + echo "CUSTOMIZATIONS MADE TO THESE ENVIRONMENTS WILL BE *LOST*" + echo + echo "Hint:" + echo "Refer to [url_here] to learn how to properly *update* packages." + echo + /bin/echo -n "Do you wish to continue? [y/N] " + read choice + case "$choice" in + Y*|y*) + # Nuke the site from orbit + REINSTALL=1 + ;; + *) + exit 0 + ;; + esac + echo + fi + fi + echo +} - echo "Do you wish to use your existing conda installation? (recommended) [Y/n]" - read choice - case "$choice" in - N*|n*) - INSTALL_PATH="$INSTALL_ALTERNATE_PATH" - ;; - *) - ;; - esac -fi +function do_install_continuum +{ + if [[ $INSTALL_REQUIRED == 0 ]]; then + return 0 + fi -if [[ $INSTALL_PATH != $_INSTALL_PATH ]]; then - # User picked an alternative installation - echo "Alternative installation path: $INSTALL_PATH" - # Do installation - $FETCH $FETCH_ARGS $CONTINUUM_URL + # Perform scripted installation + echo "Downloading ${CONTINUUM_URL}..." + $FETCH $FETCH_ARGS $CONTINUUM_URL 2>/dev/null chmod +x "$INSTALLER" - ./"$INSTALLER" -p "$INSTALL_PATH" + + echo "Executing ${INSTALLER}..." + ./"$INSTALLER" -b -p "$INSTALL_PATH" + + # If the miniconda installer fails, we need to stop. + install_status=$? + if [[ $install_status != 0 ]]; then + echo "Installation failed. Unable to continue." >&2 + exit 6 + fi - # This allows us to continue without having to recycle the environment: + # Assimilate new installation export PATH="$INSTALL_PATH/bin:$PATH" - # Fall through to repository installation -fi + echo "Control returned to $(basename $0)" +} +function do_install_stsci +{ + # Repository installation -# Repository installation -for python_version in ${PYTHON_VERSIONS[@]} -do - for release in ${STSCI_RELEASES[@]} + if [[ $REINSTALL != 0 ]]; then + install_type='re' + fi + echo "Installation in progress..." + for python_version in ${PYTHON_VERSIONS[@]} do - STSCI_URL="$STSCI_BASE/$release" - release="stsci-$release-$python_version" - logfile="/tmp/install-${release}.log" - - repo_alive "$STSCI_URL" - alive=$? - if [[ $alive < 1 ]]; then - echo "$release repository is up." - else - echo "$release repository is down. (installation skipped)" - continue - fi - - /bin/echo -n "Installing $release (monitor progress with: tail -f $logfile) ... " - ( conda create -y -n "$release" -c "$STSCI_URL" python=$python_version stsci 2>&1 ) > "$logfile" - retval=$? - - if [[ $retval > 0 ]]; then - printf "failed\n\tA problem occurred while installing %s. Please review the installation log.\n" "$release" - echo - else - echo "done" - fi + echo "+ Performing Python $python_version ${install_type}installation:" + for release in ${STSCI_RELEASES[@]} + do + STSCI_URL="$STSCI_BASE/$release" + release="stsci-$release-$python_version" + logfile="/tmp/install-${release}.log" + + /bin/echo -n "- $release ... " + repo_alive "$STSCI_URL" + alive=$? + if [[ $alive > 0 ]]; then + echo "skipped (repository is unavailable)" + continue + fi + + if [[ $REINSTALL != 0 ]]; then + ( conda env remove -y -n "$release" 2>&1 ) >/dev/null + fi + ( conda create -q -y -n "$release" -c "$STSCI_URL" python=$python_version stsci 2>&1 ) > "$logfile" + retval=$? + + if [[ $retval > 0 ]]; then + printf "failed\nA problem occurred while installing %s\nPlease review the installation log: %s\n" "$release" "$logfile" >&2 + echo + # die... + return 1 + else + echo "complete" + fi + done + echo done -done + return 0 +} + +function do_overview +{ + local ENVIRONMENTS="`conda env list \ + | egrep '^stsci-conda.*' \ + | awk '{ print $1 }'`" + + echo "Activate the desired environment with *one* the following:" + for environ in $ENVIRONMENTS + do + printf "source activate %s\n" "$environ" + done + echo +} + +# +# Main +# + +preamble +init_specs +check_sanity + +do_preinstall +do_install_continuum +do_install_stsci + +show_overview=$? +if [[ $show_overview == 0 ]]; then + do_overview +fi +echo |