--- bin/elasticsearch-env	2021-09-01 12:39:36.000000000 -0400
+++ bin/elasticsearch-env	2021-09-01 12:46:54.000000000 -0400
@@ -19,23 +19,19 @@
   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 "$ES_JAVA_HOME" ]; then
+  if [ -x /usr/libexec/java_home ]; then
+    export ES_JAVA_HOME=$(/usr/libexec/java_home)
+    export KEYTOOL="$ES_JAVA_HOME"/jre/bin
+  fi
+fi
 if [ ! -z "$ES_JAVA_HOME" ]; then
   JAVA="$ES_JAVA_HOME/bin/java"
   JAVA_TYPE="ES_JAVA_HOME"
@@ -44,15 +40,17 @@
   echo "warning: usage of JAVA_HOME is deprecated, use ES_JAVA_HOME" >&2
   JAVA="$JAVA_HOME/bin/java"
   JAVA_TYPE="JAVA_HOME"
-else
-  # use the bundled JDK (default)
-  if [ "$(uname -s)" = "Darwin" ]; then
-    # macOS has a different structure
-    JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
-  else
-    JAVA="$ES_HOME/jdk/bin/java"
-  fi
-  JAVA_TYPE="bundled JDK"
+# MacPorts' port:elasticsearch includes port:openjdk11 as a dependency;
+# no need to include this bundled Elasticsearch copy of OpenJDK13
+## else
+##   # use the bundled JDK (default)
+##   if [ "$(uname -s)" = "Darwin" ]; then
+##     # macOS has a different structure
+##     JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
+##   else
+##     JAVA="$ES_HOME/jdk/bin/java"
+##   fi
+##   JAVA_TYPE="bundled JDK"
 fi
 
 if [ ! -x "$JAVA" ]; then
@@ -84,8 +82,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