Get rid of wrapper scripts in the container

This commit is contained in:
Micah Lee 2021-11-29 15:39:24 -08:00
parent 2de2b6dca5
commit 8052220034
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
5 changed files with 17 additions and 29 deletions

View file

@ -88,8 +88,7 @@ RUN \
chmod +x /usr/local/bin/pdftk chmod +x /usr/local/bin/pdftk
COPY dangerzone.py /usr/local/bin/ COPY dangerzone.py /usr/local/bin/
COPY document-to-pixels /usr/local/bin/ RUN chmod +x /usr/local/bin/dangerzone.py
COPY pixels-to-pdf /usr/local/bin/
# Add the unprivileged user # Add the unprivileged user
RUN adduser -h /home/user -s /bin/sh -D user RUN adduser -h /home/user -s /bin/sh -D user

View file

@ -17,6 +17,7 @@ import subprocess
import glob import glob
import os import os
import json import json
import shutil
import magic import magic
from PIL import Image from PIL import Image
@ -300,6 +301,15 @@ class DangerzoneConverter:
"Converted document to pixels", "Converted document to pixels",
percentage, percentage,
) )
# Move converted files into /dangerzone
for filename in (
glob.glob("/tmp/page-*.rgb")
+ glob.glob("/tmp/page-*.width")
+ glob.glob("/tmp/page-*.height")
):
shutil.move(filename, "/dangerzone")
return 0 return 0
def pixels_to_pdf(self): def pixels_to_pdf(self):
@ -500,6 +510,10 @@ class DangerzoneConverter:
percentage = 100.0 percentage = 100.0
self.output(False, "Safe PDF created", percentage) self.output(False, "Safe PDF created", percentage)
# Move converted files into /safezone
shutil.move("/tmp/safe-output.pdf", "/safezone")
shutil.move("/tmp/safe-output-compressed.pdf", "/safezone")
return 0 return 0
def output(self, error, text, percentage): def output(self, error, text, percentage):

View file

@ -1,14 +0,0 @@
#!/bin/sh
# Do the conversion
/usr/bin/python3 /usr/local/bin/dangerzone.py document-to-pixels
RETURN_CODE=$?
if [ $RETURN_CODE -ne 0 ]; then
echo ""
exit $RETURN_CODE
fi
# Move converted files into /dangerzone
/bin/mv /tmp/page-*.rgb /dangerzone
/bin/mv /tmp/page-*.width /dangerzone
/bin/mv /tmp/page-*.height /dangerzone

View file

@ -1,13 +0,0 @@
#!/bin/sh
# Do the conversion
OCR=$OCR OCR_LANGUAGE=$OCR_LANGUAGE /usr/bin/python3 /usr/local/bin/dangerzone.py pixels-to-pdf
RETURN_CODE=$?
if [ $RETURN_CODE -ne 0 ]; then
echo ""
exit $RETURN_CODE
fi
# Move converted files into /safezone
/bin/mv /tmp/safe-output.pdf /safezone
/bin/mv /tmp/safe-output-compressed.pdf /safezone

View file

@ -85,6 +85,7 @@ def convert(input_filename, output_filename, ocr_lang, stdout_callback):
"-v", "-v",
f"{pixel_dir}:/dangerzone", f"{pixel_dir}:/dangerzone",
container_name, container_name,
"dangerzone.py",
"document-to-pixels", "document-to-pixels",
] ]
ret = exec_container(args, stdout_callback) ret = exec_container(args, stdout_callback)
@ -109,6 +110,7 @@ def convert(input_filename, output_filename, ocr_lang, stdout_callback):
"-e", "-e",
f"OCR_LANGUAGE={ocr_lang}", f"OCR_LANGUAGE={ocr_lang}",
container_name, container_name,
"dangerzone.py",
"pixels-to-pdf", "pixels-to-pdf",
] ]
ret = exec_container(args, stdout_callback) ret = exec_container(args, stdout_callback)