Advertisement
m1k3ry4n

drush

Jan 19th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.30 KB | None | 0 0
  1. #!/usr/bin/env sh
  2. # $Id$
  3. #
  4. # This script is a simple wrapper that will run Drush with the most appropriate
  5. # php executable it can find.
  6. #
  7.  
  8. # Get the absolute path of this executable
  9. ORIGDIR=$(pwd)
  10. SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
  11.  
  12. # Resolve symlinks - this is the equivalent of "readlink -f", but also works with non-standard OS X readlink.
  13. while [ -h "$SELF_PATH" ]; do
  14.     # 1) cd to directory of the symlink
  15.     # 2) cd to the directory of where the symlink points
  16.     # 3) Get the pwd
  17.     # 4) Append the basename
  18.     DIR=$(dirname -- "$SELF_PATH")
  19.     SYM=$(readlink $SELF_PATH)
  20.     SELF_PATH=$(cd "$DIR" && cd "$(dirname -- "$SYM")" && pwd)/$(basename -- "$SYM")
  21. done
  22. cd "$ORIGDIR"
  23.  
  24. # Build the path to drush.php.
  25. SCRIPT_PATH=$(dirname "$SELF_PATH")/drush.php
  26. case $(uname -a) in
  27.   CYGWIN*)
  28.     SCRIPT_PATH=$(cygpath -w -a -- "$SCRIPT_PATH") ;;
  29. esac
  30.  
  31.  
  32. # If not exported, try to determine and export the number of columns.
  33. # We do not want to run $(tput cols) if $TERM is empty or "dumb", because
  34. # if we do, tput will output an undesirable error message to stderr.  If
  35. # we redirect stderr in any way, e.g. $(tput cols 2>/dev/null), then the
  36. # error message is suppressed, but tput cols becomes confused about the
  37. # terminal and prints out the default value (80).
  38. if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != dumb ] && [ ! -z "`which tput`" ] ; then
  39.   # Note to cygwin users: install the ncurses package to get tput command.
  40.   if COLUMNS=$(tput cols); then
  41.     export COLUMNS
  42.   fi
  43. fi
  44.  
  45. if [ ! -z "$DRUSH_PHP" ] ; then
  46.   # Use the DRUSH_PHP environment variable if it is available.
  47.   php="$DRUSH_PHP"
  48. else
  49.   # Default to using the php that we find on the PATH.
  50.   # Note that we need the full path to php here for Dreamhost, which behaves oddly.  See http://drupal.org/node/662926
  51.   php=`which php`
  52.  
  53.   # We check for a command line (cli) version of php, and if found use that.
  54.   which php-cli >/dev/null 2>&1
  55.   if [ "$?" = 0 ] ; then
  56.     php=`which php-cli`
  57.   fi
  58.  
  59.   # On MSYSGIT, we need to use "php", not the full path to php
  60.   if [ ! -z "$MSYSTEM" ] && [ "x${MSYSTEM:0:5}" = "xMINGW" ] ; then
  61.     php="php"
  62.   fi
  63. fi
  64.  
  65. # Check to see if the user has provided a php.ini file or drush.ini file in any conf dir
  66. # Last found wins, so search in reverse priority order
  67. for conf_dir in $(dirname "$SELF_PATH") /etc/drush $HOME/.drush ; do
  68.   if [ -f $conf_dir/php.ini ] ; then
  69.     drush_php_ini=$conf_dir/php.ini
  70.   fi
  71.   if [ -f $conf_dir/drush.ini ] ; then
  72.     drush_php_override=$conf_dir/drush.ini
  73.   fi
  74. done
  75.  
  76. # Add in the php file location and/or the php override variables as appropriate
  77. if [ "x$drush_php_ini" != "x" ] ; then
  78.   php_options="--php-ini $drush_php_ini"
  79. fi
  80. if [ "x$drush_php_override" != "x" ] ; then
  81.   php_options=`grep '^[a-z_A-Z0-9]\+ *=' $drush_php_override | sed -e 's|\([^ =]*\) *= *\(.*\)|\1="\2"|' -e 's| ||g' -e 's|^|\
  82. -d |' | tr '\n\r' '  '`
  83. fi
  84.  
  85. # Pass in the path to php so that drush knows which one
  86. # to use if it re-launches itself to run subcommands.  We
  87. # will also pass php options if any are defined.
  88. if [ -z "$php_options" ] ; then
  89.   exec "$php" $php_options "$SCRIPT_PATH" --php="$php" "$@"
  90. else
  91.   exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"
  92. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement