Generalise determination of hacking directory path

Bash needs a special case to determine the dirname of the sourced path
(the hacking dir), but in all other cases, using $0 allows the script to
be sourced also from within the hacking directory, not only from its
parent.

Signed-off-by: martin f. krafft <madduck@madduck.net>
pull/3209/head
martin f. krafft 12 years ago
parent 39aa5e5eac
commit 581dea70d1

@ -3,11 +3,12 @@
# modifies environment for running Ansible from checkout # modifies environment for running Ansible from checkout
# When run using source as directed, $0 gets set to bash, so we must use $BASH_SOURCE # When run using source as directed, $0 gets set to bash, so we must use $BASH_SOURCE
if [ -n "$BASH_SOURCE" ] ; then case "$0" in
HACKING_DIR=`dirname $BASH_SOURCE` (bash)
else HACKING_DIR=${BASH_SOURCE%/*};;
HACKING_DIR="$PWD/hacking" (*)
fi HACKING_DIR=${0%/*};;
esac
# The below is an alternative to readlink -fn which doesn't exist on OS X # The below is an alternative to readlink -fn which doesn't exist on OS X
# Source: http://stackoverflow.com/a/1678636 # Source: http://stackoverflow.com/a/1678636
FULL_PATH=`python -c "import os; print(os.path.realpath('$HACKING_DIR'))"` FULL_PATH=`python -c "import os; print(os.path.realpath('$HACKING_DIR'))"`

Loading…
Cancel
Save