Stirling-PDF icon indicating copy to clipboard operation
Stirling-PDF copied to clipboard

Install and deploy on a Linux machine without docker, root (superuser), apt, yum, or apk (via nix-env).

Open bluestero opened this issue 9 months ago • 3 comments

As the title describes, I was contributing to Codesphere to create a template for a dockerless PDF-tool. Now, it would have been smooth sailing by just following the: https://github.com/Stirling-Tools/Stirling-PDF/blob/main/LocalRunGuide.md

But the catch was:

  • No root access.
  • Cannot use apt, yum, or apk.
  • Cannot source and build packages yourselves (since no root).

So it took me I think 2 weeks to finally find a workaround for the issues I faced such as:

  • Leptonica not found (Jbig2enc installation), probably weird installation by nix-env.
  • When using any libreoffice conversion tools after deployment, you get cannot make directory /run/user/1501 permission denied.

So it took a lot of research and workarounds to finally have a way to make this work and wanted to add this non-root and nix-env method in the LocalRunGuide.md.

Also, the first issue I saw was about changing the port (something I had to as well), so if it is not mentioned anywhere regarding changing host and port, I can add that as well.

I already have how I am going to approach the readme.MD, and have read through the CONTRIBUTING.md and would start when get assigned to this.

Looking forward for a positive response.

bluestero avatar May 06 '24 07:05 bluestero

I'd want to see what the work arounds were to approve etc But sure !

Frooodle avatar May 06 '24 08:05 Frooodle

@Frooodle Sure, will refer to the https://github.com/Stirling-Tools/Stirling-PDF/blob/main/LocalRunGuide.md for my explanation. Also, I know its a long read, sorry about that.

1 - So first lets talk about the packages and libraries: The guide uses apt and dnf, but on Codesphere, those are not available. Since their package repositories are different, there might be missing / different name packages present. So Installed these using the nix commands:

nix-channel --update
nix-env -iA nixpkgs.git
nix-env -iA nixpkgs.automake
nix-env -iA nixpkgs.autoconf
nix-env -iA nixpkgs.zlib
nix-env -iA nixpkgs.python312
nix-env -iA nixpkgs.gnumake
nix-env -iA nixpkgs.libgcc
nix-env -iA nixpkgs.libtool
nix-env -iA nixpkgs.pkg-config
nix-env -iA nixpkgs.jdk17
nix-env -iA nixpkgs.leptonica
nix-env -iA nixpkgs.tesseract
nix-env -iA nixpkgs.unpaper
nix-env -iA nixpkgs.libreoffice
nix-env -iA nixpkgs.ocrmypdf

2 - The came the issue for building the jbig2enc package by fetching it from its git and building it. It showed Error! Leptonica not detected. when executing the ./configure. Maybe it was due to how nix installed that or I am not exactly sure, it didn't work. I tried getting the source of the nix-env, changed it to install the latest, took the installed libraries and changed the ./configure extra libraries path, lib path, include path but to no avail. Finally, the workaround for this was, I just searched for jbig2enc nix package (I just did not think of this since the instructions showed to build from its git) by running: nix-env -iA nixpkgs.jbig2enc

3 - Now it was up and running, but to a different port. Well this was quite simple, making the custom_configs.yml and putting:

server:
  host: 0.0.0.0
  port: 3000

For some reason, was not able to find it in the guide or anywhere iirc.

4 - Now that it was up and running, the conversion APIs used to fail (PDF to Word, PDF to Presentation). Basically the libreoffice dependencies. It give a very weird error:

19:48:10.871 [http-nio-3000-exec-16] INFO  s.s.SPDF.utils.ProcessExecutor - Running command: soffice --infilter=writer_pdf_import --convert-to doc --outdir /tmp/output_17933731567181759601 /tmp/input_8461399416971714634.pdf
19:48:10.903 [Thread-7] INFO  s.s.SPDF.utils.ProcessExecutor - mkdir: cannot create directory ‘/run/user/1501’: Permission denied

So after hours and hours of research (since I really couldn't find anything related to this on google), I tried to grep my way in the whole libreoffice library. And found many instances of this directory being used. To resolve this, before running the application, I execute a command: export DBUS_SESSION_BUS_ADDRESS="unix:path=/home/user/app/temp" You can keep whatever directory you want for temp/

5 - Now that this was resolved, I noticed, PDF to HTML was not working. So my guess is that pdftohtml is not included with the libreoffice package, so I resolved by installing poppler_utils via: nix-env -iA nixpkgs.poppler_utils

bluestero avatar May 06 '24 09:05 bluestero

@Frooodle So should I proceed with it?

bluestero avatar May 07 '24 09:05 bluestero