drush 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # Get the absolute path of this executable
  8. ORIGDIR=$(pwd)
  9. SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
  10. # Resolve symlinks - this is the equivalent of "readlink -f", but also works with non-standard OS X readlink.
  11. while [ -h "$SELF_PATH" ]; do
  12. # 1) cd to directory of the symlink
  13. # 2) cd to the directory of where the symlink points
  14. # 3) Get the pwd
  15. # 4) Append the basename
  16. DIR=$(dirname -- "$SELF_PATH")
  17. SYM=$(readlink $SELF_PATH)
  18. SELF_PATH=$(cd $DIR && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
  19. done
  20. cd "$ORIGDIR"
  21. # Build the path to drush.php.
  22. SCRIPT_PATH=$(dirname "$SELF_PATH")/drush.php
  23. case $(uname -a) in
  24. CYGWIN*)
  25. SCRIPT_PATH=$(cygpath -w -a -- "$SCRIPT_PATH") ;;
  26. esac
  27. # If not exported, try to determine and export the number of columns.
  28. # We do not want to run $(tput cols) if $TERM is empty or "dumb", because
  29. # if we do, tput will output an undesirable error message to stderr. If
  30. # we redirect stderr in any way, e.g. $(tput cols 2>/dev/null), then the
  31. # error message is suppressed, but tput cols becomes confused about the
  32. # terminal and prints out the default value (80).
  33. if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != dumb ] ; then
  34. # Note to cygwin users: install the ncurses package to get tput command.
  35. if COLUMNS=$(tput cols); then
  36. export COLUMNS
  37. fi
  38. fi
  39. if [ ! -z "$DRUSH_PHP" ] ; then
  40. # Use the DRUSH_PHP environment variable if it is available.
  41. php="$DRUSH_PHP"
  42. else
  43. # Default to using the php that we find on the PATH.
  44. # Note that we need the full path to php here for Dreamhost, which behaves oddly. See http://drupal.org/node/662926
  45. php=`which php`
  46. # We check for a command line (cli) version of php, and if found use that.
  47. which php-cli >/dev/null 2>&1
  48. if [ "$?" = 0 ] ; then
  49. php=`which php-cli`
  50. fi
  51. # Special case for *AMP installers, since they normally don't set themselves as the default cli php out of the box.
  52. for amp_php in /Applications/MAMP/bin/php5/bin/php /Applications/MAMP/bin/php5.2/bin/php /Applications/MAMP/bin/php5.3/bin/php /opt/lampp/bin/php /Applications/xampp/xamppfiles/bin/php /Applications/acquia-drupal/php/bin/php; do
  53. if [ -x $amp_php ]; then
  54. php=$amp_php
  55. fi
  56. done
  57. fi
  58. # Check to see if the user has provided a php.ini file or drush.ini file in any conf dir
  59. # Last found wins, so search in reverse priority order
  60. for conf_dir in $(dirname "$SELF_PATH") /etc/drush $HOME/.drush ; do
  61. if [ -f $conf_dir/php.ini ] ; then
  62. drush_php_ini=$conf_dir/php.ini
  63. fi
  64. if [ -f $conf_dir/drush.ini ] ; then
  65. drush_php_override=$conf_dir/drush.ini
  66. fi
  67. done
  68. # Add in the php file location and/or the php override variables as appropriate
  69. if [ "x$drush_php_ini" != "x" ] ; then
  70. php="$php --php-ini $drush_php_ini"
  71. fi
  72. if [ "x$drush_php_override" != "x" ] ; then
  73. drush_override_vars=`grep '^[a-z_A-Z0-9]\+ *=' $drush_php_override | sed -e 's|\([^ =]*\) *= *\(.*\)|\1="\2"|' -e 's| ||g' -e 's|^|-d |' | tr '\n\r' ' '`
  74. php="$php $drush_override_vars"
  75. fi
  76. # Pass in the path to php so that drush knows which one
  77. # to use if it re-launches itself to run subcommands
  78. exec $php "$SCRIPT_PATH" "$@" --php="$php"