github.com/mattdotmatt/gauge@v0.3.2-0.20160421115137-425a4cdccb62/build/install/install.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2015 ThoughtWorks, Inc.
     4  
     5  # This file is part of Gauge.
     6  
     7  # Gauge is free software: you can redistribute it and/or modify
     8  # it under the terms of the GNU General Public License as published by
     9  # the Free Software Foundation, either version 3 of the License, or
    10  # (at your option) any later version.
    11  
    12  # Gauge is distributed in the hope that it will be useful,
    13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  # GNU General Public License for more details.
    16  
    17  # You should have received a copy of the GNU General Public License
    18  # along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    19  
    20  set -e
    21  
    22  install_plugin() {
    23      echo "Installing plugin - $1..."
    24      $prefix/bin/gauge --install $1
    25  }
    26  
    27  display_usage() {
    28  	echo "On Linux, this script takes an optional install path."
    29  	echo -e "\nUsage:\n$0 [path] \n"
    30  }
    31  
    32  set_gaugeroot() {
    33      # ensure gauge is on PATH
    34      if [ -z "$(which gauge)" ]; then
    35          echo "Adding gauge to system path..."
    36          echo "PATH=$PATH:$prefix/bin" >> ~/.profile
    37          updated_profile=1
    38      fi
    39      # ensure GAUGE_ROOT is set
    40      if [ -z "$GAUGE_ROOT" ]; then
    41          echo "Adding GAUGE_ROOT to environment..."
    42          echo "export GAUGE_ROOT=$prefix"  >> ~/.profile
    43          updated_profile=1
    44      fi
    45      if [ $updated_profile ] ; then
    46          source ~/.profile
    47      fi
    48  }
    49  
    50  install_gauge() {
    51      echo "Installing gauge at $prefix"
    52      echo "Creating $prefix if it doesn't exist"
    53      [ -d $prefix ] || mkdir $prefix
    54  
    55      # check for write permissions
    56      if [ ! -w "$prefix" -a "$prefix" = "/usr/local" ]; then
    57          echo
    58          echo "Installation failed..."
    59          echo "You do not have write permissions for $prefix"
    60          echo "Please run this script as sudo or pass a custom location where you want to install Gauge."
    61          echo "Example: ./install.sh /home/gauge/local/gauge_install_dir"
    62          echo
    63          exit 1
    64      fi
    65  
    66      # do the installation
    67      echo "Copying files to $prefix"
    68      gaugePropertiesFile=$prefix/share/gauge/gauge.properties
    69      if [ -f $prefix/share/gauge/timestamp.txt ] ; then
    70          currentTimeStamp=`date +%s -r $gaugePropertiesFile`
    71          oldTimeStamp=`cat $prefix/share/gauge/timestamp.txt`
    72          if [ $currentTimeStamp != $oldTimeStamp ] ; then
    73              backupFile=$prefix/share/gauge/gauge.properties.bak
    74              echo "If you have Gauge installed already and there are any manual changes in gauge.properties file, a backup of it has been taken at GAUGE_INSTALL_LOCATION\share\gauge\gauge.properties.bak. You can restore these configurations later."
    75              rm -rf $backupFile
    76              cat $gaugePropertiesFile > $backupFile
    77          fi
    78      fi
    79  
    80      cp -rf bin share $prefix
    81      date +%s -r $gaugePropertiesFile > $prefix/share/gauge/timestamp.txt
    82  
    83      set_gaugeroot
    84      echo "Gauge core successfully installed.\n"
    85  }
    86  
    87  if [ -z "$1" ]; then
    88      prefix=/usr/local
    89  else
    90      prefix=$1
    91  fi
    92  
    93  # if more than one arguments supplied, display usage
    94  if [ $# -gt 1 ]
    95  then
    96      display_usage
    97      exit 1
    98  fi
    99  
   100  # check whether user has supplied -h or --help . If yes display usage
   101  if [[ ( $@ == "--help") || $@ == "-h" ]]
   102  then
   103      display_usage
   104      exit 0
   105  fi
   106  
   107  install_gauge $prefix
   108  install_plugin html-report