App-Options

 view release on metacpan or  search on metacpan

bin/prefix  view on Meta::CPAN

#!/bin/bash
#*********************************************************************
#** prefix
#*********************************************************************
#** @(#)$Id: prefix 7988 2006-10-27 18:39:02Z spadkins $
#*********************************************************************

export OLD_PREFIX=$PREFIX
export PREFIX=${PREFIX:-/usr/local}

if [[ -f "$HOME/.prefixes" ]]      # check if multiple environments exist
then
   export PREFIXES_FILE=$HOME/.prefixes
else
   export PREFIXES_FILE=/etc/prefixes 
fi

print_usage ()
{
   echo
   echo "The prefix script allows you to manage multiple installations of"
   echo "a set of software installed on the same machine.  It helps in this"
   echo "by taking care of the reconfiguration of environment variables"
   echo "appropriate for each installation.  It is assumed that the"
   echo "software for each installation is all under a single directory"
   echo "whose name is assigned to an environment variable called PREFIX. "
   echo
   echo "This arrangement of enabling multiple installations of software"
   echo "on a single machine is useful at many times.  On a single server,"
   echo "it can provide for development, test, and production installations"
   echo "of software.  Alternatively, on development servers,"
   echo "it allows for multiple development \"sandboxes\", one for each"
   echo "developer.  On production servers, it allows for multiple versions"
   echo "of the production software to be installed.  One might be the currently"
   echo "running software, one the previous software kept online as a fall-back,"
   echo "and one a new release of software which is scheduled to be brought"
   echo "online soon."
   echo
   echo "There are three usages of the prefix script:"
   echo
   echo "  (1) The interactive usage should be placed as the last line"
   echo "      of a user's ".profile".  The user must be running the"
   echo "      Korn shell (ksh) or the Bourne Again shell (bash)."
   echo "      The user is prompted to enter one of the known PREFIX locations,"
   echo "      specified in the \$HOME/.prefixes file or the /etc/prefixes file."
   echo "      During configuration, the \$PREFIX/.prefixrc file is sourced"
   echo "      in order to accomplish environment-specific configurations."
   echo "  (2) The non-interactive user configuration does not consult"
   echo "      \$HOME/.prefixes or /etc/prefixes or prompt the user, but merely"
   echo "      configures the environment in accordance with the cmd line argument."
   echo "  (3) The batch command usage is mainly for running commands from"
   echo "      cron or running commands in another environment without changing"
   echo "      to that environment."
   echo
   echo "Usage (1): . prefix                     (sets up environment)"
   echo "      (2): . prefix <prefix>            (non-interactive setup)"
   echo "      (3): prefix <prefix> <cmd> <args> (runs cmd configured for PREFIX)"
   echo
}

if [[ "$1" = "-?" ]]
then
   print_usage
else
   export PREFIX_CMD=""
   if [[ "$1" != "" ]]
   then
      export NEW_PREFIX="$1"
      export PREFIX_ASK="no"
      shift
      if [[ $# -gt 0 ]]
      then
         export PREFIX_CMD="$*"
         set --                             # clear cmd line args
      fi
   fi

   if [[ "$PREFIX_ASK" != "no" ]]
   then
      if [[ -f "$PREFIXES_FILE" ]]     # check if multiple environments exist
      then
         export NUM_PREFIXES=$(wc -l < "$PREFIXES_FILE")
         if [[ "$NEW_PREFIX" = "" ]]      
         then
            export NEW_PREFIX=$(head -1 "$PREFIXES_FILE")
         fi
   
         if [[ "$PREFIX_ASK" != "no" && "$NUM_PREFIXES" -gt 1 ]]
         then
            echo "========================================================"
            echo "SET UP SOFTWARE PREFIX (ROOT DIRECTORY FOR THE SOFTWARE)"
            echo "========================================================"
            export PS3="Select a directory: "
            select NEW_PREFIX in $(sed 's/#.*//' "$PREFIXES_FILE")
            do
               break
            done
            if [[ "$NEW_PREFIX" = "" ]]
            then
               export NEW_PREFIX="$REPLY"
            fi
         fi
      fi
   fi

   if [[ "$NEW_PREFIX" = "" ]]
   then
      echo
      echo "ERROR: Please specify a PREFIX or create a ~/.prefixes file"



( run in 1.966 second using v1.01-cache-2.11-cpan-6aa56a78535 )