diff --git a/distribution/packages/src/common/scripts/preinst b/distribution/packages/src/common/scripts/preinst index 22f2405af3c..0718e31b05e 100644 --- a/distribution/packages/src/common/scripts/preinst +++ b/distribution/packages/src/common/scripts/preinst @@ -1,3 +1,4 @@ +#!/bin/bash # # This script is executed in the pre-installation phase # @@ -9,16 +10,22 @@ # $1=1 : indicates an new install # $1=2 : indicates an upgrade +err_exit() { + echo "$@" >&2 + exit 1 +} + # Check for these at preinst time due to failures in postinst if they do not exist if [ -x "$JAVA_HOME/bin/java" ]; then JAVA="$JAVA_HOME/bin/java" +elif command -v java; then + JAVA=`command -v java` else - JAVA=`which java` + JAVA="" fi if [ -z "$JAVA" ]; then - echo "could not find java; set JAVA_HOME or ensure java is in PATH" - exit 1 + err_exit "could not find java; set JAVA_HOME or ensure java is in PATH" fi case "$1" in @@ -75,8 +82,7 @@ case "$1" in ;; *) - echo "pre install script called with unknown argument \`$1'" >&2 - exit 1 + err_exit "pre install script called with unknown argument \`$1'" ;; esac diff --git a/distribution/src/bin/elasticsearch-env b/distribution/src/bin/elasticsearch-env index fc8b4a809fe..d1dec54f93d 100644 --- a/distribution/src/bin/elasticsearch-env +++ b/distribution/src/bin/elasticsearch-env @@ -45,7 +45,7 @@ else fi if [ ! -x "$JAVA" ]; then - echo "could not find java; set JAVA_HOME or ensure java is in PATH" + echo "could not find java; set JAVA_HOME or ensure java is in PATH" >&2 exit 1 fi diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java index 341ecc78bc9..f298e7681cc 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/ArchiveTestCase.java @@ -111,7 +111,7 @@ public abstract class ArchiveTestCase extends PackagingTestCase { sh.run("chmod -x '" + javaPath + "'"); final Result runResult = sh.runIgnoreExitCode(bin.elasticsearch.toString()); assertThat(runResult.exitCode, is(1)); - assertThat(runResult.stdout, containsString("could not find java; set JAVA_HOME or ensure java is in PATH")); + assertThat(runResult.stderr, containsString("could not find java; set JAVA_HOME or ensure java is in PATH")); } finally { sh.run("chmod +x '" + javaPath + "'"); } diff --git a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackageTestCase.java b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackageTestCase.java index db31babca57..cc2ae29653c 100644 --- a/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackageTestCase.java +++ b/qa/vagrant/src/main/java/org/elasticsearch/packaging/test/PackageTestCase.java @@ -70,6 +70,7 @@ public abstract class PackageTestCase extends PackagingTestCase { mv(originalJavaPath, relocatedJavaPath); final Result installResult = runInstallCommand(distribution()); assertThat(installResult.exitCode, is(1)); + assertThat(installResult.stderr, containsString("could not find java; set JAVA_HOME or ensure java is in PATH")); } finally { mv(relocatedJavaPath, originalJavaPath); }