Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/utils/bin/activate.bash
diff options
context:
space:
mode:
Diffstat (limited to 'utils/bin/activate.bash')
-rwxr-xr-xutils/bin/activate.bash31
1 files changed, 27 insertions, 4 deletions
diff --git a/utils/bin/activate.bash b/utils/bin/activate.bash
index 8695009..e3cf2c7 100755
--- a/utils/bin/activate.bash
+++ b/utils/bin/activate.bash
@@ -1,8 +1,30 @@
-if [ -z "$PACKAGE_HOME" ]; then
+if [ -z "${BASH_ARGV[0]}" ]; then
+
+ # as a last recourse, use the present working directory
PACKAGE_HOME=$(pwd)
+
+else
+
+ # get the absolute path of the executable
+ SELF_PATH=$(
+ cd -P -- "$(dirname -- "${BASH_ARGV[0]}")" \
+ && pwd -P
+ ) && SELF_PATH=$SELF_PATH/$(basename -- "${BASH_ARGV[0]}")
+
+ # resolve symlinks
+ while [ -h "$SELF_PATH" ]; do
+ DIR=$(dirname -- "$SELF_PATH")
+ SYM=$(readlink -- "$SELF_PATH")
+ SELF_PATH=$(cd -- "$DIR" && cd -- $(dirname -- "$SYM") && pwd)/$(basename -- "$SYM")
+ done
+
+ PACKAGE_HOME=$(dirname -- "$(dirname -- "$SELF_PATH")")
+
fi
+export PACKAGE_HOME
+
# which -s narwhal doesn't work (os x 10.5, kriskowal)
if [ -f "$PACKAGE_HOME"/bin/narwhal ]; then
NARWHAL="$PACKAGE_HOME"/bin/narwhal
@@ -13,8 +35,7 @@ else
if [ "$?" -ne 127 ]; then
NARWHAL=narwhal
else
- echo "ERROR: narwhal is not in your PATH or $PACKAGE_HOME/bin."
- exit
+ echo "ERROR: narwhal is not in your PATH nor in $PACKAGE_HOME/bin." >&2
fi
fi
@@ -23,5 +44,7 @@ if [ -f "$PACKAGE_HOME"/narwhal.conf ]; then
export NARWHAL_DEFAULT_PLATFORM
fi
-export PATH="$("$NARWHAL" --package "$PACKAGE_HOME" --path :)"
+if [ "$NARWHAL" ]; then
+ export PATH="$("$NARWHAL" --package "$PACKAGE_HOME" --path :)"
+fi