--- bin/elasticsearch-env
+++ bin/elasticsearch-env	2019-05-09 13:57:05.000000000 -0400
@@ -19,32 +19,31 @@
   fi
 done
 
-# determine Elasticsearch home; to do this, we strip from the path until we find
-# bin, and then strip bin (there is an assumption here that there is no nested
-# directory under bin also named bin)
-ES_HOME=`dirname "$SCRIPT"`
-
-# now make ES_HOME absolute
-ES_HOME=`cd "$ES_HOME"; pwd`
-
-while [ "`basename "$ES_HOME"`" != "bin" ]; do
-  ES_HOME=`dirname "$ES_HOME"`
-done
-ES_HOME=`dirname "$ES_HOME"`
+ES_HOME="@PREFIX@/share/elasticsearch"
+ES_PATH_CONF="@PREFIX@/etc/elasticsearch"
 
 # now set the classpath
 ES_CLASSPATH="$ES_HOME/lib/*"
 
 # now set the path to java
+if [ -z "$JAVA_HOME" ]; then
+  if [ -x /usr/libexec/java_home ]; then
+    export JAVA_HOME=$(/usr/libexec/java_home)
+    export KEYTOOL="$JAVA_HOME"/jre/bin
+  fi
+fi
+
 if [ ! -z "$JAVA_HOME" ]; then
   JAVA="$JAVA_HOME/bin/java"
-else
-  if [ "$(uname -s)" = "Darwin" ]; then
-    # OSX has a different structure
-    JAVA="$ES_HOME/jdk/Contents/Home/bin/java"
-  else
-    JAVA="$ES_HOME/jdk/bin/java"
-  fi
+# MacPorts' port:elasticsearch includes port:openjdk12 as a dependency;
+# no need to include this bundled Elasticsearch copy of OpenJDK12
+## else
+##   if [ "$(uname -s)" = "Darwin" ]; then
+##     # OSX has a different structure
+##     JAVA="$ES_HOME/jdk/Contents/Home/bin/java"
+##   else
+##     JAVA="$ES_HOME/jdk/bin/java"
+##   fi
 fi
 
 if [ ! -x "$JAVA" ]; then
@@ -70,8 +69,6 @@
 
 export HOSTNAME=$HOSTNAME
 
-if [ -z "$ES_PATH_CONF" ]; then ES_PATH_CONF="$ES_HOME"/config; fi
-
 if [ -z "$ES_PATH_CONF" ]; then
   echo "ES_PATH_CONF must be set to the configuration path"
   exit 1