# Check is there is another web renderer instance active
wait_for_node_to_finish() {
while pgrep -x "node" > /dev/null; do
echo "node is currently running. Waiting..."
sleep 1 # Wait for 1 second before checking again
done
}
# Check for the lpr command if it's compatible
command_name="lpr"
search_string="lpr - print files"
# Search the man page for the string
if man "$command_name" 2>/dev/null | grep -q "$search_string"; then
echo "$command_name is compatible" > /dev/null
else
echo "Incompatible or not installed lpr program - exiting"
echo "Install the right version of the lpr program or if using a distro which ships older packages like lpr, move to a newer distro which has fresher packages."
exit 1
fi
printer=examplename # replace this with your actual printer name before putting it into /usr/bin
imagelogmsg="Server hoster decided to enable file logging, if you don't wish your file to be logged, ask the server owner to delete your sent file or if you are the server hoster set LOG=nolog in .env file" # specify a custom logging of files message
nsfwscantosmsg="Server hoster enabled NSFW scanning, by sending any images to this instance, you agree to the DeepAI TOS at https://deepai.org/terms-of-service/terms-of-service to scan them." # specify a custom logging of NSFW message
nsfwscantrue="The following image you uploaded is not safe for work. Due to Cloudflare TOS, you cannot send content promoting NSFW"
deepaiapikey=00000000-0000-0000-0000-000000000000 # replace zeros with your actual API key
# If the user specified for NSFW scanning (.env configuration flag: NSFWSCAN=true) then check if there is a argument passed to scan for it
# To use the DeepAI NSFW scanning service, provide a API key under the variable deepaiapikey (leave it blank, and specify NSFWSCAN=false in .env if you are not using it)
lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "/tmp/outputweb.png" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
else
echo "Rendering HTML file"
wait_for_node_to_finish
node index.js $1 /tmp/outputweb.png
echo "Printing rendered HTML file"
lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "/tmp/outputweb.png" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "/tmp/outputweb.png" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
else
echo "'url' variable not found in [htmlrender] section of text file, assuming normal text"
fi
else
echo "[htmlrender] section not found in text file, assuming normal text"
lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "/tmp/outputweb.png" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
else
echo "'url' variable not found in [htmlrender] section of text file, assuming normal text"
fi
else
echo "[htmlrender] section not found in text file, assuming normal text"
lpr -r -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "$1" -P $printer && exit 0 # if you are using a different printer that requires different commands to print, change this part of the code.
echo "Converting Microsoft Office file format to .pdf"
filename=$(basename "$1")
extensionless="${filename%.*}"
echo "converted file is "$extensionless
libreoffice --headless --convert-to pdf "$1" --outdir "/tmp/$extensionless" || bash -c 'echo "Conversion failed, try again later" && exit 1'
echo "Printing .pdf converted Microsoft Office file"
lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "/tmp/$extensionless.pdf" -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.
echo "Converting Microsoft Office file format to .pdf"
filename=$(basename "$1")
extensionless="${filename%.*}"
echo "converted file is "$extensionless
libreoffice --headless --convert-to pdf "$1" --outdir "/tmp/$extensionless" || bash -c 'echo "Conversion failed, try again later" && exit 1'
echo "Printing .pdf converted Microsoft Office file"
lpr -o portrait -o media=A4 -o fit-to-page -o print-quality=$quality $pagerange "/tmp/$extensionless.pdf" -P $printer # if you are using a different printer that requires different commands to print, change this part of the code.