Whirr
  1. Whirr
  2. WHIRR-507

Make whirr script executable from any path

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.7.0
    • Fix Version/s: 0.7.1
    • Component/s: None
    • Labels:
    • Environment:

      Linux (Ubuntu 11.04)

      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.

      1. whirr.noreadlink
        2 kB
        Marco Didonna
      2. whirr.readlink
        1 kB
        Marco Didonna
      3. whirr
        2 kB
        Marco Didonna
      4. whirr_script.patch
        1 kB
        Marco Didonna
      5. whirr_scala.patch
        0.8 kB
        Marco Didonna

        Activity

        Hide
        Andrei Savu added a comment -

        Committed to 0.7 branch.

        Show
        Andrei Savu added a comment - Committed to 0.7 branch.
        Hide
        Andrei Savu added a comment -

        Committed to trunk. Thanks Marco!

        Show
        Andrei Savu added a comment - Committed to trunk. Thanks Marco!
        Hide
        Andrei Savu added a comment -

        +1 works great. I will go ahead and commit this - I think I've seen a similar proposal on StackOverflow on a different question.

        Show
        Andrei Savu added a comment - +1 works great. I will go ahead and commit this - I think I've seen a similar proposal on StackOverflow on a different question.
        Hide
        Marco Didonna added a comment -

        It is special because it doesn't use readlink (not available under mac according to tom white) and it just works

        Show
        Marco Didonna added a comment - It is special because it doesn't use readlink (not available under mac according to tom white) and it just works
        Hide
        Andrei Savu added a comment -

        Is the Scala solution so special & unique? Let's try to have a version of the patch with that in and we will decide later if this is a license violation.

        Show
        Andrei Savu added a comment - Is the Scala solution so special & unique? Let's try to have a version of the patch with that in and we will decide later if this is a license violation.
        Hide
        Marco Didonna added a comment -

        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

        Show
        Marco Didonna added a comment - 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
        Hide
        Andrei Savu added a comment -

        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.

        Show
        Andrei Savu added a comment - 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.
        Hide
        Marco Didonna added a comment -

        This should be the correct patch, sorry about the old one

        Show
        Marco Didonna added a comment - This should be the correct patch, sorry about the old one
        Hide
        Andrei Savu added a comment -

        the patch removes some existing code. please update your branch.

        Show
        Andrei Savu added a comment - the patch removes some existing code. please update your branch.
        Hide
        Marco Didonna added a comment -

        here it is

        Show
        Marco Didonna added a comment - here it is
        Hide
        Andrei Savu added a comment -

        Marco can you generate this as a patch for the latest trunk? I've just committed a few more changes.

        Show
        Andrei Savu added a comment - Marco can you generate this as a patch for the latest trunk? I've just committed a few more changes.
        Hide
        Marco Didonna added a comment -

        Minor fixes to the whirr script

        Show
        Marco Didonna added a comment - Minor fixes to the whirr script
        Hide
        Andrei Savu added a comment -

        Moving this on the roadmap for 0.8.0.

        Show
        Andrei Savu added a comment - Moving this on the roadmap for 0.8.0.
        Hide
        Marco Didonna added a comment -

        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

        Show
        Marco Didonna added a comment - 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
        Hide
        Tom White added a comment -

        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.

        Show
        Tom White added a comment - 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.
        Hide
        Marco Didonna added a comment -

        minor fixes

        Show
        Marco Didonna added a comment - minor fixes
        Hide
        Marco Didonna added a comment -

        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.

        Show
        Marco Didonna added a comment - 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.
        Hide
        Tom White added a comment -

        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?

        Show
        Tom White added a comment - 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?
        Hide
        Marco Didonna added a comment - - 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.

        Show
        Marco Didonna added a comment - - 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.
        Hide
        Tom White added a comment -

        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?

        Show
        Tom White added a comment - 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?
        Hide
        Marco Didonna added a comment -

        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

        Show
        Marco Didonna added a comment - 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
        Hide
        Tom White added a comment -

        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

        Show
        Tom White added a comment - 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
        Hide
        Marco Didonna added a comment -

        The modified whirr scripts

        Show
        Marco Didonna added a comment - The modified whirr scripts

          People

          • Assignee:
            Marco Didonna
            Reporter:
            Marco Didonna
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development