Index: ../trunk-jpl/packagers/macosx/install.sh
===================================================================
--- ../trunk-jpl/packagers/macosx/install.sh	(revision 18410)
+++ ../trunk-jpl/packagers/macosx/install.sh	(revision 18411)
@@ -1,7 +1,5 @@
 #!/bin/bash
 
-# Environment Variables
-#
 # ISSM_DIR and MATLAB_DIR must be set correctly.
 # {{{
 if [ "${ISSM_DIR}x" == "x" ]; then
@@ -25,114 +23,97 @@
 fi
 # }}}
 
-cd $ISSM_DIR
+#List of external pakages to be installed and their installation scripts
+EXTERNALPACKAGES="autotools install.sh                
+                  mpich     install-3.0-macosx64-static.sh
+                  cmake     install.sh                
+                  petsc     install-3.5-macosx64-static.sh
+                  triangle  install-macosx64.sh "
 
-# Externalpackages
+# Install Externalpackages
 # {{{
-echo ""
-echo "Installing external packages..."
-echo ""
+cd $ISSM_DIR/externalpackages
 
-cd "$ISSM_DIR/externalpackages/matlab"
-echo '---------------------------------'
-echo "Linking Matlab"
-echo '---------------------------------'
-ln -s $MATLAB_DIR ./install
+#number of packages: 
+NUMPACKAGES=$(($(echo $EXTERNALPACKAGES | wc -w )/2))
 
-cd "$ISSM_DIR/externalpackages/cmake"
-echo '---------------------------------'
-echo "Installing CMAKE"
-echo '---------------------------------'
-./install.sh $1 &> /dev/null
+for ((i=1;i<=$NUMPACKAGES;i++))
+do
+	NUM1=$((2*$i-1))
+	NUM2=$((2*$i))
+	PACKAGENAME=$(echo $EXTERNALPACKAGES | cut -d " " -f $NUM1-$NUM1)
+	PACKAGEINST=$(echo $EXTERNALPACKAGES | cut -d " " -f $NUM2-$NUM2)
 
-if [ $? -ne 0 ]; then
-   echo "FAILED TO INSTALL CMAKE!"
-   exit 1;
-fi
+	cd $PACKAGENAME
 
-cd "$ISSM_DIR/externalpackages/autotools"
-echo '---------------------------------'
-echo "Installing Autotools"
-echo '---------------------------------'
-./install.sh &> /dev/null
+	#tricky part here. We do not want to reinstall this package if it's already installed
+	#and the svn file which does the install has not be modified! To keep track of 
+	#this, we check the current svn version against the "last changed" revision number.  If they 
+	#are the same, we reinstall the package. 
+	current_version=`svnversion`
+	last_changed_version=`svn info $PACKAGEINST | grep "Last Changed Rev" | awk '{printf("%s\n",$4);}'`
 
-if [ $? -ne 0 ]; then
-   echo "FAILED TO INSTALL AUTOTOOLS!"
-   exit 1;
-fi
+	if [[ $current_version == $last_changed_version ]]; then 
+		#go ahead and reinstall. 
+		echo "For $PACKAGENAME: svn current_version  is $current_version and last changed version is $last_changed_version"
+		echo "Triggering new install of $PACKAGENAME"
+		install_test=1
+	else
+		#ok, we want to skip, unless the package is not installed: 
+		if [ -d install ]; then 
+			#could be empty, signaling a failed previous install: 
+			if [ "$(ls -A install)" ];then
+				echo "For $PACKAGENAME: svn current_version  is $current_version and last changed version is $last_changed_version"
+				echo "and install directory exists, so skipping install of $PACKAGENAME"
+				install_test=0;
+			else
+				echo "For $PACKAGENAME: svn current_version  is $current_version and last changed version is $last_changed_version"
+				echo "and install directory exists, however, it is empty, so triggering install of $PACKAGENAME"
+				install_test=1;
+			fi
+		else
+			echo "For $PACKAGENAME: svn current_version  is $current_version and last changed version is $last_changed_version"
+			echo "However, install directory does not exist, so triggering install of $PACKAGENAME"
+			install_test=1;
+		fi
+	fi
 
+	if [[ $install_test == 1 ]]; then 
+		echo "======================================================";
+		echo "       Installing $PACKAGENAME                        ";
+		echo "======================================================";
+		./$PACKAGEINST |  tee compil.log
+		if [ $? -ne 0 ]; then
+			echo "======================================================";
+			echo "    ERROR: installation of $PACKAGENAME failed        ";
+			echo "======================================================";
+			#erase install directory, so that next time, we still try and compile this!
+			rm -rf install
+		fi
+		source $ISSM_DIR/etc/environment.sh
+	else
+		echo "======================================================";
+		echo "       Skipping install of $PACKAGENAME                        ";
+		echo "======================================================";
+	fi
+	cd ..
+done
 source $ISSM_DIR/etc/environment.sh
-
-cd "$ISSM_DIR/externalpackages/triangle"
-echo '---------------------------------'
-echo "Installing Triangle"
-echo '---------------------------------'
-./install-macosx64.sh &> /dev/null
-
-if [ $? -ne 0 ]; then
-   echo "FAILED TO INSTALL TRIANGLE!"
-   exit 1;
-fi
-
-cd "$ISSM_DIR/externalpackages/mpich"
-echo '---------------------------------'
-echo "Installing MPICH"
-echo '---------------------------------'
-./install-3.0-macosx64-static.sh $1 &> /dev/null
-
-if [ $? -ne 0 ]; then
-   echo "FAILED TO INSTALL MPICH!"
-   exit 1;
-fi
-
-cd "$ISSM_DIR/externalpackages/petsc"
-echo '---------------------------------'
-echo "Installing PETSc"
-echo '---------------------------------'
-./install-3.5-macosx64-static.sh &> /dev/null
-
-if [ $? -ne 0 ]; then
-   echo "FAILED TO INSTALL PETSC!"
-   exit 1;
-fi
 # }}}
 
-source $ISSM_DIR/etc/environment.sh
-
-cd $ISSM_DIR
-
+# Compile ISSM
+#{{{
 echo "Aureconf..."
 autoreconf -if &> /dev/null
-
-if [ $? -ne 0 ]; then
-   echo "FAILED TO AUTORECONF!"
-   exit 1;
-fi
-
 echo "Configuring..."
 $ISSM_DIR/configs/config-macosx64-static.sh &> /dev/null
+if [ $? -ne 0 ]; then echo "FAILED TO CONFIGURE!" && exit 1; fi
 
-if [ $? -ne 0 ]; then
-   echo "FAILED TO CONFIGURE!"
-   exit 1;
-fi
-
 echo "Building..."
-if [ -z $1 ]; then
-   make -j$1 &> /dev/null
-else
-   make &> /dev/null
-fi
+make -j 4 
+if [ $? -ne 0 ]; then echo "FAILED TO BUILD!" && exit 1; fi
 
-if [ $? -ne 0 ]; then
-   echo "FAILED TO BUILD!"
-   exit 1;
-fi
-
 echo "Installing..."
 make install &> /dev/null
-
-if [ $? -ne 0 ]; then
-   echo "FAILED TO INSTALL!"
-   exit 1;
-fi
+if [ $? -ne 0 ]; then echo "FAILED TO INSTALL!" && exit 1; fi
+#}}}
