[gimp-web/testing] new and improved install.sh



commit 4006f148e05ac090d53c4515944af1509bfd794e
Author: Sam Gleske <sam mxracer gmail com>
Date:   Fri May 2 11:01:18 2014 -0400

    new and improved install.sh
    
    This is now POSIX compatible with proper exit
    code reporting for Jenkins jobs
    
    comment updates for install.sh
    
    variable trailing slash cleanup in install.sh
    
    Signed-off-by: Michael Schumacher <schumaml gmx de>

 install.sh |  108 ++++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 77 insertions(+), 31 deletions(-)
---
diff --git a/install.sh b/install.sh
index 969bfa2..6af4b3f 100755
--- a/install.sh
+++ b/install.sh
@@ -1,43 +1,89 @@
 #!/bin/bash
+#Linux 3.13.0-24-generic x86_64
+#GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
+#GNU Make 3.81
+#Python 2.7.6
 
-if [ ! -f install.config ]; then
-  echo ""
-  echo "Install procedure requires install.config file."
-  echo "See install.config.sample for an example."
-  echo ""
-  exit 1
-fi
+######################################################################
+# variable defaults
 
+#source install config if it exists but is not a requirement
+if [ -f "install.config" ];then
 source install.config
-
-if [ "x${HTDOCS_DIR}" = "x" ]; then
-  echo ""
-  echo "HTDOCS_DIR must be specified in install.config."
-  echo "See install.config.sample for an example."
-  echo ""
-  exit 1
 fi
 
-if [ "x${PYTHON}" = "x" ]; then
-  if [ "x`which python2.4`" != "x" ]; then
-    PYTHON=python2.4
+#Output file where make output is written
+MAKEOUT="${MAKEOUT:-make.out}"
+
+#set MAKE if the MAKE variable is null
+MAKE="${MAKE:-make}"
+
+#set PYTHON if PYTHON variable is null
+#search for a python 2.x version else set PYTHON=python
+if [ -z "${PYTHON}" ]; then
+  if which python2.7 &> /dev/null;then
+    PYTHON="python2.7"
+  elif which python2.6 &> /dev/null;then
+    PYTHON="python2.6"
+  elif which python2.5 &> /dev/null;then
+    PYTHON="python2.5"
+  elif which python2.4 &> /dev/null;then
+    PYTHON="python2.4"
+  elif which python2.3 &> /dev/null;then
+    PYTHON="python2.3"
+  elif which python2.2 &> /dev/null;then
+    PYTHON="python2.2"
   else
-    if [ "x`which python2.3`" != "x" ]; then
-      PYTHON=python2.3
-    else
-      if [ "x`which python2.2`" != "x" ]; then
-        PYTHON=python2.2
-      else
-        PYTHON=python
-      fi
-    fi
+    PYTHON="python"
   fi
 fi
 
-if [ -z "$MAKE" ]; then
-  MAKE=make
-fi
+#variable clean up
+#remove trailing slash from HTDOCS_DIR if it exists
+HTDOCS_DIR="${HTDOCS_DIR%/}"
+
+######################################################################
+# functions
+
+#This function checks for errors before allowing to continue
+function preflight(){
+  STATUS=0
+  if [ -z "${HTDOCS_DIR}" ]; then
+    echo "HTDOCS_DIR must be specified in install.config."
+    echo "See install.config.sample for an example."
+    echo ""
+    STATUS=1
+  fi
+  #Test if python exists and is executable
+  if [ ! -x "$(which "${PYTHON}")" ];then
+    echo "${PYTHON} does not exist on this system or it is not executable!"
+    echo ""
+    STATUS=1
+  fi
+  if [ ! -x "$(which "${MAKE}")" ];then
+    echo "${MAKE} does not exist on this system or it is not executable!"
+    echo ""
+    STATUS=1
+  fi
+  return ${STATUS}
+}
+
+#main function is where all the magic happens.  Building the site
+function main(){
+  STATUS=0
+  ${MAKE} PYTHON="${PYTHON}" DocumentRoot="${HTDOCS_DIR}" clean all programmatic install 2>&1 | tee 
"${MAKEOUT}"
+  #capture the exit status of the make command
+  if [ ! "${PIPESTATUS[0]}" -eq "0" ];then
+    STATUS=1
+  fi
+  echo done >> "${MAKEOUT}"
+  return ${STATUS}
+}
 
-${MAKE} PYTHON=${PYTHON} DocumentRoot=${HTDOCS_DIR} clean all programmatic install 2>&1 | tee make.out
-echo done >> make.out
+######################################################################
+# main execution
 
+#main depends on successful execution of preflight
+#output to stderr like a good posix compatible program
+#return a bad status code when the build process fails
+preflight 1>&2 && main 1>&2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]