--- bin/bwa.orig	2018-03-12 21:27:31.000000000 -0400
+++ bin/bwa	2018-03-18 16:04:20.381807263 -0400
@@ -1,13 +1,17 @@
 #!/bin/sh
 OS=$(uname)
-case "$0" in
-/*)	bin_dir=$(dirname "$0");;
-*)	bin_dir=$(dirname "$(pwd)/$0");;
-esac
-case "$bin_dir" in
-*/.)	install_dir=$bin_dir.;;
-*)	install_dir=$(dirname $bin_dir);;
-esac
+
+# Find original directory of bash script, resovling symlinks
+# http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in/246128#246128
+SOURCE="${BASH_SOURCE[0]}"
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+    DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+    SOURCE="$(readlink "$SOURCE")"
+    [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+bin_dir="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
+install_dir=$(dirname "$bin_dir")
+
 lib_dir=$install_dir/lib
 libexec_dir=$install_dir/libexec
 
