commit c9742f2ed77b02d8240d66dc1d4660891386eb11 Author: Robert Ransom rransom.8774@gmail.com Date: Fri Sep 2 03:25:11 2011 -0400
[2525 Linux] Make RelativeLink.sh work when run using a relative symlink --- src/RelativeLink/RelativeLink.sh | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/RelativeLink/RelativeLink.sh b/src/RelativeLink/RelativeLink.sh index 579612c..222bb6d 100755 --- a/src/RelativeLink/RelativeLink.sh +++ b/src/RelativeLink/RelativeLink.sh @@ -133,17 +133,32 @@ fi # If this script is being run through a symlink, we need to know where # in the filesystem the script itself is, not where the symlink is. myname="$0" -while [ -L "$myname" ]; do +if [ -L "$myname" ]; then # XXX readlink is not POSIX, but is present in GNU coreutils # and on FreeBSD. Unfortunately, the -f option (which follows # a whole chain of symlinks until it reaches a non-symlink - # path name) is a GNUism, so we can't safely use it. (Using - # it would be rude to FreeBSD users who currently have no - # other officially supported choice than TBB for Linux, and - # might even break compatibility with older versions of the - # GNU utility.) - myname="`readlink -n "$myname"`" -done + # path name) is a GNUism, so we have to have a fallback for + # FreeBSD. Fortunately, FreeBSD has realpath instead; + # unfortunately, that's also non-POSIX and is not present in + # GNU coreutils. + # + # If this launcher were a C program, we could just use the + # realpath function, which *is* POSIX. Too bad POSIX didn't + # make that function accessible to shell scripts. + + # If realpath is available, use it; it Does The Right Thing. + possibly_my_real_name="`realpath "$myname" 2>/dev/null`" + if [ "$?" -eq 0 ]; then + myname="$possibly_my_real_name" + else + # realpath is not available; hopefully readlink -f works. + myname="`readlink -f "$myname" 2>/dev/null`" + if [ "$?" -ne 0 ]; then + # Ugh. + complain "start-tor-browser cannot be run using a symlink on this operating system." + fi + fi +fi
# Try to be agnostic to where we're being started from, chdir to where # the script is.