Menu

#1321 The launcher script does not work with the plain ZIP version on MacOS (again)

SQuirreL
open
nobody
None
5
2019-01-19
2017-10-31
No

The issue reported in the previous "closed-fixed" ticket #1287 (https://sourceforge.net/p/squirrel-sql/bugs/1287/) is introduced again to the launcher script for version 3.8.0

On MacOS, the launcher script contains a hard-coded reference to Contents/Resources/Java

if $macosx ; then
    SQUIRREL_SQL_HOME=`dirname "$0"`/Contents/Resources/Java
else
        SQUIRREL_SQL_HOME=`dirname "$0"`
fi

The should work correctly when the application is installed through the standard installer procedure, but fails to start Squirrel SQL when one uses the plain ZIP version (since there, the original (non-Mac specific) directory layout is present)

Please see the original ticket #1287 (https://sourceforge.net/p/squirrel-sql/bugs/1287/) for proposed solution and further details.

Discussion

  • Bill Horvath

    Bill Horvath - 2017-11-02

    I've replicated this problem after running the installer. The launcher script is called when I click the application icon, and it fails silently. When I add some echo calls to the script and run it from the command line, I can see it doesn't correctly set the value of SQUIRREL_SQL_HOME, which breaks the JavaVersionChecker call.

     
  • Bill Horvath

    Bill Horvath - 2017-11-02

    (Note: Peter and I are unrelated AFAIK.)

     
  • Gerd Wagner

    Gerd Wagner - 2017-11-04

    Peter,

    the 3.8.0 script contains the code you suggested in bug #1287 which itself contains a reference to Contents/Resources/Java. But the code you introduced in the following if statement tries to redefine the variable SQUIRREL_SQL_HOME.

    It would be nice if you could check your suggested change again and compare it to the existing 3.8.0 script.

    In the latest snapshots the MAC OS and Linux-Scripts where separated. It would be very kind if you could have a look at that version, too.

    Thanks in advance
    Gerd

     
  • Peter G. Horvath

    Gerd,

    I might be missing something, but I do not see my suggested code changes in the squirrel-sql.sh from squirrelsql-3.8.0-standard.zip (downloaded from Squirrel SQL's home page)

    As you see the check I proposed is not there ( could this maybe a build issue?):

    # Are we running within Cygwin on some version of Windows or on Mac OS X?
    cygwin=false;
    macosx=false;
    case "`uname -s`" in
        CYGWIN*) 
            cygwin=true 
            ;;
        Darwin*) 
            macosx=true
            ;;
    esac
    
    # SQuirreL home. This is the plain zip version of squirrel-sql.sh, so the installer isn't run.  In this case
    # the script cannot be modified by the installer to hard-code the install path.  We prefer to specify squirrel
    # home as an absolute path, so that the command will work when exec'd from any location. So we attempt to 
    # detect the absolute path using dirname "$0", which should work in most cases.  
    if $macosx ; then
            SQUIRREL_SQL_HOME=`dirname "$0"`/Contents/Resources/Java
    else 
            SQUIRREL_SQL_HOME=`dirname "$0"`
    fi
    
    # SQuirreL home in Unix format.
    if $cygwin ; then
            UNIX_STYLE_HOME=`cygpath "$SQUIRREL_SQL_HOME"`
    else
            UNIX_STYLE_HOME="$SQUIRREL_SQL_HOME"
    fi
    
    cd "$UNIX_STYLE_HOME"
    
    # Check to see if the JVM meets the minimum required to run SQuirreL and inform the user if not and skip 
    # launch.  versioncheck.jar is a special jar file which has been compiled with javac version 1.2.2, which 
    # should be able to be run by that version or higher. The arguments to JavaVersionChecker below specify the 
    # minimum acceptable version (first arg) and any other acceptable subsequent versions.  <MAJOR>.<MINOR> should 
    # be all that is necessary for the version form. 
    $JAVACMD -cp "$UNIX_STYLE_HOME/lib/versioncheck.jar" JavaVersionChecker 1.6 1.7 1.8
    if [ "$?" = "1" ]; then
      exit
    fi
    
     
  • Peter G. Horvath

    My proposed solution of changing

    if $macosx ; then
            SQUIRREL_SQL_HOME=`dirname "$0"`/Contents/Resources/Java
    else 
            SQUIRREL_SQL_HOME=`dirname "$0"`
    fi
    

    to

    if $macosx ; then
        SQUIRREL_SQL_HOME=`dirname "$0"`/Contents/Resources/Java
        if [ ! -d "$SQUIRREL_SQL_HOME" ]; then
            # We assume that this is the ZIP file extracted on MacOS,
            # so, fall-back to the defult path
            SQUIRREL_SQL_HOME=`dirname "$0"`
        fi
    else
            SQUIRREL_SQL_HOME=`dirname "$0"`
    fi
    

    is just not there. I am wondering, why is that, because I was under the impression the proposed code change was accepted into the code base.

     
  • Gerd Wagner

    Gerd Wagner - 2017-11-06

    Peter,
    sorry, I didn't update the scripts of the plain zip releases.

    I just released a new snapshot
    https://sourceforge.net/projects/squirrel-sql/files/3-snapshots/snapshot-20171106_2206/
    that as usually contains the installers an exceptionally also the plain zips. The plain zip scripts are updated in the snapshot. Please note that there are now separate scripts for Linux/Unix and Mac. The installers automatically come with the right script but the plain zip packages now contain squirrel-sql.sh for Linux/Unix and squirrel-sql-mac.sh for the Mac.

    It would be nice if you had a look.

    Thanks in advance
    Gerd

     
  • Peter G. Horvath

    Hi Gerd,

    I tested this, and unfortunately, there seem to be some issues. The launcher script works properly if you start the script from the same directory, but fails if you start from anywhere else:

    This is the output I see:

    $ squirrelsql-snapshot-20171106_2206-optional/squirrel-sql-mac.sh
    +++ dirname squirrelsql-snapshot-20171106_2206-optional/squirrel-sql-mac.sh
    ++ cd squirrelsql-snapshot-20171106_2206-optional
    ++ pwd
    
    + ABSPATH=/Users/FOOBAR/Downloads/squirrelsql-snapshot-20171106_2206-optional
    + IZPACK_JAVA_HOME=/Library/Internet
    + Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    squirrelsql-snapshot-20171106_2206-optional/squirrel-sql-mac.sh: line 28: Plug-Ins/JavaAppletPlugin.plugin/Contents/Home: No such file or directory
    + '[' -d /Users/FOOBAR/.sdkman/candidates/java/current -a -x /Users/FOOBAR/.sdkman/candidates/java/current/bin/java ']'
    + JAVACMD=/Users/FOOBAR/.sdkman/candidates/java/current/bin/java
    + macosx=false
    + case "`uname -s`" in
    ++ uname -s
    + macosx=true
    + true
    ++ echo /Users/FOOBAR/Downloads/squirrelsql-snapshot-20171106_2206-optional
    ++ grep -o '^/.*/Contents/'
    + SQUIRREL_SQL_HOME=Resources/Java
    + '[' '!' -d Resources/Java ']'
    ++ dirname squirrelsql-snapshot-20171106_2206-optional/squirrel-sql-mac.sh
    + SQUIRREL_SQL_HOME=squirrelsql-snapshot-20171106_2206-optional
    + UNIX_STYLE_HOME=squirrelsql-snapshot-20171106_2206-optional
    + cd squirrelsql-snapshot-20171106_2206-optional
    + /Users/FOOBAR/.sdkman/candidates/java/current/bin/java -cp squirrelsql-snapshot-20171106_2206-optional/lib/versioncheck.jar JavaVersionChecker 1.6 1.7 1.8 9
    Error: Could not find or load main class JavaVersionChecker
    + '[' 1 = 1 ']'
    + exit
    

    I think the original fix proposed in https://sourceforge.net/p/squirrel-sql/bugs/1287/ should work correctly. I personally don't like the idea of having separate launcher script for Mac.

     
  • Gerd Wagner

    Gerd Wagner - 2017-11-17

    Peter,
    although this change contradicts the change made for bug
    https://sourceforge.net/p/squirrel-sql/bugs/1310
    I changed it back to your prefered version.

    Since there seems to be no version that works for all Mac users the problem is well documented in the script itself to allow users to try out which version works for them.

    I just released a snapshot
    https://sourceforge.net/projects/squirrel-sql/files/3-snapshots/snapshot-20171118_0029/
    containing even the plain zips. It would be nice, Peter, if you could give it another try.

    Thanks
    Gerd

     

    Last edit: Gerd Wagner 2017-11-18
  • Harry Evans

    Harry Evans - 2017-11-29

    The following changes seem to work for me when invoking the script manually (from any dir) as /Applications/SQuirreLSQL.app/Contents/MacOS/squirrel-sql.sh and when double clicking the icon from the Applications folder:
    change

    # SQuirreL home.
    if $macosx ; then
        SQUIRREL_SQL_HOME=`dirname "$0"`/Contents/Resources/Java
    # resolves to /Applications/SQuirreLSQL.app/Contents/MacOS/Contents/Resources/Java which does not exist
    

    to

    # SQuirreL home.
    if $macosx ; then
        SQUIRREL_SQL_HOME=`dirname "$0"`/../Resources/Java
    # resolves to /Applications/SQuirreLSQL.app/Contents/Resources/Java which does exist, and is the correct path.
    

    Just this fix will make the script work when invoked manually from the terminal. However, when you double click the icon and get the dreaded Service exited with abnormal code: 127 error in console, you can't see any of your echo statements. I wrapped the entire last line of the script in a subshell, and logged it to syslog. This is what printed in the console:

    XX/XX/17 XX:XX:XX.XXX AM syslog[96682]: /Applications/SQuirreLSQL.app/Contents/MacOS/squirrel-sql.sh: line 123: /Library/Internet: No such file or directory
    

    the last line of the script needs to change from:

    $JAVACMD -Xmx256m -cp "$CP" $MACOSX_SQUIRREL_PROPS -splash:"$SQUIRREL_SQL_HOME/icons/splash.jpg" net.sourceforge.squirrel_sql.client.Main --log-config-file "$UNIX_STYLE_HOME"/log4j.properties --squirrel-home "$UNIX_STYLE_HOME" $NATIVE_LAF_PROP $SCRIPT_ARGS
    

    to

    "$JAVACMD" -Xmx256m -cp "$CP" $MACOSX_SQUIRREL_PROPS -splash:"$SQUIRREL_SQL_HOME/icons/splash.jpg" net.sourceforge.squirrel_sql.client.Main --log-config-file "$UNIX_STYLE_HOME"/log4j.properties --squirrel-home "$UNIX_STYLE_HOME" $NATIVE_LAF_PROP $SCRIPT_ARGS
    

    to quote the $JAVACMD invocation, since (at least on my box, and I think many others) $JAVACMD resolves to a directory with a space when doubleclicked (such as /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java) but when run from the terminal resolves to a directory without a space (such as /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java). Some Macs might resolve the doubleclick invocation to a dir without a space, but quoting $JAVACMD will make it work in all cases.

    Hoepfully this also works for others.

     
  • Harry Evans

    Harry Evans - 2017-11-29

    Missed one instance. Also need to change from:

    $JAVACMD -cp "$UNIX_STYLE_HOME/lib/versioncheck.jar" JavaVersionChecker 1.6 1.7 1.8
    if [ "$?" = "1" ]; then
    

    to

    "$JAVACMD" -cp "$UNIX_STYLE_HOME/lib/versioncheck.jar" JavaVersionChecker 1.6 1.7 1.8
    if [ "$?" = "1" ]; then
    

    Given that the unquoted $JAVACMD fails with a 127, the script would just keep chugging along, whether version was correct or not. Quoting it makes sure the command is always actually invoked. I would also change the if statement from

    if [ "$?" = "1" ]; then
    

    to

    if [ "$?" != "0" ]; then
    

    in order to catch all possible failure types, since (I think) you want to fail for any non zero error type, vs only failing explicitly on 1.

     
  • Gerd Wagner

    Gerd Wagner - 2017-12-02

    Harry,

    except from
    SQUIRREL_SQL_HOME=dirname "$0"/../Resources/Java
    all your suggestions are integrated in the MAC scripts.

    SQUIRREL_SQL_HOME=dirname "$0"/../Resources/Java
    was added as a comment only. The lines next to the comment were subject to a lively discussion. Part of it you can find above other parts are in bugs 1287, 1310.
    A comment above the different possible lines to which yours now belongs hints users to try out which works for them.

    A new snapshot will be released soon that contains your changes. It would be nice if you could give it a try.

    Thanks
    Gerd

     
  • Harry Evans

    Harry Evans - 2017-12-06

    Gerd,

    Thanks for the update. I will try the latest snapshot tonight ot tomorrow. On the one item that you left two versions of the command for, I was unable to find any additional discussion. Is there any thread I can read with the details?

    The reason I ask is that, according to Apple, SquirrelQL is using the correct directory structure:

    SQuirreLSQL.app/
       Contents/
          Info.plist
          MacOS/
            squirrel-sql.sh      
          Resources/
            Java/
    

    When you double-click on SQuirreLSQL icon in the Application folder on a Mac, the line you left active in scquirrel-sql.sh will resolve

    `dirname "$0"`
    

    to

    /Applications/SQuirreLSQL.app/Contents/MacOS
    

    When you append /Contents/Resources/Java to that, you get /Applications/SQuirreLSQL.app/Contents/MacOS/Contents/Resources/Java which clearly is not the path to reach the "Java" directory in the directory tree. The path you want is /Applications/SQuirreLSQL.app/Contents/Resources/Java. You could use dirname twice to get this, and append /Contents/Resources/Java to it, or what I did, which used ".." given that we know where we are in the bundle reletive hierarchy. Unless dirname "$0" somehow returns a different value on some mac systems when running the script from the place it is installed by the installer, I don't see how the derived path can ever be correct. Like I said, I would love to understand the opposite viewpoint, so if it is documented somewhere, can you provide a link?

     

    Last edit: Harry Evans 2017-12-06
  • Connor Sadler

    Connor Sadler - 2017-12-12

    Hi,

    This seems to be a problem in the released squirrel-sql-3.8.0-MACOSX-install.jar
    I installed using the wizard-type installer into /Applications/SQuirreLSQL.app
    Clicking on the new application icon then did nothing (other than wobble the icon for a couple of seconds)
    I found the squirrel-sql.sh and found that the paths are incorrect as described in this thread.

    If I run the script through Terminal I see the error: Error: Could not find or load main class JavaVersionChecker

    I can hack the script to correct the path:
    UNIX_STYLE_HOME=$UNIX_STYLE_HOME/../Resources/Java

    Is this issue being addressed?
    Is there a different way to install on Mac OS please?

    Regards,

    Connor

     
  • Pete K.

    Pete K. - 2018-03-22

    The latest snapshot is also still missing quotes in this line:

    # IZPACK_JAVA_HOME is filtered in by the IzPack installer when this script is installed
    IZPACK_JAVA_HOME="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home"
    

    I had to add the double-quotes around the path name in order to get SQuirrelSQL to launch. Can IzPack be configured to put those quotes in?

     
  • Gerd Wagner

    Gerd Wagner - 2018-04-04

    Pete, the double quotes are added and are committed to our GIT repository. The changes will be available in future snapshots and versions.

     
  • Frank Kemmer

    Frank Kemmer - 2018-04-25

    I had the problem, that the squirrel bash script didn't start the program.

    When I looked into the script, I found a comment saying:

    "Mac users are not able which of the three lines below works correctly"

    Since I have a Macbook with MacOS High Sierra ... here are my two cents ...

    $ uname -a
    Darwin <myhostname> 17.5.0 Darwin Kernel Version 17.5.0: Mon Mar 5 22:24:32 PST 2018; root:xnu-4570.51.1~1/RELEASE_X86_64 x86_64</myhostname>

    When you call squirrel as App, the bash script variable $0 returns the absolute path to the directory, the script resides in. Assuming the standard installation directory /Application this means e.g.:

    /Applications/SQuirreLSQL.app/Contents/MacOS

    I used the following code to set the squirrel home:

    #    SQUIRREL_SQL_HOME=`dirname "$0"`/Contents/Resources/Java
        APP_MacOS_DIR=$(dirname "$0")
        APP_CONTENTS_DIR=$(dirname "${APP_MacOS_DIR}")
        SQUIRREL_SQL_HOME="${APP_CONTENTS_DIR}/Resources/Java"
        echo "### SQUIRREL_SQL_HOME: [${SQUIRREL_SQL_HOME}]"
    #    SQUIRREL_SQL_HOME=$(echo $ABSPATH | grep -o '^/.*/Contents/')Resources/Java
    #    SQUIRREL_SQL_HOME=`dirname "$0"`/../Resources/Java
    

    On my mac this works. Personally I would recommend the way ant uses, to determine JAVA_HOME and add the lib path to the Resources/Java/ via a lib option as the ant bash script does. That way you coud base your code on a well tested script and do it in a way that has proven quite stable.

    Hope I could help a little bit ... Keep up the good work.

     

    Last edit: Frank Kemmer 2018-04-25
  • Gerd Wagner

    Gerd Wagner - 2018-05-12

    Frank,
    just added your suggestion as a new alternative to the MAC OS launch script. It will be available in future snapshots and versions.
    Thanks
    Gerd

     
  • Joseph Coco

    Joseph Coco - 2019-01-18

    Alternative 2 worked for me. I didn't try 3. I was having issues previously, so instead of just opening the jar via Finder I used a specific java with -jar in the terminal to open it.

    SQUIRREL_SQL_HOME=$(echo $ABSPATH | grep -o '^/.*/Contents/')Resources/Java

    MacOS 10.14.1
    My Java path: /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
    Java version: build 1.8.0_202-ea-b03
    Jvm version: 64-Bit Server VM (build 25.202-b03, mixed mode)

    Why not put some debugging code in the script to suggest switching the path inside the script if it fails? That would have saved me a lot of time, I thought it was a Java issue.

     
  • Gerd Wagner

    Gerd Wagner - 2019-01-19

    Joseph, could you suggest such a change to the script?

     

Log in to post a comment.

MongoDB Logo MongoDB