|
| 1 | +#!/usr/bin/env sh |
| 2 | +################################################################################ |
| 3 | +# |
| 4 | +# Cake is a shell script for invoking CakePHP shell commands |
| 5 | +# |
| 6 | +# CakePHP(tm) : Rapid Development Framework (https://cakephp.org) |
| 7 | +# Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 8 | +# |
| 9 | +# Licensed under The MIT License |
| 10 | +# For full copyright and license information, please see the LICENSE.txt |
| 11 | +# Redistributions of files must retain the above copyright notice. |
| 12 | +# |
| 13 | +# @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) |
| 14 | +# @link https://cakephp.org CakePHP(tm) Project |
| 15 | +# @since 1.2.0 |
| 16 | +# @license https://opensource.org/licenses/mit-license.php MIT License |
| 17 | +# |
| 18 | +################################################################################ |
| 19 | + |
| 20 | +# Canonicalize by following every symlink of the given name recursively |
| 21 | +canonicalize() { |
| 22 | + NAME="$1" |
| 23 | + if [ -f "$NAME" ] |
| 24 | + then |
| 25 | + DIR=$(dirname -- "$NAME") |
| 26 | + NAME=$(cd -P "$DIR" > /dev/null && pwd -P)/$(basename -- "$NAME") |
| 27 | + fi |
| 28 | + while [ -h "$NAME" ]; do |
| 29 | + DIR=$(dirname -- "$NAME") |
| 30 | + SYM=$(readlink "$NAME") |
| 31 | + NAME=$(cd "$DIR" > /dev/null && cd $(dirname -- "$SYM") > /dev/null && pwd)/$(basename -- "$SYM") |
| 32 | + done |
| 33 | + echo "$NAME" |
| 34 | +} |
| 35 | + |
| 36 | +# Find a CLI version of PHP |
| 37 | +findCliPhp() { |
| 38 | + for TESTEXEC in php php-cli /usr/local/bin/php |
| 39 | + do |
| 40 | + SAPI=`echo "<?= PHP_SAPI ?>" | $TESTEXEC 2>/dev/null` |
| 41 | + if [ "$SAPI" = "cli" ] |
| 42 | + then |
| 43 | + echo $TESTEXEC |
| 44 | + return |
| 45 | + fi |
| 46 | + done |
| 47 | + echo "Failed to find a CLI version of PHP; falling back to system standard php executable" >&2 |
| 48 | + echo "php"; |
| 49 | +} |
| 50 | + |
| 51 | +# If current path is a symlink, resolve to real path |
| 52 | +realname="$0" |
| 53 | +if [ -L "$realname" ] |
| 54 | +then |
| 55 | + realname=$(readlink -f "$0") |
| 56 | +fi |
| 57 | + |
| 58 | +CONSOLE=$(dirname -- "$(canonicalize "$realname")") |
| 59 | +APP=$(dirname "$CONSOLE") |
| 60 | + |
| 61 | +# If your CLI PHP is somewhere that this doesn't find, you can define a PHP environment |
| 62 | +# variable with the correct path in it. |
| 63 | +if [ -z "$PHP" ] |
| 64 | +then |
| 65 | + PHP=$(findCliPhp) |
| 66 | +fi |
| 67 | + |
| 68 | +if [ $(basename $realname) != 'cake' ] |
| 69 | +then |
| 70 | + exec $PHP "$CONSOLE"/cake.php $(basename $realname) "$@" |
| 71 | +else |
| 72 | + exec $PHP "$CONSOLE"/cake.php "$@" |
| 73 | +fi |
| 74 | + |
| 75 | +exit |
0 commit comments