+this="$0"
+
+# OSX 10.8 readlink doesn't have -f
+while [ -h "$this" ]; do
+ # [ -h should guarantee that readlink output will be non-null
+ link=`readlink -n "$this"`
+ # if absolute path
+ if expr "$link" : '^/.*' > /dev/null; then
+ this="$link"
+ else
+ this=`dirname "$this"`/"$link"
+ fi
+done
+BASE=`dirname "$this"`
+