kobo / groovyserv

Groovy's startup acceralator.
http://kobo.github.io/groovyserv/
Other
98 stars 10 forks source link

GROOVYSERV_HOME resolution fails when binaries are symbolic links when using SH #19

Closed berngp closed 13 years ago

berngp commented 13 years ago

Given groovyserv installed at /usr/local/share/groovyserv/groovyserv-x.y.z.arch

When the binaries are linked at ln -s /usr/local/share/groovyserv/groovyserv-x.y.z.arch/bin/* /usr/local/bin

and the binaries are executed. $ groovyclient -v

Then the resolution of _GROOVYSERVHOME fails.

nobeans commented 13 years ago

Hmm, my groovyserv v0.5 on MacOSX which was installed by Homebrew is almost similar to the above environment. it works well.

installed dir: /usr/local/Cellar/groovyserv/0.5

binaries: /usr/local/bin/groovyclient -> ../Cellar/groovyserv/0.5/bin/groovyclient /usr/local/bin/groovyserver -> ../Cellar/groovyserv/0.5/bin/groovyserver

what's error message?

berngp commented 13 years ago

the problem is that, at least in Ubuntu and Centos (therefore Fedora and Redhat), the following statement doesn't resolve to true

if [ $(echo $ORIGINAL_FILEPATH | cut -c 1) == "/" ]

when we have

/usr/local/bin/groovyserver -> /usr/local/share/groovyserv/groovyserv-0.6-SNAPSHOT.x86_64/bin/groovyserver

honestly I don't know why it doesn't since the returned seems to be "/"

berngp commented 13 years ago

To add some more context the problem happens in sh but not in bash. Check it out in any *NIX env:

#!/bin/sh
resolve_symlink() {
   local TARGET=$1

   # if target is symbolic link
   if [ -L $TARGET ]; then
       local ORIGINAL_FILEPATH=`readlink $TARGET`
       #if [ $(echo ${ORIGINAL_FILEPATH} | grep -c "^/") -eq 1 ]; then
       if [ $(echo $ORIGINAL_FILEPATH | cut -c 1) == "/" ]; then
           echo "$ORIGINAL_FILEPATH"
       else
           echo "$(dirname $TARGET)/$ORIGINAL_FILEPATH"
       fi
   else
       echo "$TARGET"
   fi
}
expand_path() {
   local TARGET=$1
   if [ -d "$TARGET" ]; then
       echo $(cd $TARGET && pwd -P)
   elif [ -f "$TARGET" ]; then
       local TARGET_RESOLVED=$(resolve_symlink $TARGET)
       local FILENAME=$(basename $TARGET_RESOLVED)
       local DIR_EXPANDED="$(expand_path $(dirname $TARGET_RESOLVED))"
       echo "$DIR_EXPANDED/$FILENAME"
   else
       echo "$TARGET"
   fi
}
#echo "$(dirname $(dirname $(expand_path $1)))"
echo "$(expand_path $1)"

Test it with /bin/sh and with /bin/bash with

$  ./test.sh /usr/local/bin/groovyserver

_Got to love _sh, don't you..

berngp commented 13 years ago

so in sh it will work as follows..

 if [ $(echo $ORIGINAL_FILEPATH | cut -c 1) = "/" ]; then

... I will vote to keep on the grep and avoid confusion but either way its fine.

berngp commented 13 years ago

I closed it by mistake bu as of 2011-02-27 the issue is still open.

nobeans commented 13 years ago

Ok, I see. I didn't know that '==' in test command is available only on bash.

Before: at groovyserver:115

 if [ $(echo $ORIGINAL_FILEPATH | cut -c 1) == "/" ]; then

After: at groovyserver:115

 if [ $(echo $ORIGINAL_FILEPATH | cut -c 1) = "/" ]; then

Is it okay?

berngp commented 13 years ago

its fine :)

nobeans commented 13 years ago

pushed. thx for your report!