Skip to content

Commit

Permalink
Merge pull request #12 from Akronix/master
Browse files Browse the repository at this point in the history
Rewrite shell script launcher for linux systems
  • Loading branch information
nroduit authored Jan 25, 2017
2 parents 0a27181 + a6b827a commit 066f187
Showing 1 changed file with 46 additions and 56 deletions.
102 changes: 46 additions & 56 deletions weasis-distributions/src/main/resources-portable/viewer-linux.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,67 @@
# requirement on a Linux machine. If it is successful, it will export a JAVA_HOME environment
# variable that can be used by another calling script.
#
# To specify the required version, set the REQUIRED_VERSION to the major version required,
# e.g. 1.3, but not 1.3.1.
# Rewritten by Abel 'Akronix' Serrano Juste <[email protected]>

# Specify the required JDK version.
# Only major version is checked. Minor version or any other version string info is left out.
REQUIRED_TEXT_VERSION=1.8

# Transform the required version string into a number that can be used in comparisons
REQUIRED_VERSION=`echo $REQUIRED_TEXT_VERSION | sed -e 's;\.;0;g'`
# Check JAVA_HOME directory to see if Java version is adequate
if [ $JAVA_HOME ]
then
JAVA_EXE=$JAVA_HOME/bin/java
VERSION=`$JAVA_EXE -version 2>&1 | head -1`
VERSION=`echo $VERSION | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
VERSION=`echo $VERSION | awk '{ print substr($1, 1, 3); }' | sed -e 's;\.;0;g'`
if [ $VERSION ]
then
if [ $VERSION -ge $REQUIRED_VERSION ]
then
JAVA_HOME=`echo $JAVA_EXE | awk '{ print substr($1, 1, length($1)-9); }'`
else
JAVA_HOME=
fi
# Extract major version number for comparisons from the required version string.
# In order to do that, remove leading "1." if exists, and minor and security versions.
REQUIRED_MAJOR_VERSION=`echo $REQUIRED_TEXT_VERSION | sed -e 's/^1\.//' -e 's/\..*//'`

# Aux functions:
die ( ) {
echo
echo -e "ERROR: $*"
exit 1
}

# First, determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVA_HOME=
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
which java >/dev/null 2>&1 || die "JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please, tell your administrator to install Java >=$REQUIRED_TEXT_VERSION.
Also, make sure it's accesible from the PATH or set the JAVA_HOME variable to match the location of your Java installation."
JAVACMD="java"
fi

# If the existing JAVA_HOME directory is adequate, then leave it alone
# otherwise, use 'locate' to search for other possible java candidates and
# check their versions.
if [ $JAVA_HOME ]
# Then, get the installed version
INSTALLED_VERSION=`$JAVACMD -version 2>&1 | awk '/version [0-9]*/ {print $3;}'`
echo "Found java $INSTALLED_VERSION"

# Remove double quotes, remove leading "1." if it exists and remove everything apart from the major version number.
INSTALLED_MAJOR_VERSION=`echo $INSTALLED_VERSION | sed -e 's/"//' -e 's/^1\.//' -e 's/\..*//'`

if (( INSTALLED_MAJOR_VERSION < REQUIRED_MAJOR_VERSION ))
then
:
else
for JAVA_EXE in `locate bin/java | grep java$ | xargs echo`
do
if [ $JAVA_HOME ]
then
:
else
VERSION=`$JAVA_EXE -version 2>&1 | head -1`
VERSION=`echo $VERSION | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`
VERSION=`echo $VERSION | awk '{ print substr($1, 1, 3); }' | sed -e 's;\.;0;g'`
if [ $VERSION ]
then
if [ $VERSION -ge $REQUIRED_VERSION ]
then
JAVA_HOME=`echo $JAVA_EXE | awk '{ print substr($1, 1, length($1)-9); }'`
fi
fi
fi
done
die "Your version of java is too low to run Weasis.\nPlease update to $REQUIRED_TEXT_VERSION or higher"
fi

# Get additional weasis arguments
userParameters=()
for var in "$@"
do
if [[ $var == \$* ]]
if [[ $var == \$* ]]
then
userParameters+=("$var")
userParameters+=("$var")
fi
done
echo user arguments: ${userParameters[@]}

# If the correct Java version is detected, then export the JAVA_HOME environment variable
if [ $JAVA_HOME ]
then
export JAVA_HOME
echo Java Home: $JAVA_HOME/bin/java
curPath=$(dirname "`readlink -f "$0"`")
echo Weasis launcher directory: $curPath
$JAVA_HOME/bin/java -Xms64m -Xmx512m -Dgosh.args="-sc telnetd -p 17179 start" -Dweasis.portable.dir="$curPath" -classpath "$curPath/weasis/weasis-launcher.jar:$curPath/weasis/felix.jar:$curPath/weasis/substance.jar" org.weasis.launcher.WeasisLauncher \$dicom:get --portable ${userParameters[@]}
else echo 'Weasis requires Java Runtime '$REQUIRED_TEXT_VERSION' or higher, please install it'
fi
# If the correct Java version is detected, launch weasis from current path
curPath=$(dirname "`readlink -f "$0"`")
echo "Weasis launcher directory: $curPath"
$JAVACMD -Xms64m -Xmx512m -Dgosh.args="-sc telnetd -p 17179 start" -Dweasis.portable.dir="$curPath" -classpath "$curPath/weasis/weasis-launcher.jar:$curPath/weasis/felix.jar:$curPath/weasis/substance.jar" org.weasis.launcher.WeasisLauncher \$dicom:get --portable ${userParameters[@]}

0 comments on commit 066f187

Please sign in to comment.