Drupal investigation

drush.launcher 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env sh
  2. #
  3. # This script is a simple launcher that will run Drush with the most appropriate
  4. # php executable it can find. In most cases, the 'drush' script should be
  5. # called first; it will in turn launch this script.
  6. #
  7. # Solaris users: Add /usr/xpg4/bin to the head of your PATH
  8. #
  9. # Get the absolute path of this executable
  10. SELF_DIRNAME="`dirname -- "$0"`"
  11. SELF_PATH="`cd -P -- "$SELF_DIRNAME" && pwd -P`/`basename -- "$0"`"
  12. # Decide if we are running a Unix shell on Windows
  13. if `which uname > /dev/null 2>&1`; then
  14. case "`uname -a`" in
  15. CYGWIN*)
  16. CYGWIN=1 ;;
  17. MINGW*)
  18. MINGW=1 ;;
  19. esac
  20. fi
  21. # Resolve symlinks - this is the equivalent of "readlink -f", but also works with non-standard OS X readlink.
  22. while [ -h "$SELF_PATH" ]; do
  23. # 1) cd to directory of the symlink
  24. # 2) cd to the directory of where the symlink points
  25. # 3) Get the pwd
  26. # 4) Append the basename
  27. DIR="`dirname -- "$SELF_PATH"`"
  28. SYM="`readlink "$SELF_PATH"`"
  29. SYM_DIRNAME="`dirname -- "$SYM"`"
  30. SELF_PATH="`cd "$DIR" && cd "$SYM_DIRNAME" && pwd`/`basename -- "$SYM"`"
  31. done
  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, "unknown", 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 ] && [ "$TERM" != unknown ] && [ -n "`which tput`" ] ; then
  39. # Note to cygwin/mingw/msys users: install the ncurses package to get tput command.
  40. # Note to mingw/msys users: there is no precompiled ncurses package.
  41. if COLUMNS="`tput cols`"; then
  42. export COLUMNS
  43. fi
  44. fi
  45. if [ -n "$DRUSH_PHP" ] ; then
  46. # Use the DRUSH_PHP environment variable if it is available.
  47. php="$DRUSH_PHP"
  48. else
  49. # On MSYSGIT, we need to use "php", not the full path to php
  50. if [ -n "$MINGW" ] ; then
  51. php="php"
  52. else
  53. # Default to using the php that we find on the PATH.
  54. # We check for a command line (cli) version of php, and if found use that.
  55. # Note that we need the full path to php here for Dreamhost, which behaves oddly. See http://drupal.org/node/662926
  56. php="`which php-cli 2>/dev/null`"
  57. if [ ! -x "$php" ]; then
  58. php="`which php 2>/dev/null`"
  59. fi
  60. if [ ! -x "$php" ]; then
  61. echo "ERROR: can't find php."; exit 1
  62. fi
  63. fi
  64. fi
  65. # Build the path to drush.php.
  66. SCRIPT_PATH="`dirname "$SELF_PATH"`/drush.php"
  67. if [ -n "$CYGWIN" ] ; then
  68. # try to determine if we are running cygwin port php or Windows native php:
  69. if [ -n "`"$php" -i | grep -E '^System => Windows'`" ]; then
  70. SCRIPT_PATH="`cygpath -w -a -- "$SCRIPT_PATH"`"
  71. else
  72. SCRIPT_PATH="`cygpath -u -a -- "$SCRIPT_PATH"`"
  73. fi
  74. fi
  75. # Check to see if the user has provided a php.ini file or drush.ini file in any conf dir
  76. # Last found wins, so search in reverse priority order
  77. for conf_dir in "`dirname "$SELF_PATH"`" /etc/drush "$HOME/.drush" ; do
  78. if [ ! -d "$conf_dir" ] ; then
  79. continue
  80. fi
  81. # Handle paths that don't start with a drive letter on MinGW shell. Equivalent to cygpath on Cygwin.
  82. if [ -n "$MINGW" ] ; then
  83. conf_dir=`sh -c "cd \"$conf_dir\"; pwd -W"`
  84. fi
  85. if [ -f "$conf_dir/php.ini" ] ; then
  86. drush_php_ini="$conf_dir/php.ini"
  87. fi
  88. if [ -f "$conf_dir/drush.ini" ] ; then
  89. drush_php_override="$conf_dir/drush.ini"
  90. fi
  91. done
  92. # If the PHP_INI environment variable is specified, then tell
  93. # php to use the php.ini file that it specifies.
  94. if [ -n "$PHP_INI" ] ; then
  95. drush_php_ini="$PHP_INI"
  96. fi
  97. # If the DRUSH_INI environment variable is specified, then
  98. # extract all ini variable assignments from it and convert
  99. # them into php '-d' options. These will override similarly-named
  100. # options in the php.ini file
  101. if [ -n "$DRUSH_INI" ] ; then
  102. drush_php_override="$DRUSH_INI"
  103. fi
  104. # Add in the php file location and/or the php override variables as appropriate
  105. if [ -n "$drush_php_ini" ] ; then
  106. php_options="--php-ini $drush_php_ini"
  107. fi
  108. if [ -n "$drush_php_override" ] ; then
  109. php_options=`grep '^[a-z_A-Z0-9.]\+ *=' $drush_php_override | sed -e 's|\([^ =]*\) *= *\(.*\)|\1="\2"|' -e 's| ||g' -e 's|^|-d |' | tr '\n\r' ' '`
  110. fi
  111. # If the PHP_OPTIONS environment variable is specified, then
  112. # its contents will be passed to php on the command line as
  113. # additional options to use.
  114. if [ -n "$PHP_OPTIONS" ] ; then
  115. php_options="$php_options $PHP_OPTIONS"
  116. fi
  117. # Pass in the path to php so that drush knows which one to use if it
  118. # re-launches itself to run subcommands. We will also pass in the php options.
  119. # Important note: Any options added here must be removed when Drush processes
  120. # a #! (shebang) script. @see drush_adjust_args_if_shebang_script()
  121. exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"