Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 201470

Summary: Shell scripts are not posix compliant and of bad quality
Product: z_Archived Reporter: Stefan Fleiter <stefan.fleiter>
Component: TPTPAssignee: Bing Xu <xubing>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P1 CC: jcayne, jkubasta, nmehrega, samwai
Version: unspecifiedKeywords: plan
Target Milestone: ---Flags: jcayne: review+
Hardware: PC   
OS: Linux   
Whiteboard: closed460
Attachments:
Description Flags
Patch
none
New patch with Joel's correction none

Description Stefan Fleiter CLA 2007-08-28 15:54:28 EDT
All shell scripts specify /bin/sh in their http://en.wikipedia.org/wiki/Shebang_%28Unix%29 line.
As stated at wikipedia

#!/bin/sh — On some systems, such as Solaris, this is the Bourne shell. On Linux systems there is usually no Bourne shell and this is a link to another shell, such as bash. According to the Single UNIX Specification's requirements for /bin/sh, such a shell will usually mimic the Bourne shell's behaviour, but be aware that using #!/bin/sh in shell scripts may invoke different Bourne-compatible shells on different systems.

So you can not expect the shell to be bash.
But this is expected in several places.

ubuntu 7.04 and up use /bin/dash - Debian Almquist SHell.
dash requires the shell script to be POSIX compliant, while bash is less
strict and supports the '==' operator for string comparison.

All the following problems are distributed over all shell files.
There is a lot of duplication there ACStart.sh, ACVersion.sh and all the
other shell files are duplicated for all architectures.
So these bugs all have to be fixed several times.


String comparisons habe to be done with =, not ==.
Not all shells can compare empty strings from variables correctly,
so use
    if [ x$VAR = x ]; then
to work around this.
Or even better
use
    if [ -z x$VAR ]; then


For ACServer.sh, ACStop.sh and ACVersion.sh the following changes should be done:


@@ -6,8 +6,8 @@
 #
 # If TPTP_AC_HOME is not set then we assume we are running from bin.
 #
-if [ "$TPTP_AC_HOME" = "" ]; then
-       TPTP_AC_HOME=..
+if [  -z $TPTP_AC_HOME ]; then
+       TPTP_AC_HOME=$(dirname $0)/..
        export TPTP_AC_HOME
 fi


Instead of relying on the fact the script is executed from the bin dir
use "$(dirname $0)/.." to get the parent dir of the script no matter what
the current working dir is.

 PATH=$TPTP_AC_HOME/bin:$PATH
@@ -41,7 +41,7 @@
 # Bug 175696
 # Make sure TEMP dir is set
 #
-if [ x$TEMP == x ]; then
+if [ -z $TEMP ]; then
        export TEMP=/tmp
 fi


SetConfig.sh has other problems:
It is not clear from which directory this has to be called.
java is called from the path. What if I have several java versions installed?
config.nl1.jar, config.nl2.jar and config.nl2a.jar are not part of tptp.
    if [ $SECURED = "0" ]; then  
This could fail if SECURED could be the empty string.
Comment 1 Stefan Fleiter CLA 2007-08-30 10:23:02 EDT
This bug has the potential to cause the Agent Controller not to work
for shell implementations which are not bash.

It was already reported in the newsgoup eclipse.tptp
Message-ID: <f7n84b$4f9$1@build.eclipse.org>

Why is this not targeted for 4.4.1?
Comment 2 jkubasta CLA 2007-08-30 10:31:08 EDT
Samson, Navid,
Please review the proposed change.  If containable in the 441 timeframe (end of next week with reviews and smoke test), I will retarget
Comment 3 Bing Xu CLA 2008-02-27 13:56:17 EST
Created attachment 90906 [details]
Patch
Comment 4 Bing Xu CLA 2008-02-27 14:03:36 EST
I didn't make the following change because 175696 has fixed it.

>....
>-if [ x$TEMP == x ]; then
>+if [ -z $TEMP ]; then
 >       export TEMP=/tmp
> fi
>....


Problem with SetConfig.sh that it needs Java in PATH has been raised as a separate bug 205637.

Joel, can you review my change to the scripts.
Comment 5 Joel Cayne CLA 2008-02-28 08:47:04 EST
Bing,
The -z change looks fine. The != checks could be updated to use -ne to match this change for $1 and $RUNNING.

Consider using `dirname $0` instead to be consistent with the rest of the script's command substitution, as well as working across multiple shells. Also look at updating the comment preceding the call as it is no longer required to be in the bin directory. 
Comment 6 Bing Xu CLA 2008-02-28 09:40:04 EST
Created attachment 91000 [details]
New patch with Joel's correction

Joel, can you review the new changes.  If OK please check them in.  Thanks.
Comment 7 Joel Cayne CLA 2008-02-28 10:12:46 EST
Looks good. Patch checked into HEAD.
Comment 8 jkubasta CLA 2008-02-28 23:26:33 EST
Patch in CVS
Comment 9 Paul Slauenwhite CLA 2009-06-30 12:10:38 EDT
As of TPTP 4.6.0, TPTP is in maintenance mode and focusing on improving quality by resolving relevant enhancements/defects and increasing test coverage through test creation, automation, Build Verification Tests (BVTs), and expanded run-time execution. As part of the TPTP Bugzilla housecleaning process (see http://wiki.eclipse.org/Bugzilla_Housecleaning_Processes), this enhancement/defect is verified/closed by the Project Lead since this enhancement/defect has been resolved and unverified for more than 1 year and considered to be fixed. If this enhancement/defect is still unresolved and reproducible in the latest TPTP release (http://www.eclipse.org/tptp/home/downloads/), please re-open.