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.
7 # Solaris users: Add /usr/xpg4/bin to the head of your PATH
10 # Get the absolute path of this executable
11 SELF_DIRNAME="`dirname -- "$0"`"
12 SELF_PATH="`cd -P -- "$SELF_DIRNAME" && pwd -P`/`basename -- "$0"`"
14 # Decide if we are running a Unix shell on Windows
15 if `which uname > /dev/null 2>&1`; then
24 # Resolve symlinks - this is the equivalent of "readlink -f", but also works with non-standard OS X readlink.
25 while [ -h "$SELF_PATH" ]; do
26 # 1) cd to directory of the symlink
27 # 2) cd to the directory of where the symlink points
29 # 4) Append the basename
30 DIR="`dirname -- "$SELF_PATH"`"
31 SYM="`readlink "$SELF_PATH"`"
32 SYM_DIRNAME="`dirname -- "$SYM"`"
33 SELF_PATH="`cd "$DIR" && cd "$SYM_DIRNAME" && pwd`/`basename -- "$SYM"`"
36 # If not exported, try to determine and export the number of columns.
37 # We do not want to run `tput cols` if $TERM is empty, "unknown", or "dumb", because
38 # if we do, tput will output an undesirable error message to stderr. If
39 # we redirect stderr in any way, e.g. `tput cols 2>/dev/null`, then the
40 # error message is suppressed, but tput cols becomes confused about the
41 # terminal and prints out the default value (80).
42 if [ -z $COLUMNS ] && [ -n "$TERM" ] && [ "$TERM" != dumb ] && [ "$TERM" != unknown ] && [ -n "`which tput`" ] ; then
43 # Note to cygwin/mingw/msys users: install the ncurses package to get tput command.
44 # Note to mingw/msys users: there is no precompiled ncurses package.
45 if COLUMNS="`tput cols`"; then
50 if [ -n "$DRUSH_PHP" ] ; then
51 # Use the DRUSH_PHP environment variable if it is available.
54 # On MSYSGIT, we need to use "php", not the full path to php
55 if [ -n "$MINGW" ] ; then
58 # Default to using the php that we find on the PATH.
59 # We check for a command line (cli) version of php, and if found use that.
60 # Note that we need the full path to php here for Dreamhost, which behaves oddly. See http://drupal.org/node/662926
61 php="`which php-cli 2>/dev/null`"
63 if [ ! -x "$php" ]; then
64 php="`which php 2>/dev/null`"
67 if [ ! -x "$php" ]; then
68 echo "ERROR: can't find php."; exit 1
73 # Build the path to drush.php.
74 SCRIPT_PATH="`dirname "$SELF_PATH"`/drush.php"
75 if [ -n "$CYGWIN" ] ; then
76 # try to determine if we are running cygwin port php or Windows native php:
77 if [ -n "`"$php" -i | grep -E '^System => Windows'`" ]; then
78 SCRIPT_PATH="`cygpath -w -a -- "$SCRIPT_PATH"`"
80 SCRIPT_PATH="`cygpath -u -a -- "$SCRIPT_PATH"`"
84 # Check to see if the user has provided a php.ini file or drush.ini file in any conf dir
85 # Last found wins, so search in reverse priority order
86 for conf_dir in "`dirname "$SELF_PATH"`" /etc/drush "$HOME/.drush" ; do
87 if [ ! -d "$conf_dir" ] ; then
90 # Handle paths that don't start with a drive letter on MinGW shell. Equivalent to cygpath on Cygwin.
91 if [ -n "$MINGW" ] ; then
92 conf_dir=`sh -c "cd \"$conf_dir\"; pwd -W"`
94 if [ -f "$conf_dir/php.ini" ] ; then
95 drush_php_ini="$conf_dir/php.ini"
97 if [ -f "$conf_dir/drush.ini" ] ; then
98 drush_php_override="$conf_dir/drush.ini"
101 # If the PHP_INI environment variable is specified, then tell
102 # php to use the php.ini file that it specifies.
103 if [ -n "$PHP_INI" ] ; then
104 drush_php_ini="$PHP_INI"
106 # If the DRUSH_INI environment variable is specified, then
107 # extract all ini variable assignments from it and convert
108 # them into php '-d' options. These will override similarly-named
109 # options in the php.ini file
110 if [ -n "$DRUSH_INI" ] ; then
111 drush_php_override="$DRUSH_INI"
114 # Add in the php file location and/or the php override variables as appropriate
115 if [ -n "$drush_php_ini" ] ; then
116 php_options="--php-ini $drush_php_ini"
118 if [ -n "$drush_php_override" ] ; then
119 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' ' '`
121 # If the PHP_OPTIONS environment variable is specified, then
122 # its contents will be passed to php on the command line as
123 # additional options to use.
124 if [ -n "$PHP_OPTIONS" ] ; then
125 php_options="$php_options $PHP_OPTIONS"
128 # Pass in the path to php so that drush knows which one to use if it
129 # re-launches itself to run subcommands. We will also pass in the php options.
130 # Important note: Any options added here must be removed when Drush processes
131 # a #! (shebang) script. @see drush_adjust_args_if_shebang_script()
132 exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"