Skip to content

Instantly share code, notes, and snippets.

@JasonGiedymin
Forked from kwilczynski/mesos-detect-java.sh
Created November 30, 2013 14:30
Show Gist options
  • Save JasonGiedymin/7719762 to your computer and use it in GitHub Desktop.
Save JasonGiedymin/7719762 to your computer and use it in GitHub Desktop.
#!/bin/bash
java_binary_link="/usr/bin/java"
java_library="libjvm.so"
library_paths=(
/jre/lib/amd64/server
/jre/lib/amd64/client
/usr/lib
/lib
)
if [ -z "$java_home" ] || [ ! -d "$java_home" ]; then
JAVA_HOME=$(dirname $(dirname $(dirname $(readlink -f $java_binary_link))))
if [ ! -d $java_home ]; then
JAVA_HOME="/usr/lib/jvm/default-java"
fi
fi
if ! /sbin/ldconfig -p | /bin/grep $java_library > /dev/null 2>&1 ; then
for path in ${library_paths[@]}; do
library_path=$(echo $"${JAVA_HOME}/${path}" | tr -s '/')
if [ -f "${library_path}/${java_library}" ]; then
LD_LIBRARY_PATH="${library_path}:${LD_LIBRARY_PATH}"
break
fi
done
fi
export JAVA_HOME LD_LIBRARY_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment