From 2c2cc3f984db5090355176a215c4edb0bc86599b Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Thu, 4 Aug 2022 20:34:22 -0400
Subject: [PATCH] unix_setup improvements

---
 unix_setup.sh | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/unix_setup.sh b/unix_setup.sh
index cd29169b4a..bfb4e8ad01 100644
--- a/unix_setup.sh
+++ b/unix_setup.sh
@@ -35,6 +35,10 @@ echo "---------------------------------------------"
 echo "Checking prerequisites and preparing ${APPLICATION_NAME}:"
 echo "---------------------------------------------"
 
+# make sure cwd is same as script's
+SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+pushd $SCRIPTPATH
+
 # Verify PhotoRec was installed
 echo -n "Checking for PhotoRec..."
 photorec_filepath=/usr/bin/photorec
@@ -53,7 +57,8 @@ echo -n "Checking for Java..."
 if [ -n "$JAVA_PATH" ]; then 
     if [ -x "$JAVA_PATH/bin/java" ]; then
         # only works on linux; not os x
-        sed -Ei '/^#?\s*jdkhome=.*$' "etc/$APPLICATION_NAME.conf"
+        awk '!/^\s*#?\s*jdkhome=.*$/' etc/$APPLICATION_NAME.conf > etc/$APPLICATION_NAME.conf.tmp && \
+        mv etc/$APPLICATION_NAME.conf.tmp etc/$APPLICATION_NAME.conf && \
         echo "jdkhome=$JAVA_PATH" >> etc/$APPLICATION_NAME.conf
     else
         echo "ERROR: Java was not found in $JAVA_PATH."
@@ -113,6 +118,8 @@ chmod -R u+x autopsy/solr/bin
 # make sure it is executable
 chmod u+x bin/$APPLICATION_NAME
 
+popd
+
 echo
 echo "Application is now configured. You can execute bin/$APPLICATION_NAME to start it"
-echo
+echo
\ No newline at end of file
-- 
GitLab