Blame view

bin/cake 2.18 KB
6c4edfa3   Alexandre   First Commit LabI...
1
2
3
4
5
#!/usr/bin/env sh
################################################################################
#
# Cake is a shell script for invoking CakePHP shell commands
#
07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
6
7
# CakePHP(tm) :  Rapid Development Framework (https://cakephp.org)
# Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
6c4edfa3   Alexandre   First Commit LabI...
8
9
10
11
12
#
# Licensed under The MIT License
# For full copyright and license information, please see the LICENSE.txt
# Redistributions of files must retain the above copyright notice.
#
07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
13
14
# @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
# @link          https://cakephp.org CakePHP(tm) Project
6c4edfa3   Alexandre   First Commit LabI...
15
# @since         1.2.0
07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
16
# @license       https://opensource.org/licenses/mit-license.php MIT License
6c4edfa3   Alexandre   First Commit LabI...
17
18
19
20
21
#
################################################################################

# Canonicalize by following every symlink of the given name recursively
canonicalize() {
07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
22
23
24
25
26
27
28
29
30
31
32
33
    NAME="$1"
    if [ -f "$NAME" ]
    then
        DIR=$(dirname -- "$NAME")
        NAME=$(cd -P "$DIR" > /dev/null && pwd -P)/$(basename -- "$NAME")
    fi
    while [ -h "$NAME" ]; do
        DIR=$(dirname -- "$NAME")
        SYM=$(readlink "$NAME")
        NAME=$(cd "$DIR" > /dev/null && cd $(dirname -- "$SYM") > /dev/null && pwd)/$(basename -- "$SYM")
    done
    echo "$NAME"
6c4edfa3   Alexandre   First Commit LabI...
34
35
}

07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Find a CLI version of PHP
findCliPhp() {
    for TESTEXEC in php php-cli /usr/local/bin/php
    do
        SAPI=`echo "<?= PHP_SAPI ?>" | $TESTEXEC 2>/dev/null`
        if [ "$SAPI" = "cli" ]
        then
            echo $TESTEXEC
            return
        fi
    done
    echo "Failed to find a CLI version of PHP; falling back to system standard php executable" >&2
    echo "php";
}

# If current path is a symlink, resolve to real path
realname="$0"
if [ -L "$realname" ] 
then
	realname=$(readlink -f "$0")
fi

CONSOLE=$(dirname -- "$(canonicalize "$realname")")
6c4edfa3   Alexandre   First Commit LabI...
59
60
APP=$(dirname "$CONSOLE")

07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
61
62
63
64
65
66
67
68
# If your CLI PHP is somewhere that this doesn't find, you can define a PHP environment
# variable with the correct path in it.
if [ -z "$PHP" ]
then
    PHP=$(findCliPhp)
fi

if [ $(basename $realname) != 'cake' ]
6c4edfa3   Alexandre   First Commit LabI...
69
then
07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
70
    exec $PHP "$CONSOLE"/cake.php $(basename $realname) "$@"
6c4edfa3   Alexandre   First Commit LabI...
71
else
07e4c3fb   Etienne Pallier   v4.108.0-3.7.9 - ...
72
    exec $PHP "$CONSOLE"/cake.php "$@"
6c4edfa3   Alexandre   First Commit LabI...
73
74
75
fi

exit