Bug in standalone subsonic.sh

General discussions.

Moderator: moderators

Bug in standalone subsonic.sh

Postby delcypher » Sat Oct 30, 2010 9:10 am

Hi came across a bug today when trying out Subsonic 4.1 in the bash shell script.

The bug is on lines 103-105

Code: Select all
if [ -e /bin/readlink ] || [ -e /usr/bin/readlink ]; then
    cd $(dirname $(readlink $0))

In my case $0='./subsonic.sh' and I have readlink (GNU coreutils) 8.6

Because I have readlink installed the if statement succeeds. The command $(readlink $0) returns nothing as it only returns a value if the file soft link. In my case ./subsonic.sh is not a soft link.

so then the command becomes
cd $(dirname )

dirname returns an error because it has no argument. Which means the finally executed command is just cd. This changes directory to the user's home directory which consequently causes subsonic to not start because the command to start subsonic assumes the jar file is in the current directory.

Code: Select all

  -Dsubsonic.home=${SUBSONIC_HOME} \
  -Dsubsonic.host=${SUBSONIC_HOST} \
  -Dsubsonic.port=${SUBSONIC_PORT} \
  -Dsubsonic.contextPath=${SUBSONIC_CONTEXT_PATH} \
  -Dsubsonic.defaultMusicFolder=${SUBSONIC_DEFAULT_MUSIC_FOLDER} \
  -Dsubsonic.defaultPodcastFolder=${SUBSONIC_DEFAULT_PODCAST_FOLDER} \
  -Dsubsonic.defaultPlaylistFolder=${SUBSONIC_DEFAULT_PLAYLIST_FOLDER} \
  -jar subsonic-booter-jar-with-dependencies.jar > ${LOG} 2>&1 &

I propose these set of commands instead of the if statement shown at the beginning.

Code: Select all
#if script was executed via symbolic link we should change to the directory of the file linked to
if [ -n "$(which readlink 2> /dev/null)" -a -n "$(readlink $0 2> /dev/null)" ]; then
    cd $(dirname $(readlink $0))

Hope someone finds this useful.
Posts: 109
Joined: Tue Jun 01, 2010 10:39 am

Postby sindre_mehus » Sat Oct 30, 2010 9:17 am


Thanks for pointing that out. I am aware of it and have fixed it in the next release.

My fix (which another friendly user suggested) is slightly different, but achieves the same:

Code: Select all
cd $(dirname $0)
if [ -L $0 ] && ([ -e /bin/readlink ] || [ -e /usr/bin/readlink ]); then
    cd $(dirname $(readlink $0))

Subsonic developer
User avatar
Posts: 1955
Joined: Tue Nov 29, 2005 6:19 pm
Location: Oslo, Norway

Return to General

Who is online

Users browsing this forum: No registered users and 4 guests