#!/bin/sh function internet_error { echo "ERROR. There seems to be a problem with your internet connection." echo " I was unable to download the following URL:" echo $1 echo " Please fix the problem and try again." exit 1 } CARPY_INSTALL_URL=http://code.obs.carnegiescience.edu/carnegie-python-distribution/obtaining-carpy CARPY_FTP=ftp://ftp.obs.carnegiescience.edu/pub/CarPy/binaries GCC_FTP=ftp://ftp.obs.carnegiescience.edu/pub/CarPy/gcc CARPY_VERSIONS=${CARPY_FTP}/Versions # This script attempts to download/install a binary copy of CarPy. # It tests as much as possible that you have everything needed # First we check for the usual suspects env | grep -q -i scisoft if [ ! $? ] ; then echo "You have scisoft enabled in your environment. This will" echo "conflict with CarPy and you should disable it before" echo "running this script." exit 1 fi env | grep -q -i ureka if [ ! $? ] ; then echo "You have Ureka enabled in your environment. This will" echo "conflict with CarPy and you should disable it (use" echo "ur_forget) before running this script." exit 1 fi # Check that /usr/local exists and we can write to it if [ ! -d /usr/local/CarPy ] ; then mkdir -p /usr/local/CarPy 2> /dev/null if [ ! $? -eq 0 ] ; then echo "ERROR: You must run this script with root privileges" echo "Try again as root, or use 'sudo'" exit 1 fi else echo "WARNING: /usr/local/CarPy already exists. Do you want me to" echo "continue and over-write the existing installation? (yes/no)" read answer case "$answer" in yes) echo ;; *) exit 0 ;; esac touch /usr/local/CarPy/testfile 2> /dev/null if [ ! $? -eq 0 ] ; then echo "ERROR: You must run this script with root privileges" echo "Try again as root, or use 'sudo'" exit 1 fi rm /usr/local/CarPy/testfile fi # See which application we use for retrieving tar files CURL=$(which curl) || CURL='nope' WGET=$(which wget) || WGET='nope' if [ "$CURL" = "nope" -a "$WGET" = "nope" ] ; then echo "Error: you don't have wget or curl installed. You will either have to" echo "install one of these tools or you will have to install CarPy by hand." echo "Please see:" echo $CARPY_INSTALL_URL exit 1 fi if [ $CURL = 'nope' ] ; then download="$WGET --quiet" else download="$CURL -O -s" fi # Check the binary version OSSYS=$(uname -s) if [ "$OSSYS" = 'Darwin' ] ; then export ARCHSYS=`uname -s` export ARCHMODEL=`uname -m` export OSVER=`sw_vers -productVersion | /usr/bin/python -ESc "import sys; print '.'.join(sys.stdin.read().split('.')[:2])"` elif [ "$OSSYS" = "Linux" ] ; then export ARCHSYS=`lsb_release -i -s` export ARCHMODEL=`arch` export OSVER=`lsb_release -r -s | cut -d . -f1-2` fi # Download the universal tarfile cd /usr/local echo "Downloading version info from repository..." $download $CARPY_VERSIONS || internet_error $CARPY_VERSIONS echo "Done!" echo "Your system has been identified as the following:" TAG=${ARCHSYS}.${OSVER}.${ARCHMODEL} echo $TAG echo "Checking for matching binary build..." grep -q $TAG Versions if [ ! $? -eq 0 ] ; then echo "Sorry, your system architecture does not have a binary version in our" echo "database. You will have to install CarPy from source. See:" echo "$CARPY_SRC_INSTALL" exit 0 fi read -r dummy UNIV_TAR BUILD GCC <<< $(grep $TAG Versions) echo "Found!" if [ "$UNIV_TAR" = "Package" ] ; then echo "Your OS has a binary package file (.pkg or RPM) that you can find" echo "at the following URL:" echo "https://code.obs.carnegiescience.edu/carnegie-python-distribution/downloads" echo "Please download that package file and install it manually" exit 0 fi echo "Downloading universal archive..." $download ${CARPY_FTP}/${UNIV_TAR} || internet_error ${CARPY_FTP}/${UNIV_TAR} tar -zxf $UNIV_TAR echo "Done!" cd CarPy # At this point, we need to see if a gcc/gfortran is needed if [ ! -z "$GCC" ] ; then echo "Fetching $GCC..." $download ${GCC_FTP}/${GCC} || internet_error ${GCC_FTP}/${GCC} echo "Done!" GCC_TAR=$(basename $GCC) if [ -e /usr/local/bin/gcc -o -e /usr/local/bin/gfortran ] ; then echo "WARNING!!! In order to use this binary version of CarPy, we need" echo "to install a custom gcc/gfortran suite in /usr/local. But you" echo "seem to have one already. Do you wish to proceed and over-write" echo "the gcc/gfortran located in /usr/local? (no/yes)" read answer case "$answer" in yes) echo ;; *) echo "Aborting! Probably best if you build CarPy from source. See:" echo $CARPY_SRC_INSTALL exit 0 ;; esac fi cd / echo "Extracting gfortran build to /usr/local..." tar -zxf /usr/local/CarPy/$GCC_TAR echo "Done!" fi # Now we get the binary build cd /usr/local/CarPy echo "Fetching ${BUILD}..." $download ${CARPY_FTP}/${BUILD} || internet_error ${CARPY_FTP}/${BUILD} echo "Done!" echo "Extracting binary to /usr/local/CarPy/builds..." tar -zxf $BUILD echo "Done!" rm $BUILD cd .. rm $UNIV_TAR Versions # Check if we need X11 if [ "$ARCHSYS" = "Darwin" ] ; then Xversion=`xdpyinfo | grep -i "X.org version" | awk '{print $3}'` || Xversion="nope" if [ "$Xversion" = "nope" ] ; then echo "Sorry, you don't seem to have X installed. Please download and " echo "install Xquartz from www.xquartz.org. Then run this script again" exit 1 fi if [ -f ${PYTHONBASE}/Xversion.dat ] ; then test=$(grep $Xversion ${PYTHONBASE}/Xversion.dat) if [ $? -eq 1 ] ; then this=$(head -1 ${PYTHONBASE}/Xversion.dat) echo "Warning: This CarPy was built with X.org version $this, but" echo "you have version $Xversion. This may be an issue and you may" echo "need to build from source if you get X-related errors or" echo "get errors about missing VTK objects (e.g., vtkGridTransform)." fi fi fi # Next, check to see if there are RPMS to look for that may be missing: if [ -f ${PYTHONBASE}/RPMS ] ; then missing=no for rpm in $(cat ${PYTHONBASE}/RPMS) ; do rpm -q $rpm > /dev/null if [ $? -ne 0 ] ; then missing=yes break fi done if [ "$missing" = "yes" ] ; then echo "*******************************************************************" echo "You are missing the following RPMs. Please install them using your" echo "system's package manager before running CarPy:" for rpm in $(cat ${PYTHONBASE}/RPMS) ; do rpm -q $rpm > /dev/null if [ $? -ne 0 ] ; then echo $rpm fi done echo "*******************************************************************" fi fi # Check to see if there are packages to look for that may be missing: if [ -f ${PYTHONBASE}/PKGS ] ; then missing=no for pkg in $(cat ${PYTHONBASE}/PKGS) ; do dpkg -l $pkg > /dev/null if [ $? -ne 0 ] ; then missing=yes break fi done if [ "$missing" = "yes" ] ; then echo "*******************************************************************" echo "You are missing the following packages. Please install them using" echo "your system's package manager (e.g., apt-get) before running CarPy:" for pkg in $(cat ${PYTHONBASE}/PKGS) ; do dpkg -l $pkg > /dev/null if [ $? -ne 0 ] ; then echo $pkg fi done echo "*******************************************************************" fi fi # Check to see if there are other packages to look for that may be missing: if [ -f ${PYTHONBASE}/PKGS_OSX ] ; then missing=no for pkg in $(cat ${PYTHONBASE}/PKGS_OSX) ; do # Expect pkg,message tuples read -ra arr <<< "$pkg" # test or pkg, if not there, print message if [ ! -f ${arr[0]} ] ; then missing=yes break fi done if [ "$missing" = "yes" ] ; then echo "*******************************************************************" echo "You are missing the following packages. Please install them " echo "according to the associated message. 'brew install' messages" echo "require that you first install homebrew (https://brew.sh)" for pkg in $(cat ${PYTHONBASE}/PKGS) ; do read -ra arr <<< "$pkg" # test or pkg, if not there, print message if [ ! -f ${arr[0]} ] ; then echo ${arr[@]:1} fi done echo "*******************************************************************" fi fi echo "" echo "Done! If all went well, CarPy is now installed on your system. In order" echo "to activate it, use either of the following commands:" echo "bash/sh: . /usr/local/CarPy/Setup.bash" echo "csh/tcsh: source /usr/local/CarPy/Setup.csh"