Skip to content

Instantly share code, notes, and snippets.

@cshtdd
Created January 16, 2019 12:04
Show Gist options
  • Save cshtdd/aba7c6d1ba6f2df321c3e5789348b3ed to your computer and use it in GitHub Desktop.
Save cshtdd/aba7c6d1ba6f2df321c3e5789348b3ed to your computer and use it in GitHub Desktop.
Setup all the Java versions Elastic Search needs to compile
#!/bin/bash
# desired java versions
JAVA_VERSION_11=11.0.1-open
JAVA_VERSION_10=10.0.2-open
JAVA_VERSION_9=9.0.4-open
JAVA_VERSION_8=8.0.192-zulu
# determine if this program is being sourced
skip=false
[[ $- == *i* ]] || skip=true
[[ interactive ]] || skip=true
[[ ! `shopt -q login_shell` ]] || skip=true
if [[ $skip == true ]]; then
echo "This file needs to be run with sourced"
echo "so that sdkman can be found. e.g:"
echo " source setup_elastic_search_java.sh"
exit 1
fi
# installing java versions
if [[ $1 == '--skip-install' ]]; then
echo "Skipping installation"
else
echo "Install Java ${JAVA_VERSION_11}"
sdk install java $JAVA_VERSION_11
echo "Install Java ${JAVA_VERSION_10}"
sdk install java $JAVA_VERSION_10
echo "Install Java ${JAVA_VERSION_9}"
sdk install java $JAVA_VERSION_9
echo "Install Java ${JAVA_VERSION_8}"
sdk install java $JAVA_VERSION_8
fi
# reading all the java version installation paths
JAVA_HOME_11="$HOME/.sdkman/candidates/java/${JAVA_VERSION_11}"
echo "JAVA_HOME_11='${JAVA_HOME_11}'"
JAVA_HOME_10="$HOME/.sdkman/candidates/java/${JAVA_VERSION_10}"
echo "JAVA_HOME_10='${JAVA_HOME_10}'"
JAVA_HOME_9="$HOME/.sdkman/candidates/java/${JAVA_VERSION_9}"
echo "JAVA_HOME_9='${JAVA_HOME_9}'"
JAVA_HOME_8="$HOME/.sdkman/candidates/java/${JAVA_VERSION_8}"
echo "JAVA_HOME_8='${JAVA_HOME_8}'"
# generate java variable setup script
cat > /tmp/elastic-search-java-vars <<EOL
export JAVA_HOME=${JAVA_HOME_11}
export JAVA10_HOME=${JAVA_HOME_10}
export JAVA9_HOME=${JAVA_HOME_9}
export JAVA8_HOME=${JAVA_HOME_8}
export RUNTIME_JAVA_HOME=${JAVA_HOME_8}
sdk use java ${JAVA_VERSION_11}
EOL
# loading the java variables
source /tmp/elastic-search-java-vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment