From 043ab46fb50a45dfba5c2e8ac5875826673e0de1 Mon Sep 17 00:00:00 2001
From: CanbiZ <47820557+MickLesk@users.noreply.github.com>
Date: Wed, 30 Oct 2024 09:12:01 +0100
Subject: [PATCH] Tweak: Fix Paperless Ghostscript

---
 ct/paperless-ngx.sh              | 12 ++++++++++++
 install/paperless-ngx-install.sh | 10 +++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/ct/paperless-ngx.sh b/ct/paperless-ngx.sh
index d23986b1..a3682427 100644
--- a/ct/paperless-ngx.sh
+++ b/ct/paperless-ngx.sh
@@ -67,6 +67,18 @@ function update_script() {
   header_info
   if [ "$UPD" == "1" ]; then
     if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
+	  if [[ "$(gs --version 2>/dev/null)" != "10.04.0" ]]; then
+        msg_info "Updating Ghostscript"
+        cd /tmp
+        wget -q https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10040/ghostscript-10.04.0.tar.gz
+        tar -xzf ghostscript-10.04.0.tar.gz
+        cd ghostscript-10.04.0
+        ./configure &>/dev/null
+        make &>/dev/null
+        sudo make install &>/dev/null
+        rm -rf /tmp/ghostscript*
+        msg_ok "Ghostscript updated to 10.04.0"
+      fi
       msg_info "Stopping all Paperless-ngx Services"
       systemctl stop paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue.service
       msg_ok "Stopped all Paperless-ngx Services"
diff --git a/install/paperless-ngx-install.sh b/install/paperless-ngx-install.sh
index 7170611f..134772a0 100644
--- a/install/paperless-ngx-install.sh
+++ b/install/paperless-ngx-install.sh
@@ -52,7 +52,6 @@ msg_ok "Installed Python3 Dependencies"
 msg_info "Installing OCR Dependencies (Patience)"
 $STD apt-get install -y --no-install-recommends \
   unpaper \
-  ghostscript \
   icc-profiles-free \
   qpdf \
   liblept5 \
@@ -61,6 +60,14 @@ $STD apt-get install -y --no-install-recommends \
   zlib1g \
   tesseract-ocr \
   tesseract-ocr-eng
+  
+cd /tmp
+wget -q https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs10040/ghostscript-10.04.0.tar.gz
+$STD tar -xzf ghostscript-10.04.0.tar.gz
+cd ghostscript-10.04.0
+$STD ./configure
+$STD make
+$STD sudo make install
 msg_ok "Installed OCR Dependencies"
 
 msg_info "Installing JBIG2"
@@ -221,6 +228,7 @@ customize
 
 msg_info "Cleaning up"
 rm -rf /opt/paperless/docker
+rm -rf /tmp/ghostscript*
 $STD apt-get -y autoremove
 $STD apt-get -y autoclean
 msg_ok "Cleaned"