Add package pre-install check for java binary (#31343)
The package installation relies on java being in the path. If java is not in the path, the tests fail at post-install time. This commit adds a pre-install check to validate that java exists, and if it fails, the package is never installed, and thus keeps a system clean, rather than aborting at post-install and leaving behind a mess. Closes #29665
This commit is contained in:
parent
86ab3a2d1a
commit
adfcea2af6
|
@ -9,6 +9,18 @@
|
|||
# $1=1 : indicates an new install
|
||||
# $1=2 : indicates an upgrade
|
||||
|
||||
# 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"
|
||||
else
|
||||
JAVA=`which java`
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA" ]; then
|
||||
echo "could not find java; set JAVA_HOME or ensure java is in PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
|
||||
# Debian ####################################################
|
||||
|
|
|
@ -72,6 +72,14 @@ setup() {
|
|||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "[DEB] temporarily remove java and ensure the install fails" {
|
||||
move_java
|
||||
run dpkg -i elasticsearch-oss-$(cat version).deb
|
||||
output=$status
|
||||
unmove_java
|
||||
[ "$output" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "[DEB] install package" {
|
||||
dpkg -i elasticsearch-oss-$(cat version).deb
|
||||
}
|
||||
|
|
|
@ -71,6 +71,14 @@ setup() {
|
|||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "[RPM] temporarily remove java and ensure the install fails" {
|
||||
move_java
|
||||
run rpm -i elasticsearch-oss-$(cat version).rpm
|
||||
output=$status
|
||||
unmove_java
|
||||
[ "$output" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "[RPM] install package" {
|
||||
rpm -i elasticsearch-oss-$(cat version).rpm
|
||||
}
|
||||
|
|
|
@ -68,8 +68,11 @@ if [ ! -x "`which unzip 2>/dev/null`" ]; then
|
|||
fi
|
||||
|
||||
if [ ! -x "`which java 2>/dev/null`" ]; then
|
||||
echo "'java' command is mandatory to run the tests"
|
||||
exit 1
|
||||
# there are some tests that move java temporarily
|
||||
if [ ! -x "`command -v java.bak 2>/dev/null`" ]; then
|
||||
echo "'java' command is mandatory to run the tests"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Returns 0 if the 'dpkg' command is available
|
||||
|
@ -578,3 +581,17 @@ file_privileges_for_user_from_umask() {
|
|||
|
||||
echo $((0777 & ~$(sudo -E -u $user sh -c umask) & ~0111))
|
||||
}
|
||||
|
||||
# move java to simulate it not being in the path
|
||||
move_java() {
|
||||
which_java=`command -v java`
|
||||
assert_file_exist $which_java
|
||||
mv $which_java ${which_java}.bak
|
||||
}
|
||||
|
||||
# move java back to its original location
|
||||
unmove_java() {
|
||||
which_java=`command -v java.bak`
|
||||
assert_file_exist $which_java
|
||||
mv $which_java `dirname $which_java`/java
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue