Details

Description

I personally find very painful to be forced to call whirr script using its whole path. I'd prefer to add whirr script to my $PATH env variable so that I can call whirr from anywhere. I've modified the whirr script according to this purpose.
I've created two version of the modified script:

one that uses the readlink command

one that doesn't used the former command.

I only tested under Ubuntu 11.04 so I've no idea whether or not the readlink command is available on other distros. So please test and comment.

Tom White
added a comment - 09/Feb/12 19:58 This would be a good one to fix. Thanks for taking it on, Marco.
The readlink command isn't available on Mac, so we want to avoid using it. In Hadoop we're using BASH_SOURCE to resolve the script directory, so perhaps we could do the same here. See HADOOP-7089 , and e.g. http://svn.apache.org/repos/asf/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/bin/hadoop-daemon.sh

Marco Didonna
added a comment - 09/Feb/12 21:33 Does the whirr.noreadlink script work on mac? I was unable to successfully use the BASH_SOURCE approach...
The whirr.noreadlink file seems a good candidate to me

Tom White
added a comment - 09/Feb/12 22:01 It seems to work. However, can you give an example of when the existing script doesn't work please?
> I was unable to successfully use the BASH_SOURCE approach...
What was the problem?

The problem with the existing script is quite simple. If you use a simbolic link to the whirr script and you put it under, for example, /usr/bin the script doesn't work. Same thing happens if you add the whirr/bin dir to the $PATH.
The problem with the $BASH_SOURCE is that it simply it points to the directory from which the script is invoked (eg the user home directory) whereas the whirr.noreadlink follows the link in order to find the directory in which whirr and all its libraries are installed.

Marco Didonna
added a comment - 09/Feb/12 22:13 - edited The problem with the existing script is quite simple. If you use a simbolic link to the whirr script and you put it under, for example, /usr/bin the script doesn't work. Same thing happens if you add the whirr/bin dir to the $PATH.
The problem with the $BASH_SOURCE is that it simply it points to the directory from which the script is invoked (eg the user home directory) whereas the whirr.noreadlink follows the link in order to find the directory in which whirr and all its libraries are installed.

Tom White
added a comment - 10/Feb/12 05:25 Thanks for the explanation. Your whirr.noreadlink script contains a readlink (It worked for me earlier as I had forgotten that I had installed a readlink script on my Mac for testing.)
Is there any way to rewrite not to use readlink?

You're right, I didn't realize in the whirr.noreadlink script there is a readlink call.
So I took inspiration from the hadoop script which uses a $HADOOP_HOME that point to the root of the hadoop installation. Does it seem a reasonable approach?

I did find an elegant solution to this issue in the scala script that launches the scala interpreter ... I think there may be some licensing issues if we use their solution.

Marco Didonna
added a comment - 10/Feb/12 09:34 You're right, I didn't realize in the whirr.noreadlink script there is a readlink call.
So I took inspiration from the hadoop script which uses a $HADOOP_HOME that point to the root of the hadoop installation. Does it seem a reasonable approach?
I did find an elegant solution to this issue in the scala script that launches the scala interpreter ... I think there may be some licensing issues if we use their solution.

Tom White
added a comment - 14/Feb/12 04:29 This works for me on Mac except when the symlink is to the whirr script (and not say the bin directory). Does it work for you?
Also, the patch mentions HADOOP_HOME when it should be WHIRR_HOME.

Marco Didonna
added a comment - 14/Feb/12 11:28 Sorry for the hadoop "typo". Btw I do have a symblink to the whirr script in my /usr/bin directory and it works perfectly, assuming WHIRR_HOME is properly set

Andrei Savu
added a comment - 16/Feb/12 09:31 A few notes:
for consistency we should user uppercase for bash variables (e.g. this, bin, script etc.)
can we check for readlink and use that command if available?
if hash readlink 2>/devnull; then echo "I can haz readlink"; fi
See the following SO question for more suggestions:
http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
I don't like the idea of having to set a value for WHIRR_HOME.

We can definitely use a readlink if available, but the problem is the plan B in case readlink is not available. I did use that so question but basically all answers use readlink. There's an elegant solution in the scala script but I'm afraid it would be licence violation if we used it

Marco Didonna
added a comment - 16/Feb/12 09:41 We can definitely use a readlink if available, but the problem is the plan B in case readlink is not available. I did use that so question but basically all answers use readlink. There's an elegant solution in the scala script but I'm afraid it would be licence violation if we used it