CarPy Installation Script

This file is a shell script designed for downloading and installing CarPy, a specialized software package for astronomical data analysis, on Unix-based systems. It includes checks for internet connection, existing installations, necessary tools (like wget or curl), and potential environment conflicts (such as with scisoft or Ureka). It also handles the retrieval and installation of the appropriate CarPy version based on the system's architecture, additional required packages, and necessary gcc/gfortran dependencies. Finally, it guides the user through activating CarPy on their system.

#!/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
 
# Download the universal tarfile
cd /usr/local
echo "Downloading version info from repository..."
$download $CARPY_VERSIONS || internet_error $CARPY_VERSIONS
echo "Done!"
UNIV_TAR=$(grep universal Versions | awk '{print $2}')
echo "Downloading universal archive..."
$download ${CARPY_FTP}/${UNIV_TAR} || internet_error ${CARPY_FTP}/${UNIV_TAR}
tar -zxf $UNIV_TAR
echo "Done!"
cd CarPy
. Setup.bash > /dev/null 2> /dev/null
 
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
line=$(grep $TAG ../Versions)
BUILD=$(echo $line | awk '{print $2}')
echo "Found!"
 
# At this point, we need to see if a gcc/gfortran is needed
GCC=$(echo $line | awk '{print $3}')
if [ "$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 CarPy_*_universal.tgz
 
# 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
 
# Lastly, check to see if there are RPMS 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
 
 
 
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"