From 2e6ccd6366823ca9110cdec1b6fd8d2484f5bab0 Mon Sep 17 00:00:00 2001 From: Abel 'Akronix' Serrano Juste Date: Sun, 15 Jan 2017 23:48:37 +0100 Subject: [PATCH 1/3] Rewritten shell script launcher for Linux --- .../main/resources-portable/viewer-linux.sh | 80 ++++++------------- 1 file changed, 25 insertions(+), 55 deletions(-) mode change 100644 => 100755 weasis-distributions/src/main/resources-portable/viewer-linux.sh diff --git a/weasis-distributions/src/main/resources-portable/viewer-linux.sh b/weasis-distributions/src/main/resources-portable/viewer-linux.sh old mode 100644 new mode 100755 index f7c406cc3..75c1195f4 --- a/weasis-distributions/src/main/resources-portable/viewer-linux.sh +++ b/weasis-distributions/src/main/resources-portable/viewer-linux.sh @@ -3,77 +3,47 @@ # 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. # +# Rewritten by Abel 'Akronix' Serrano Juste +# # To specify the required version, set the REQUIRED_VERSION to the major version required, -# e.g. 1.3, but not 1.3.1. +# e.g. 1.3, but not 1.3.1. Also, always set decimal value: e.g. 2.0, but not 2 or 2. 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 ] +REQUIRED_VERSION_INTEGER=`echo $REQUIRED_TEXT_VERSION | sed -e 's/\./0/'` + +# First, check if java is installed and accesible in $PATH. If so, get installed version. +JAVA_EXE=`which java` +if [ $JAVA_EXE ] 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 - else - JAVA_HOME= - fi + INSTALLED_VERSION=`java -version 2>&1 | awk '/version [0-9]*/ {print $3;}'` + echo "Found java $INSTALLED_VERSION" + + # Remove double quotes, replace first dot by 0 and remove the rest of the version string. + INSTALLED_VERSION_INTEGER=`echo $INSTALLED_VERSION | sed -e 's/"//' -e 's/\./0/' -e 's/\..*//'` +else + echo -e "Java was not detected in your system.\nPlease, tell your administrator to install Java >=$REQUIRED_TEXT_VERSION and to make sure it's accesible from the PATH." + exit 3; 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 ] +if (( INSTALLED_VERSION_INTEGER < REQUIRED_VERSION_INTEGER )) 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 + echo "Your version of java is too low to run Weasis. Please update to $REQUIRED_TEXT_VERSION or higher" + exit 4; 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" +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[@]} From 73ca2a9d2d13b5e695f9f5a32204a6397f3f631d Mon Sep 17 00:00:00 2001 From: Abel 'Akronix' Serrano Juste Date: Mon, 23 Jan 2017 00:13:07 +0100 Subject: [PATCH 2/3] Extended java probing in viewer-linux.sh for more UNIX systems. Based on the shell script generated by Gradle. --- .../main/resources-portable/viewer-linux.sh | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/weasis-distributions/src/main/resources-portable/viewer-linux.sh b/weasis-distributions/src/main/resources-portable/viewer-linux.sh index 75c1195f4..01fe68a45 100755 --- a/weasis-distributions/src/main/resources-portable/viewer-linux.sh +++ b/weasis-distributions/src/main/resources-portable/viewer-linux.sh @@ -6,30 +6,49 @@ # Rewritten by Abel 'Akronix' Serrano Juste # # To specify the required version, set the REQUIRED_VERSION to the major version required, -# e.g. 1.3, but not 1.3.1. Also, always set decimal value: e.g. 2.0, but not 2 or 2. +# e.g. 1.3, but not 1.3.1. Also, always set decimal value: e.g. 9.0, but not 9 or 9. REQUIRED_TEXT_VERSION=1.8 # Transform the required version string into a number that can be used in comparisons REQUIRED_VERSION_INTEGER=`echo $REQUIRED_TEXT_VERSION | sed -e 's/\./0/'` -# First, check if java is installed and accesible in $PATH. If so, get installed version. -JAVA_EXE=`which java` -if [ $JAVA_EXE ] -then - INSTALLED_VERSION=`java -version 2>&1 | awk '/version [0-9]*/ {print $3;}'` - echo "Found java $INSTALLED_VERSION" - - # Remove double quotes, replace first dot by 0 and remove the rest of the version string. - INSTALLED_VERSION_INTEGER=`echo $INSTALLED_VERSION | sed -e 's/"//' -e 's/\./0/' -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 + 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 - echo -e "Java was not detected in your system.\nPlease, tell your administrator to install Java >=$REQUIRED_TEXT_VERSION and to make sure it's accesible from the PATH." - exit 3; + 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 +# 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, replace first dot by 0 and remove the rest of the version string. +INSTALLED_VERSION_INTEGER=`echo $INSTALLED_VERSION | sed -e 's/"//' -e 's/\./0/' -e 's/\..*//'` + if (( INSTALLED_VERSION_INTEGER < REQUIRED_VERSION_INTEGER )) then - echo "Your version of java is too low to run Weasis. Please update to $REQUIRED_TEXT_VERSION or higher" - exit 4; + die "Your version of java is too low to run Weasis.\nPlease update to $REQUIRED_TEXT_VERSION or higher" fi # Get additional weasis arguments @@ -46,4 +65,4 @@ echo user arguments: ${userParameters[@]} # If the correct Java version is detected, launch weasis from current path curPath=$(dirname "`readlink -f "$0"`") echo "Weasis launcher directory: $curPath" -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[@]} +$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[@]} From a6b827ab7d58bfb4fe6c53fcdd8a7525015609ba Mon Sep 17 00:00:00 2001 From: Abel 'Akronix' Serrano Juste Date: Wed, 25 Jan 2017 00:45:34 +0100 Subject: [PATCH 3/3] 'Removing leading "1." if it exists and check only for JDK major version' Changes taking into account new java version string scheme: http://openjdk.java.net/jeps/223 and discussion in http://www.dcm4che.org/jira/browse/WEA-388 --- .../src/main/resources-portable/viewer-linux.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/weasis-distributions/src/main/resources-portable/viewer-linux.sh b/weasis-distributions/src/main/resources-portable/viewer-linux.sh index 01fe68a45..fdfbab9dc 100755 --- a/weasis-distributions/src/main/resources-portable/viewer-linux.sh +++ b/weasis-distributions/src/main/resources-portable/viewer-linux.sh @@ -4,13 +4,14 @@ # variable that can be used by another calling script. # # Rewritten by Abel 'Akronix' Serrano Juste -# -# To specify the required version, set the REQUIRED_VERSION to the major version required, -# e.g. 1.3, but not 1.3.1. Also, always set decimal value: e.g. 9.0, but not 9 or 9. + +# 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_INTEGER=`echo $REQUIRED_TEXT_VERSION | sed -e 's/\./0/'` +# 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 ( ) { @@ -43,10 +44,10 @@ fi INSTALLED_VERSION=`$JAVACMD -version 2>&1 | awk '/version [0-9]*/ {print $3;}'` echo "Found java $INSTALLED_VERSION" -# Remove double quotes, replace first dot by 0 and remove the rest of the version string. -INSTALLED_VERSION_INTEGER=`echo $INSTALLED_VERSION | sed -e 's/"//' -e 's/\./0/' -e 's/\..*//'` +# 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_VERSION_INTEGER < REQUIRED_VERSION_INTEGER )) +if (( INSTALLED_MAJOR_VERSION < REQUIRED_MAJOR_VERSION )) then die "Your version of java is too low to run Weasis.\nPlease update to $REQUIRED_TEXT_VERSION or higher" fi