Inicializando o projeto.
This commit is contained in:
parent
8b37dec062
commit
dd97e4d96a
74
Dockerfile.dockerfile
Normal file
74
Dockerfile.dockerfile
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
FROM debian:bookworm-slim
|
||||||
|
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
ENV CUPS_VERSION=2.4.12
|
||||||
|
ENV TZ "America/Sao_Paulo"
|
||||||
|
ENV USERNAME admin
|
||||||
|
ENV PASSWORD password
|
||||||
|
|
||||||
|
# 1) Instala dependências de build + runtime, incluindo CA para HTTPS
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
ca-certificates \
|
||||||
|
git \
|
||||||
|
build-essential autoconf automake libtool pkg-config \
|
||||||
|
libssl-dev libgnutls28-dev \
|
||||||
|
zlib1g zlib1g-dev \
|
||||||
|
libavahi-client-dev \
|
||||||
|
printer-driver-all \
|
||||||
|
printer-driver-cups-pdf \
|
||||||
|
printer-driver-foo2zjs \
|
||||||
|
foomatic-db-compressed-ppds \
|
||||||
|
openprinting-ppds \
|
||||||
|
libreoffice \
|
||||||
|
libreoffice-common \
|
||||||
|
libnss-mdns \
|
||||||
|
hpijs-ppds \
|
||||||
|
file \
|
||||||
|
hp-ppd \
|
||||||
|
hplip \
|
||||||
|
dos2unix \
|
||||||
|
cups cups-client cups-filters cups-browsed \
|
||||||
|
curl avahi-daemon dbus \
|
||||||
|
iputils-ping \
|
||||||
|
vim \
|
||||||
|
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
RUN cd /opt && \
|
||||||
|
wget https://github.com/OpenPrinting/cups/releases/download/v${CUPS_VERSION}/cups-${CUPS_VERSION}-source.tar.gz && \
|
||||||
|
tar -xzf cups-${CUPS_VERSION}-source.tar.gz && \
|
||||||
|
cd cups-${CUPS_VERSION} && \
|
||||||
|
./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --with-rcdir=/etc/init.d && \
|
||||||
|
make -j$(nproc) && \
|
||||||
|
make install && \
|
||||||
|
cd / && rm -rf /opt/*
|
||||||
|
|
||||||
|
RUN sed -i 's/Listen localhost:631/Listen 0.0.0.0:631/' /etc/cups/cupsd.conf && \
|
||||||
|
sed -i 's/Browsing Off/Browsing On/' /etc/cups/cupsd.conf && \
|
||||||
|
sed -i 's/<Location \/>/<Location \/>\n Allow All/' /etc/cups/cupsd.conf && \
|
||||||
|
sed -i 's/<Location \/admin>/<Location \/admin>\n Allow All\n Require user @SYSTEM/' /etc/cups/cupsd.conf && \
|
||||||
|
sed -i 's/<Location \/admin\/conf>/<Location \/admin\/conf>\n Allow All/' /etc/cups/cupsd.conf && \
|
||||||
|
echo "ServerAlias *" >> /etc/cups/cupsd.conf && \
|
||||||
|
echo "DefaultEncryption Never" >> /etc/cups/cupsd.conf
|
||||||
|
|
||||||
|
RUN echo 'application/vnd.openxmlformats-officedocument.wordprocessingml.document docx' >> /etc/cups/raw.types && \
|
||||||
|
echo 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx' >> /etc/cups/raw.types
|
||||||
|
|
||||||
|
RUN echo 'application/vnd.openxmlformats-officedocument.wordprocessingml.document application/pdf 100 doc2pdf' >> /etc/cups/raw.convs && \
|
||||||
|
echo 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet application/pdf 100 doc2pdf' >> /etc/cups/raw.convs
|
||||||
|
|
||||||
|
RUN cp -a /etc/cups /etc/cups.default
|
||||||
|
|
||||||
|
# 4) Volumes para persistência de config, spool e logs
|
||||||
|
VOLUME ["/etc/cups", "/var/spool/cups", "/var/log/cups"]
|
||||||
|
|
||||||
|
# 5) Expõe a porta da interface web/admin do CUPS
|
||||||
|
EXPOSE 631 5353/udp
|
||||||
|
|
||||||
|
COPY doc2pdf.sh /usr/lib/cups/filter/doc2pdf
|
||||||
|
RUN dos2unix /usr/lib/cups/filter/doc2pdf \
|
||||||
|
&& chmod 755 /usr/lib/cups/filter/doc2pdf
|
||||||
|
|
||||||
|
COPY entrypoint.sh /
|
||||||
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
|
CMD ["/entrypoint.sh"]
|
||||||
@ -1,2 +1,2 @@
|
|||||||
# cups
|
# Cups
|
||||||
A Simple Docker cups with libreoffice filter to print docx/xlsx
|
A Simple Docker cups with libreoffice filter to print docx/xlsx
|
||||||
|
|||||||
58
doc2pdf.sh
Normal file
58
doc2pdf.sh
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# /usr/lib/cups/filter/doc2pdf
|
||||||
|
set -e
|
||||||
|
|
||||||
|
JOB_ID="$1"
|
||||||
|
USER="$2"
|
||||||
|
TITLE="$3"
|
||||||
|
COPIES="$4"
|
||||||
|
OPTIONS="$5"
|
||||||
|
FILE="$6"
|
||||||
|
|
||||||
|
# Função para extrair extensão a partir do document-format (se existir)
|
||||||
|
ext_from_options() {
|
||||||
|
echo "$OPTIONS" \
|
||||||
|
| sed -n 's/.*document-format=\([^ ,]*\).*/\1/p' \
|
||||||
|
| awk -F/ '{print $2}' \
|
||||||
|
| sed -e 's/+xml//g' -e 's/xlsx/spreadsheetml.sheet/' \
|
||||||
|
-e 's/wordprocessingml.document/docx/' \
|
||||||
|
-e 's/spreadsheetml.sheet/xlsx/'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Se o CUPS passou o arquivo via stdin, ou se FILE não termina em .docx/.xlsx
|
||||||
|
if [ "$FILE" = "-" ] || ! echo "$FILE" | grep -E '\.(docx|xlsx)$' >/dev/null; then
|
||||||
|
# detecta extensão: primeiro tenta pelas OPTIONS
|
||||||
|
EXT=$(ext_from_options)
|
||||||
|
# se ainda vazio, usa file --mime-type
|
||||||
|
if [ -z "$EXT" ]; then
|
||||||
|
MIME=$(file --mime-type -b "$FILE")
|
||||||
|
case "$MIME" in
|
||||||
|
application/vnd.openxmlformats-officedocument.wordprocessingml.document) EXT=docx ;;
|
||||||
|
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet) EXT=xlsx ;;
|
||||||
|
*) EXT="" ;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$EXT" ]; then
|
||||||
|
echo "Não consegui determinar extensão para conversão (mime: $MIME, options: $OPTIONS)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TMPFILE="/tmp/job-${JOB_ID}.$EXT"
|
||||||
|
cat "${FILE:-/dev/stdin}" > "$TMPFILE"
|
||||||
|
FILE="$TMPFILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Por fim, converte DOCX/XLSX válidos
|
||||||
|
case "${FILE##*.}" in
|
||||||
|
docx|xlsx)
|
||||||
|
libreoffice --headless --convert-to pdf:"writer_pdf_Export" \
|
||||||
|
--outdir /tmp "$FILE"
|
||||||
|
PDF="/tmp/$(basename "${FILE%.*}.pdf")"
|
||||||
|
cat "$PDF"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Formato não suportado: ${FILE##*.}" >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
18
docker-compose.yaml
Normal file
18
docker-compose.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
services:
|
||||||
|
cups:
|
||||||
|
image: grandow/cups:2.4.12-office
|
||||||
|
container_name: cups
|
||||||
|
restart: unless-stopped
|
||||||
|
ulimits:
|
||||||
|
nofile:
|
||||||
|
soft: "65536"
|
||||||
|
hard: "65536"
|
||||||
|
ports:
|
||||||
|
- "631:631"
|
||||||
|
environment:
|
||||||
|
- USERNAME=admin
|
||||||
|
- PASSWORD=cups
|
||||||
|
- TZ="America/Sao_Paulo"
|
||||||
|
volumes:
|
||||||
|
- "/srv/waprint/cups/:/etc/cups/"
|
||||||
33
entrypoint.sh
Normal file
33
entrypoint.sh
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
if [ $(grep -ci $USERNAME /etc/shadow) -eq 0 ]; then
|
||||||
|
useradd -r -G lpadmin -M $USERNAME
|
||||||
|
|
||||||
|
# add password
|
||||||
|
echo $USERNAME:$PASSWORD | chpasswd
|
||||||
|
|
||||||
|
# add tzdata
|
||||||
|
ln -fs /usr/share/zoneinfo/$TZ /etc/localtime
|
||||||
|
dpkg-reconfigure --frontend noninteractive tzdata
|
||||||
|
fi
|
||||||
|
|
||||||
|
# restore default cups config in case user does not have any
|
||||||
|
if [ ! -f /etc/cups/cupsd.conf ]; then
|
||||||
|
cp -p /etc/cups.default/cupsd.conf /etc/cups/
|
||||||
|
cp -p /etc/cups.default/printers.conf /etc/cups/
|
||||||
|
#cp -rpn /etc/cups.default/* /etc/cups/
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d /etc/cups.default/ppd ]; then
|
||||||
|
mkdir -p /etc/cups/ppd
|
||||||
|
cp -rp /etc/cups.default/ppd/* /etc/cups/ppd/
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Inicia o tail dos logs em background
|
||||||
|
tail -F /var/log/cups/access_log /var/log/cups/error_log &
|
||||||
|
|
||||||
|
# Inicia o CUPS em foreground
|
||||||
|
/usr/sbin/cupsd -f &
|
||||||
|
CUPSD_PID=$!
|
||||||
|
|
||||||
|
# Espera o CUPS morrer ou o tail encerrar
|
||||||
|
wait $CUPSD_PID
|
||||||
Loading…
x
Reference in New Issue
Block a user