From c62249f9fbf42e39bca741ee013e69e1946dd548 Mon Sep 17 00:00:00 2001
From: Greg DiCristofaro <gregd@basistech.com>
Date: Thu, 18 Aug 2022 11:24:21 -0400
Subject: [PATCH] fixes for os x

---
 unix_install_scripts/README.md              |  7 ++--
 unix_install_scripts/add_homebrew_jna.sh    | 36 ---------------------
 unix_install_scripts/add_osx_jna.sh         | 34 +++++++++++++++++++
 unix_install_scripts/install_prereqs_osx.sh | 17 ++++++++--
 4 files changed, 53 insertions(+), 41 deletions(-)
 delete mode 100644 unix_install_scripts/add_homebrew_jna.sh
 create mode 100644 unix_install_scripts/add_osx_jna.sh

diff --git a/unix_install_scripts/README.md b/unix_install_scripts/README.md
index e06028d981..c94919899a 100644
--- a/unix_install_scripts/README.md
+++ b/unix_install_scripts/README.md
@@ -8,7 +8,7 @@
 *A script to install these dependencies that can be found [here](install_prereqs_osx.sh).*
 - Using [Homebrew](https://brew.sh/), install dependencies that have formulas:
   ```
-  brew install ant automake libtool afflib libewf libpq testdisk imagemagick gstreamer gst-plugins-base gst-plugins-good imagemagick
+  brew install ant automake libtool afflib libewf postgresql testdisk
   ```
 - You will also need to install Java 8 and JavaFX to run autopsy.  We recommend Liberica OpenJDK which can be installed by tapping this third-party dependency:
   ```
@@ -22,6 +22,7 @@
   ```
   /usr/libexec/java_home -v 1.8
   ```
+- If you want gstreamer to open media, you can download and install gstreamer here: `https://gstreamer.freedesktop.org/data/pkg/osx/1.20.3/gstreamer-1.0-1.20.3-universal.pkg`
   
 ## On Linux (Ubuntu / Debian-based)
 
@@ -113,8 +114,8 @@
   ```
 - At this point, you should be able to run Autopsy with the command `./autopsy` from within the `bin` directory of the extracted folder.
 
-## Setup Homebrew JNA paths
-A few features in Autopsy will only work (i.e. gstreamer) will only work if the JNA paths are specified.  If you installed the necessary dependencies through Homebrew, you will want to either run this [script](add_homebrew_jna.sh) or manually add all the gstreamer lib and dependency lib paths to the env variable `jre_flags`.
+## Setup OSX JNA paths
+A few features in Autopsy will only work (i.e. gstreamer) if the JNA paths are specified.  If you installed the necessary dependencies through Homebrew, you will want to either run this [script](add_osx_jna.sh) or manually add all the gstreamer lib and dependency lib paths to the env variable `jre_flags` with jre flag: `-Djna.library.path`.
 
 # Caveats
 - Not all current features in Autopsy are functional in a Linux and Mac environment including but not limited to:
diff --git a/unix_install_scripts/add_homebrew_jna.sh b/unix_install_scripts/add_homebrew_jna.sh
deleted file mode 100644
index 5ea47cdf01..0000000000
--- a/unix_install_scripts/add_homebrew_jna.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/bin/bash
-# Updates jna paths for mac
-
-usage() {
-    echo "Usage: add_homebrew_jna.sh [-c config_file]" 1>&2
-}
-
-while getopts "c:" o; do
-    case "${o}" in
-    c)
-        append_path=${OPTARG}
-        ;;
-    *)
-        usage
-        exit 1
-        ;;
-    esac
-done
-
-if [[ -z "$append_path" ]]; then
-    usage
-    exit 1
-fi
-
-gstreamer_paths=$({ brew deps --installed gst-plugins-base gst-plugins-good gstreamer; echo -e "gst-plugins-base\ngst-plugins-good\ngstreamer" ; } \
-    | sort \
-    | uniq \
-    | xargs brew ls \
-    | grep /lib/ \
-    | xargs -I{} dirname {} \
-    | sort \
-    | uniq \
-    | sed -e :a -e '$!N; s/\n/:/; ta')
-
-echo -e "\njreflags=\"\$jreflags -Djna.library.path=\\\"$gstreamer_paths\\\"\"" >> $append_path
-
diff --git a/unix_install_scripts/add_osx_jna.sh b/unix_install_scripts/add_osx_jna.sh
new file mode 100644
index 0000000000..6d899902e1
--- /dev/null
+++ b/unix_install_scripts/add_osx_jna.sh
@@ -0,0 +1,34 @@
+#!/bin/bash
+# Updates jna paths for mac
+
+usage() {
+    echo "Usage: add_osx_jna.sh [-i base_install_location (i.e. /home/usr/autopsy)] [-a application_name (default: autopsy)]" 1>&2
+}
+
+APPLICATION_NAME="autopsy"
+
+while getopts "a:i:" o; do
+    case "${o}" in
+    i) 
+        INSTALL_LOC=${OPTARG}
+        ;;
+    a)
+        APPLICATION_NAME=${OPTARG}
+        ;;
+    *)
+        usage
+        exit 1
+        ;;
+    esac
+done
+
+if [[ -z "$INSTALL_LOC" ]]
+then
+    usage
+    exit 1
+fi
+
+awk '!/^\s*#?\s*export jreflags=.*$/' $INSTALL_LOC/etc/$APPLICATION_NAME.conf > $INSTALL_LOC/etc/$APPLICATION_NAME.conf.tmp && \
+mv $INSTALL_LOC/etc/$APPLICATION_NAME.conf.tmp $INSTALL_LOC/etc/$APPLICATION_NAME.conf && \
+echo -e "\nexport jreflags=-Djna.library.path=\"/Library/Frameworks/GStreamer.framework/Versions/1.0/lib\"" >> $INSTALL_LOC/etc/$APPLICATION_NAME.conf
+
diff --git a/unix_install_scripts/install_prereqs_osx.sh b/unix_install_scripts/install_prereqs_osx.sh
index acba010989..b4da3b44b9 100644
--- a/unix_install_scripts/install_prereqs_osx.sh
+++ b/unix_install_scripts/install_prereqs_osx.sh
@@ -1,14 +1,27 @@
 #!/bin/bash
 echo "Installing dependencies..."
 # dependencies taken from: https://github.com/sleuthkit/autopsy/pull/5111/files
-# brew install postgresql gettext cppunit && \
-brew install ant automake libtool afflib libewf libpq testdisk gstreamer gst-plugins-base gst-plugins-good
+# brew install gettext cppunit && \
+brew install ant automake libtool afflib libewf postgresql testdisk
 if [[ $? -ne 0 ]] 
 then 
     echo "Unable to install necessary dependencies" >> /dev/stderr
     exit 1
 fi
 
+# brew gstreamer packages don't seem to play nice with autopsy.  Installing directly from gstreamer
+echo "Installing gstreamer..."
+gstreamer_tmp_path=$TMPDIR/gstreamer-1.0-1.20.3-universal.pkg
+curl -k -o $gstreamer_tmp_path 'https://gstreamer.freedesktop.org/data/pkg/osx/1.20.3/gstreamer-1.0-1.20.3-universal.pkg' && \
+sudo installer -pkg //Users/4911_admin/Downloads/gstreamer-1.0-1.20.3-universal.pkg -target / 
+gstreamer_install_result=$?
+rm $gstreamer_tmp_path
+if [[ $? -ne 0 ]] 
+then 
+    echo "Unable to install gstreamer" >> /dev/stderr
+    exit 1
+fi
+
 echo "Installing liberica java 8..."
 brew tap bell-sw/liberica && \
 brew install --cask liberica-jdk8-full
-- 
GitLab