From 856b34f9f52ce2e7845bf740defe876d03a02aad Mon Sep 17 00:00:00 2001
From: Jose Lorenzo Rodriguez <jose.zap@gmail.com>
Date: Fri, 14 Oct 2011 22:05:43 -0430
Subject: [PATCH] Correctly interpreting symlinks

---
 cake/console/cake | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/cake/console/cake b/cake/console/cake
index cbb4fcf12..c3d8567e1 100755
--- a/cake/console/cake
+++ b/cake/console/cake
@@ -18,16 +18,15 @@
 # @license              MIT License (http://www.opensource.org/licenses/mit-license.php)
 #
 ################################################################################
-LIB=${0}
-SYM=$(readlink "$0")
+LIB=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && LIB=$LIB/$(basename -- "$0")
 
-if [ ! -n "$SYM" ]
-        then
-                LIB=${LIB%/*}"/"
-        else
-                LIB=${SYM%/*}"/"
-fi
+while [ -h $LIB ]; do
+    DIR=$(dirname -- "$LIB")
+    SYM=$(readlink $LIB)
+    LIB=$(cd $DIR && cd $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+done
 
+LIB=$(dirname -- "$LIB")/
 APP=`pwd`
 
 exec php -q ${LIB}cake.php -working "${APP}" "$@"