|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -METAFACTURE_HOME=$( dirname "$( realpath "$0" )" ) |
| 3 | +# `cd` is used with a relative path in this script. We may |
| 4 | +# end in an unexpected location if CDPATH is not empty. |
| 5 | +unset CDPATH |
| 6 | + |
| 7 | +if [ -z "$BASH_SOURCE" ] ; then |
| 8 | + echo "Error: cannot determine script location (\$BASH_SOURCE is not set)" >&2 |
| 9 | + exit 2 |
| 10 | +fi |
| 11 | +# If a symbolic link is used to invoke this script this link |
| 12 | +# needs to be resolved in order to find the directory where |
| 13 | +# the actual script file lives. Several tools exist for |
| 14 | +# resolving symbolic links. However, none of these tools is |
| 15 | +# available on all platforms. Hence, we try different ones |
| 16 | +# until we succeed. |
| 17 | +if [ -L "$BASH_SOURCE" ] ; then |
| 18 | + script_file=$( realpath "$BASH_SOURCE" 2> /dev/null ) || |
| 19 | + script_file=$( readlink -f "$BASH_SOURCE" 2> /dev/null ) || |
| 20 | + script_file=$( |
| 21 | + file=$BASH_SOURCE |
| 22 | + while [ -L "$file" ] ; do |
| 23 | + cd "$( dirname "$file" )" |
| 24 | + link_name=$( basename "$file" ) |
| 25 | + file=$( readlink "$link_name" 2> /dev/null ) || |
| 26 | + file=$( ls -ld "$link_name" | sed "s/^.\+ -> \(.\+\)$/\1/g" ) |
| 27 | + done |
| 28 | + cd "$( dirname "$file" )" |
| 29 | + echo "$( pwd )/$( basename "$file" )" |
| 30 | + ) |
| 31 | +else |
| 32 | + script_file=$BASH_SOURCE |
| 33 | +fi |
| 34 | +# Remove script file name from the path and make sure |
| 35 | +# that the path is absolute: |
| 36 | +METAFACTURE_HOME=$( cd "$( dirname "$script_file" )" ; pwd ) |
4 | 37 |
|
5 | 38 | # Fix path if running under cygwin:
|
6 | 39 | if uname | grep -iq cygwin ; then
|
|
0 commit comments