Fix error message when package install fails due to missing Java (#36077)
Currently is `java` is not in $PATH the preinst script fails prematurely and prevents an appropriate message from getting displayed to the user. Make package installation more user friendly when java is not in $PATH and add a test for it. Also use a she-bang in the preinst script, as, at least in Debian, maintainer scripts must start with the #! convention [1]. Relates #31845 [1] https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html
This commit is contained in:
parent
43773a32a4
commit
6a773d7d51
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 + "'");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue