Symlinks and JBoss AS ./bin/*.sh scripts

View: New views
5 Messages — Rating Filter:   Alert me  

Symlinks and JBoss AS ./bin/*.sh scripts

by Emmanuel Bernard :: Rate this Message:

| View Threaded | Show Only this Message

Hey guys,
Over the week-end I've packaged JBoss AS 6 into HomeBrew (a Mac OS X packaging system made of git and ruby).
I've discovered that our scripts are not symlinks friendly and will fail (often not finding the jars).

I've fixed the issue but I wanted to get a review of my work. Let me know if you thing there could be a problem, otherwise I'll apply them to SVN.

I've basically replaced

DIRNAME=`dirname $0`
PROGNAME=`basename $0`

with

# Extract the directory and the program name
# takes care of symlinks
PRG="$0"
while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG="`dirname "$PRG"`/$link"
  fi
done
DIRNAME=`dirname "$PRG"`
PROGNAME=`basename "$PRG"`

Full details and full patch available here https://jira.jboss.org/browse/JBAS-8670

Emmanuel
_______________________________________________
jboss-development mailing list
jboss-development@...
https://lists.jboss.org/mailman/listinfo/jboss-development

Re: Symlinks and JBoss AS ./bin/*.sh scripts

by David M. Lloyd-3 :: Rate this Message:

| View Threaded | Show Only this Message

On 11/28/2010 10:18 AM, Emmanuel Bernard wrote:
> Hey guys,
> Over the week-end I've packaged JBoss AS 6 into HomeBrew (a Mac OS X packaging system made of git and ruby).
> I've discovered that our scripts are not symlinks friendly and will fail (often not finding the jars).
>
> I've fixed the issue but I wanted to get a review of my work. Let me know if you thing there could be a problem, otherwise I'll apply them to SVN.
> [...]
>    ls=`ls -ld "$PRG"`
>    link=`expr "$ls" : '.*->  \(.*\)$'`

This is fragile I think.  It'd probably be better to use "readlink"
instead, whose actual purpose is to read links.

--
- DML
_______________________________________________
jboss-development mailing list
jboss-development@...
https://lists.jboss.org/mailman/listinfo/jboss-development

Re: Symlinks and JBoss AS ./bin/*.sh scripts

by Emmanuel Bernard :: Rate this Message:

| View Threaded | Show Only this Message


On 28 nov. 2010, at 23:03, David M. Lloyd wrote:

> On 11/28/2010 10:18 AM, Emmanuel Bernard wrote:
>> Hey guys,
>> Over the week-end I've packaged JBoss AS 6 into HomeBrew (a Mac OS X packaging system made of git and ruby).
>> I've discovered that our scripts are not symlinks friendly and will fail (often not finding the jars).
>>
>> I've fixed the issue but I wanted to get a review of my work. Let me know if you thing there could be a problem, otherwise I'll apply them to SVN.
>> [...]
>>   ls=`ls -ld "$PRG"`
>>   link=`expr "$ls" : '.*->  \(.*\)$'`
>
> This is fragile I think.  It'd probably be better to use "readlink"
> instead, whose actual purpose is to read links.

I've tried your approach but I had a couple of issues. The main one is that readlink -f (recursive) is not standard across all platforms. The second issue I had was that readlink sometimes return links to the script basedir, sometimes as absolute. I imagine I could circumvent issue 2 (I've something for issue 1) but the fix will likely end up as weak as the original proposal (that comes from mvn, tomcat and co, so I imagine is decently battle tested).

Is that worth the work?

Emmanuel
_______________________________________________
jboss-development mailing list
jboss-development@...
https://lists.jboss.org/mailman/listinfo/jboss-development

Re: Symlinks and JBoss AS ./bin/*.sh scripts

by David M. Lloyd-3 :: Rate this Message:

| View Threaded | Show Only this Message

On 11/29/2010 08:04 AM, Emmanuel Bernard wrote:

>
> On 28 nov. 2010, at 23:03, David M. Lloyd wrote:
>
>> On 11/28/2010 10:18 AM, Emmanuel Bernard wrote:
>>> Hey guys,
>>> Over the week-end I've packaged JBoss AS 6 into HomeBrew (a Mac OS X packaging system made of git and ruby).
>>> I've discovered that our scripts are not symlinks friendly and will fail (often not finding the jars).
>>>
>>> I've fixed the issue but I wanted to get a review of my work. Let me know if you thing there could be a problem, otherwise I'll apply them to SVN.
>>> [...]
>>>    ls=`ls -ld "$PRG"`
>>>    link=`expr "$ls" : '.*->   \(.*\)$'`
>>
>> This is fragile I think.  It'd probably be better to use "readlink"
>> instead, whose actual purpose is to read links.
>
> I've tried your approach but I had a couple of issues. The main one is that readlink -f (recursive) is not standard across all platforms. The second issue I had was that readlink sometimes return links to the script basedir, sometimes as absolute. I imagine I could circumvent issue 2 (I've something for issue 1) but the fix will likely end up as weak as the original proposal (that comes from mvn, tomcat and co, so I imagine is decently battle tested).
>
> Is that worth the work?

I guess it depends on how sure you are that "ls" will always output the
link target after a "->".  I guess we could always try it and see if
anyone complains.
--
- DML
_______________________________________________
jboss-development mailing list
jboss-development@...
https://lists.jboss.org/mailman/listinfo/jboss-development

Re: Symlinks and JBoss AS ./bin/*.sh scripts

by Emmanuel Bernard :: Rate this Message:

| View Threaded | Show Only this Message


On 29 nov. 2010, at 16:59, David M. Lloyd wrote:

> On 11/29/2010 08:04 AM, Emmanuel Bernard wrote:
>>
>> On 28 nov. 2010, at 23:03, David M. Lloyd wrote:
>>
>>> On 11/28/2010 10:18 AM, Emmanuel Bernard wrote:
>>>> Hey guys,
>>>> Over the week-end I've packaged JBoss AS 6 into HomeBrew (a Mac OS X packaging system made of git and ruby).
>>>> I've discovered that our scripts are not symlinks friendly and will fail (often not finding the jars).
>>>>
>>>> I've fixed the issue but I wanted to get a review of my work. Let me know if you thing there could be a problem, otherwise I'll apply them to SVN.
>>>> [...]
>>>>   ls=`ls -ld "$PRG"`
>>>>   link=`expr "$ls" : '.*->   \(.*\)$'`
>>>
>>> This is fragile I think.  It'd probably be better to use "readlink"
>>> instead, whose actual purpose is to read links.
>>
>> I've tried your approach but I had a couple of issues. The main one is that readlink -f (recursive) is not standard across all platforms. The second issue I had was that readlink sometimes return links to the script basedir, sometimes as absolute. I imagine I could circumvent issue 2 (I've something for issue 1) but the fix will likely end up as weak as the original proposal (that comes from mvn, tomcat and co, so I imagine is decently battle tested).
>>
>> Is that worth the work?
>
> I guess it depends on how sure you are that "ls" will always output the link target after a "->".  I guess we could always try it and see if anyone complains.

The good news is that /man/ explicitly talk about '->' :)

If the file is a symbolic link, the pathname of the linked-to file is preceded by ``->''.



_______________________________________________
jboss-development mailing list
jboss-development@...
https://lists.jboss.org/mailman/listinfo/jboss-development