-
-
Save MinjeJeon/ea0a1dc391a7e9b1d2915037d7610bb4 to your computer and use it in GitHub Desktop.
Small file that installes ad uses weasyprint instead of wkhtmltopdf on linuxserver bookstack containers..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM linuxserver/bookstack:latest | |
COPY ./install-weasyproxy.sh /tmp/ | |
RUN sh /tmp/install-weasyproxy.sh | |
RUN mkdir /custom-cont-init.d/ | |
COPY ./init-weasyproxy.sh /custom-cont-init.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# run on every container startup, as mounting the entire /config directory will cause the css to disappear | |
# create css files for page sizes, if missing | |
if [ ! -d /config/weasyproxy ]; then | |
mkdir /config/weasyproxy | |
fi | |
if [ ! -f /config/weasyproxy/A4.css ]; then | |
cat << EOF > /config/weasyproxy/A4.css | |
@page { | |
size: A4; | |
} | |
EOF | |
fi | |
if [ ! -f /config/weasyproxy/Letter.css ]; then | |
cat << EOF > /config/weasyproxy/Letter.css | |
@page { | |
size: Letter; | |
} | |
EOF | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# SPDX-FileCopyrightText: 2022 Peter Magnusson <me@kmpm.se> | |
# | |
# SPDX-License-Identifier: CC0-1.0 | |
# | |
# This file installs weasyprint and creates a script that | |
# tries to proxy calls from bookstack to what it believe is | |
# wkhtmltopdf. | |
# | |
# put this file in /custom-cont-init.d and restart the container | |
# | |
# add the following to /config/www/.env | |
# WKHTMLTOPDF=/usr/local/bin/weasyproxy | |
# ALLOW_UNTRUSTED_SERVER_FETCHING=true | |
# | |
# install weasyprint | |
apk add --update --no-cache weasyprint | |
# create the weasyproxy script | |
cat << EOF > /usr/local/bin/weasyproxy | |
#!/bin/bash | |
# this tries to work as a proxy between wkhtmltopdf and weasyprint | |
# for bookstack to use on for example the linuxserver alpine image | |
set -o errexit -o pipefail -o noclobber -o nounset | |
LOGFILE=/config/log/weasyproxy.log | |
echo "--- weasyproxy \$(date) ---" | tee -a \$LOGFILE | |
echo "inbound arguments: \$@" | tee -a \$LOGFILE | |
# -allow a command to fail with !’s side effect on errexit | |
# -use return value from \${PIPESTATUS[0]}, because ! hosed \$? | |
! getopt --test > /dev/null | |
if [[ \${PIPESTATUS[0]} -ne 4 ]]; then | |
echo 'I’m sorry, `getopt --test` failed in this environment.' | |
exit 1 | |
fi | |
LONGOPTS=lowquality,page-size:,outline,print-media-type | |
OPTIONS=ls: | |
! PARSED=\$(getopt --options=\$OPTIONS --longoptions=\$LONGOPTS --name "\$0" -- "\$@") | |
if [[ \${PIPESTATUS[0]} -ne 0 ]]; then | |
# e.g. return value is 1 | |
# then getopt has complained about wrong arguments to stdout | |
exit 2 | |
fi | |
eval set -- "\$PARSED" | |
PAGE_SIZE=Letter | |
OUTLINE=n | |
MEDIA=screen | |
ARGS="-p" # add -v for verbose and -d for debug output | |
while true; do | |
case "\$1" in | |
-l|--lowquality) | |
ARGS="\$ARGS -O images" | |
shift | |
;; | |
-p|--page-size) | |
PAGE_SIZE=\$2 | |
shift 2 | |
;; | |
--outline) | |
OUTLINE=y | |
shift | |
;; | |
--print-media-type) | |
MEDIA=print | |
shift | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
echo "unsupported argument '\$1'" | tee -a \$LOGFILE | |
exit 3 | |
;; | |
esac | |
done | |
ARGS="\$ARGS -s /config/weasyproxy/\${PAGE_SIZE}.css --media-type \${MEDIA}" | |
echo "PAGE_SIZE = \${PAGE_SIZE}" | tee -a \$LOGFILE | |
echo "OUTLINE = \${OUTLINE}" | tee -a \$LOGFILE | |
echo "MEDIA = \${MEDIA}" | tee -a \$LOGFILE | |
echo "ARGS = \${ARGS}" | tee -a \$LOGFILE | |
if [[ \$# -ne 2 ]]; then | |
echo "\$0: input and output arguments is required" | tee -a \$LOGFILE | |
exit 4 | |
fi | |
weasyprint \${ARGS} \$1 \$2 >>\$LOGFILE 2>&1 | |
EOF | |
# create css files for page sizes, if missing | |
if [ ! -d /config/weasyproxy ]; then | |
mkdir /config/weasyproxy | |
fi | |
if [ ! -f /config/weasyproxy/A4.css ]; then | |
cat << EOF > /config/weasyproxy/A4.css | |
@page { | |
size: A4; | |
} | |
EOF | |
fi | |
if [ ! -f /config/weasyproxy/Letter.css ]; then | |
cat << EOF > /config/weasyproxy/Letter.css | |
@page { | |
size: Letter; | |
} | |
EOF | |
fi | |
chmod +x /usr/local/bin/weasyproxy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment