summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xstsci-conda-install208
1 files changed, 208 insertions, 0 deletions
diff --git a/stsci-conda-install b/stsci-conda-install
new file mode 100755
index 0000000..60ed0f7
--- /dev/null
+++ b/stsci-conda-install
@@ -0,0 +1,208 @@
+#!/bin/bash
+
+# Exit values are keyed as follows:
+# 0 = No error
+# 1 < 250 = Easy fix
+# 250 <= 255 = Will not fix
+
+#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
+
+OS=`uname -s`
+PLATFORM=`uname -p`
+FETCH=
+FETCH_ARGS=
+
+CONTINUUM_BASE=https://repo.continuum.io/miniconda
+CONTINUUM_RELEASE=Miniconda3
+CONTINUUM_VERSION=latest
+CONTINUUM_ARCH=x86_64
+CONTINUUM_PLATFORM=
+CONTINUUM_EXT=".sh"
+
+STSCI_BASE=http://ssb.stsci.edu
+STSCI_RELEASES=(
+ conda
+ conda-x
+ conda-dev
+)
+
+# Update this as needed. We cannot simply rely on "2" or "3" conventions here because of how repos store data.
+PYTHON_VERSIONS=(
+ 2.7
+ 3.5
+)
+_VERSION=$(echo ${CONTINUUM_RELEASE} | awk '{print tolower($0)}')
+_INSTALL_PATH="$HOME/$_VERSION"
+INSTALL_PATH="$_INSTALL_PATH"
+INSTALL_ALTERNATE_PATH="$HOME/$_VERSION"_stsci
+
+function repo_alive
+{
+ retval=1
+ local REPO="$1"
+ if [ -z "$REPO" ]; then
+ echo "repo_alive requires an argument." >&2
+ echo "usage: repo_alive {repo_url}" >&2
+ exit 1
+ fi
+ REPO_ALIVE="$REPO/repo_alive.txt"
+ ALIVE_FILE="$(basename $REPO_ALIVE)"
+
+ $FETCH $FETCH_ARGS $REPO_ALIVE &>/dev/null
+
+ if [ -f "$ALIVE_FILE" ]; then
+ rm -f "$ALIVE_FILE"
+ retval=0
+ fi
+
+ return $retval
+}
+
+function check_reinstall
+{
+ # Note, we don't care about the "root" environment. People can install whatever they want.
+ 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"
+
+ conda list -n "$environ" -f '^stsci$|^stsci-.*' &>/dev/null
+ retval=$?
+
+ if [[ $retval > 0 ]]; then
+ continue
+ else
+ for release in "${STSCI_RELEASES[@]}"
+ do
+ if [[ "stsci-$release" == $environ ]]; then
+ ((conflict++))
+ fi
+ done
+ fi
+
+ if [[ $conflict > 0 ]]; then
+ msg="CONFLICT"
+ fi
+
+ printf "+ %-20s:%20s\n" "$environ" "$msg"
+
+ done
+ echo
+
+ 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
+
+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
+
+ check_reinstall
+ found=$?
+ if [[ $found > 0 ]]; then
+ echo "To overwrite an existing installation:
+ ./$(basename $0) --reinstall"
+ echo
+ echo "To squelch this behavior and perform a fresh installation:
+ ./$(basename $0) --ignore-conflicts"
+ exit 4
+ fi
+
+ 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
+
+if [[ $INSTALL_PATH != $_INSTALL_PATH ]]; then
+ # User picked an alternative installation
+ echo "Alternative installation path: $INSTALL_PATH"
+ # Do installation
+ $FETCH $FETCH_ARGS $CONTINUUM_URL
+ chmod +x "$INSTALLER"
+ ./"$INSTALLER" -p "$INSTALL_PATH"
+
+ # This allows us to continue without having to recycle the environment:
+ export PATH="$INSTALL_PATH/bin:$PATH"
+
+ # Fall through to repository installation
+fi
+
+
+# Repository installation
+for python_version in ${PYTHON_VERSIONS[@]}
+do
+ for release in ${STSCI_RELEASES[@]}
+ 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
+ done
+done
+