Derby
  1. Derby
  2. DERBY-3207

The bin scripts should be able to run when DERBY_HOME is not set

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 10.4.1.3
    • Fix Version/s: 10.6.1.0
    • Component/s: Demos/Scripts
    • Labels:
      None

      Description

      The scripts under bin should be able to run without requiring the users to set DERBY_HOME explicitly. The script derby_common.sh, which is sourced by all the scripts under bin, contains code to detect DERBY_HOME based on the value of $0, but since the scripts need to know DERBY_HOME in order to source derby_common.sh, they still fail when DERBY_HOME is not set.

      When I removed this part of bin/ij

      -------

      if [ -z "$DERBY_HOME" ] ; then
      echo "Error: DERBY_HOME is not set. Please set the DERBY_HOME environment variable"
      echo "to the location of your Derby installation."
      exit 1
      fi

      . $DERBY_HOME/bin/derby_common.sh

      -------

      and in-lined the code in derby_common.sh in its place, I was able to run ij successfully by typing the command './bin/ij' without setting DERBY_HOME first.

      1. d3207.diff
        10 kB
        Knut Anders Hatlen
      2. d3207.stat
        0.5 kB
        Knut Anders Hatlen

        Issue Links

          Activity

          Hide
          Knut Anders Hatlen added a comment -

          Committed revision 924209.

          Show
          Knut Anders Hatlen added a comment - Committed revision 924209.
          Hide
          Knut Anders Hatlen added a comment -

          I tested the patch by building the snapshot and release targets and verified that the scripts worked without DERBY_HOME in the following scenarios:

          1) when the script was executed by specifying the full path (absolute or relative) on the command line

          2) when invoking a symbolic link that pointed to one of the scripts

          3) when having the bin directory in PATH and invoking the script without specifying full path

          Examples of the above scenarios copied from my terminal window:

          $ unset DERBY_HOME
          $ ./db-derby-snapshot-10.6.0.0-923109M/bin/ij
          ij version 10.6
          ij> exit;
          $ ln -s db-derby-snapshot-10.6.0.0-923109M/bin/ij .
          $ ./ij
          ij version 10.6
          ij> exit;
          $ export PATH=`pwd`/db-derby-snapshot-10.6.0.0-923109M/bin:$PATH
          $ ij
          ij version 10.6
          ij> exit;

          Show
          Knut Anders Hatlen added a comment - I tested the patch by building the snapshot and release targets and verified that the scripts worked without DERBY_HOME in the following scenarios: 1) when the script was executed by specifying the full path (absolute or relative) on the command line 2) when invoking a symbolic link that pointed to one of the scripts 3) when having the bin directory in PATH and invoking the script without specifying full path Examples of the above scenarios copied from my terminal window: $ unset DERBY_HOME $ ./db-derby-snapshot-10.6.0.0-923109M/bin/ij ij version 10.6 ij> exit; $ ln -s db-derby-snapshot-10.6.0.0-923109M/bin/ij . $ ./ij ij version 10.6 ij> exit; $ export PATH=`pwd`/db-derby-snapshot-10.6.0.0-923109M/bin:$PATH $ ij ij version 10.6 ij> exit;
          Hide
          Knut Anders Hatlen added a comment -

          Here's a patch that addresses this issue. Before the patch can be applied, the original scripts must be moved from the bin directory to a new directory called bin/templates. Use the following commands to do that:

          mkdir bin/templates
          svn add bin/templates

          svn mv bin/dblook bin/templates/
          svn mv bin/ij bin/templates/
          svn mv bin/sysinfo bin/templates/
          svn mv bin/NetworkServerControl bin/templates/
          svn mv bin/startNetworkServer bin/templates/
          svn mv bin/stopNetworkServer bin/templates/
          svn mv bin/derby_common.sh bin/templates/

          Then the patch can be applied. The patch will make the following changes:

              • build.xml:
          • add a target that prepends the contents of derby_common.sh to each of the scripts in bin/templates/ and puts the resulting concatenated scripts directly under bin/
          • exclude the bin/template directory from the archives produced by "ant snapshot"
              • tools/release/build.xml:
          • exclude the bin/template directory from the bin archives created by "ant release"
              • bin/templates/ {ij,dblook,sysinfo,startNetworkServer,stopNetworkServer,NetworkServerControl}

                :

          • removed the following section from all the files, since the content of derby_common.sh will now be included directly in the scripts:

          -if [ -z "$DERBY_HOME" ] ; then

          • echo "Error: DERBY_HOME is not set. Please set the DERBY_HOME environment variable"
          • echo "to the location of your Derby installation."
          • exit 1
            -fi
            -
            -. $DERBY_HOME/bin/derby_common.sh
          Show
          Knut Anders Hatlen added a comment - Here's a patch that addresses this issue. Before the patch can be applied, the original scripts must be moved from the bin directory to a new directory called bin/templates. Use the following commands to do that: mkdir bin/templates svn add bin/templates svn mv bin/dblook bin/templates/ svn mv bin/ij bin/templates/ svn mv bin/sysinfo bin/templates/ svn mv bin/NetworkServerControl bin/templates/ svn mv bin/startNetworkServer bin/templates/ svn mv bin/stopNetworkServer bin/templates/ svn mv bin/derby_common.sh bin/templates/ Then the patch can be applied. The patch will make the following changes: build.xml: add a target that prepends the contents of derby_common.sh to each of the scripts in bin/templates/ and puts the resulting concatenated scripts directly under bin/ exclude the bin/template directory from the archives produced by "ant snapshot" tools/release/build.xml: exclude the bin/template directory from the bin archives created by "ant release" bin/templates/ {ij,dblook,sysinfo,startNetworkServer,stopNetworkServer,NetworkServerControl} : removed the following section from all the files, since the content of derby_common.sh will now be included directly in the scripts: -if [ -z "$DERBY_HOME" ] ; then echo "Error: DERBY_HOME is not set. Please set the DERBY_HOME environment variable" echo "to the location of your Derby installation." exit 1 -fi - -. $DERBY_HOME/bin/derby_common.sh
          Hide
          Knut Anders Hatlen added a comment -

          This should be an easy thing to fix, so I'll try to get it into 10.6. The Windows BAT files already works without DERBY_HOME set, so we only need to make this change for the Unix shell scripts.

          Show
          Knut Anders Hatlen added a comment - This should be an easy thing to fix, so I'll try to get it into 10.6. The Windows BAT files already works without DERBY_HOME set, so we only need to make this change for the Unix shell scripts.
          Hide
          Knut Anders Hatlen added a comment -

          The simple solution is to inline derby_common.sh in all the scripts. To avoid the cost of maintaining duplicated code, I think it's best if we only have templates for the scripts in the repository, and let ant do the inlining for us in the build process.

          Show
          Knut Anders Hatlen added a comment - The simple solution is to inline derby_common.sh in all the scripts. To avoid the cost of maintaining duplicated code, I think it's best if we only have templates for the scripts in the repository, and let ant do the inlining for us in the build process.

            People

            • Assignee:
              Knut Anders Hatlen
              Reporter:
              Knut Anders Hatlen
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development