PerBothner / DomTerm

DOM/JavaScript-based terminal-emulator/console

Home Page:https://domterm.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Launcher script breaks if run as `bin/domterm`

rwhogg opened this issue · comments

The launcher script works if you run it as ./bin/domterm (starting from the source directory).
However, it doesn't work if you run it as just bin/domterm.

Output (I stuck a #bin/bash -x at the top) in the latter case:

++ which bin/domterm

  • thisfile=bin/domterm
  • test -L bin/domterm
    ++ sed -e 's|/bin$||'
    +++ dirname bin/domterm
    ++ echo bin
  • DOMTERM_DIR=bin
  • test -n ''
  • JAVA=/home/bob/linuxbin/java
  • EXTRA_ARG=
  • case "$1" in
  • EXTRA_ARG=--firefox
  • exec /home/bob/linuxbin/java -cp bin/domterm.jar:bin/java_websocket.jar: -Djava.library.path=bin org.domterm.websocket.DomServer --firefox
    Error: Could not find or load main class org.domterm.websocket.DomServer

I'll see if I can fix this myself.

I use bin/domterm all the time. Probably an incompatibility in "which":

$ which --version
GNU which v2.20, Copyright (C) 1999 - 2008 Carlo Wood.
GNU which comes with ABSOLUTELY NO WARRANTY;
This program is free software; your freedom to use, change
and distribute this program is protected by the GPL.

The man page says: "For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt."

Seems like the MacOS version (presumably from BSD?) isn't as capable.

We also have the option of using the bash builtin 'type',but that doesn't handle the "bin/domterm" case, it appears.

My which doesn't even support --version (or even -v) as an option - looks like I'm using the debianutils version.

It's worth noting that you mentioned bash. I'm on zsh, and so are many others. Since any Linux worth its salt has bash installed and so does OS X, would you be willing to put a shebang line in the script to ensure everyone is running it on the same shell?

Yes, I'm fine restricting it to bash. After all, I require Java (for now); maximum portability can wait. (The Windows port may be more interesting ...)

brew install gnu-which fixed it for me. Thanks for the suggestion about which!

I'm going to close this. Feel free to reopen if you want.

I also ran into this. As it gives a first bad impression ("doesn't run out of the box"), I suggest you re-open this (I can't); I'll submit a patch later.

Would it make sense to use 'type -p'? It seems to Do The Right Thing (based on a few tests). It means we require bash (though ksh also seems to work). As a bonus, it's faster, since it's built-in.

What do you think of the following:

#!/bin/bash
thisfile=`type -p $0`
case "$thisfile" in
  "") echo "installation error - can't find path to $0"; exit -1 ;;
  /*) ;;
  *) thisfile="$PWD/$thisfile"  ;;
esac         
while test -L "$thisfile"; do thisfile=$(readlink -f "$thisfile"); done
DOMTERM_DIR=`echo $(dirname $thisfile) | sed -e 's|/bin$||'`

etc as before

I can verify that the above works.

I checked this change in. Thanks for testing it.

Yes, type -p is more portable (and works for me, too) -- but then I wonder why this code needs to be so complicated? See my #22.