ReMarkable CUPS print on OS X
Hi.
The backend script expects 5 or 6 arguments, but the cups printing on OS X appears to pass a lot more:
26 77165 76719 0 11:07AM ?? 0:00.02 /bin/bash /usr/libexec/cups/backend/remarkable 9 thorbenj testprint 1 AP_ColorMatchingMode=AP_ApplicationColorMatching AP_D_InputSlot= nocollate com.apple.print.DocumentTicket.PMSpoolFormat=application/pdf com.apple.print.JobInfo.PMJobName=testprint com.apple.print.PrinterInfo.PMColorDeviceID..n.=5688 com.apple.print.PrintSettings.PMCopies..n.=1 com.apple.print.PrintSettings.PMCopyCollate..b. com.apple.print.PrintSettings.PMDuplexing..n.=1 com.apple.print.PrintSettings.PMFirstPage..n.=1 com.apple.print.PrintSettings.PMLastPage..n.=2147483647 com.apple.print.PrintSettings.PMPageRange..a.0..n.=1 com.apple.print.PrintSettings.PMPageRange..a.1..n.=2147483647 fit-to-page media=A4 pserrorhandler-requested=standard sides=one-sided job-uuid=urn:uuid:b4d64749-0c46-3d8c-51b4-a0918a857fe3 job-originating-host-name=localhost date-time-at-creation= date-time-at-processing= time-at-creation=1561626442 time-at-processing=1561626442 document-name-supplied=testprint PageSize=A4
So the script is currently swollowing the print without error, as there is an exit 0 at the end.
I will maybe try to tweak the script, but first I thought I would document how I got this far on OS X for other users:
The PPD should be gziped and placed here: /Library/Printers/PPDs/Contents/Resources/ReMarkable.ppd.gz
Confirm with:
localhost:~ root# lpinfo -m | grep -i remarkable
Library/Printers/PPDs/Contents/Resources/ReMarkable.ppd.gz Remarkable Tablet, 1.0
The backend script should go here: /usr/libexec/cups/backend/remarkable
the "_lp" user needs to be able to use rmapi. (as root do the following)
ln -s /Users/USERNAME/.rmapi /var/spool/cups/.rmapi
chown USERNAME:_lp /Users/USERNAME/.rmapi
chmod g+r /Users/USERNAME/.rmapi
Add the printer:
lpadmin -L 'my.ReMarkable Cloud' -D 'my.ReMarkable Cloud Printer' -m /Library/Printers/PPDs/Contents/Resources/ReMarkable.ppd.gz -p remarkable -E -v 'remarkable:/PrintOuts'
So I've localised the problem to SIP (System Integrity Protection), think SELinux but for OS X.
The script may not write to /tmp. So I edited it to use /var/spool/cups/tmp
rmapi must be in a vaild bin dir, so I copied it to /usr/local/bin; it can now execute. However rmapi my not open path /var/spool/cups/.rmapi; this is forbidden.
It does not appear that rmapi allow overriding the location of that file. I will have to open a ticket there.
https://github.com/juruen/rmapi/issues/59
BTW for debugging, I added this near the top of the script:
DEBUGLOG=/var/spool/cups/tmp/rm.log
date > $DEBUGLOG
id >> $DEBUGLOG
env >> $DEBUGLOG
echo "Args(${#})" >> $DEBUGLOG
exec 1>$DEBUGLOG 2>&1
Note the date print will truncate the log.
With a custom version of rmapi, I can now print on OS X
Hmm, what to add? @ThorbenJ :+1:
Up to you here is my version of the script:
#!/bin/bash
backend=${0}
jobid=${1}
cupsuser=${2}
jobtitle=${3}
jobcopies=${4}
joboptions=${5}
jobfile=${6}
rmapi="/usr/local/bin/rmapi"
DEBUGLOG=/var/spool/cups/tmp/rm.log
date > $DEBUGLOG
id >> $DEBUGLOG
env >> $DEBUGLOG
echo "Args(${#})" >> $DEBUGLOG
exec 1>$DEBUGLOG 2>&1
tmpdir=/var/spool/cups/tmp
printtime=$(date +%Y-%b-%d-%H-%M)
sanitized_jobtitle="$(echo ${jobtitle} | tr [[:blank:]:/%\&=+?\\\\#\'\`\´\*] _)"
outname=${tmpdir}/${printtime}_${sanitized_jobtitle}
case ${#} in
0)
# this case is for "backend discovery mode"
echo "Remarkable Printer \"Mark Meyer\" \"Backend to print directly to Remarkable cloud\""
exit 0
;;
5)
# backend needs to read from stdin if number of arguments is 5
cat - > ${outname}
if [ ! -e ${DEVICE_URI#remarkable:} ]; then
${rmapi} put ${outname} ${DEVICE_URI#remarkable:}
else
${rmapi} put ${outname}
fi
rm ${outname}
;;
6)
cat ${6} > ${outname}
if [ ! -e ${DEVICE_URI#remarkable:} ]; then
${rmapi} put ${outname} ${DEVICE_URI#remarkable:}
else
${rmapi} put ${outname}
fi
;;
esac
#echo 1>&2
exit 0
Some Notes: the data > .. will truncate the logfile each run
the exec > .. redirect stdout and stderr to that log file
I do not know what echo 1>&2 intended to do, so I commented it out.
Documentation changes/notes:
On OS X the "remarkable" script needs to go in /usr/libexec/cups/backend/remarkable
The PPD needs to be in: /Library/Printers/PPDs/Contents/Resources/ReMarkable.ppd.gz
rmapi needs to be in /usr/local/bin/rmapi
and it must load its config from /etc/cups/rmapi.conf and not ~/.rmapi.
The do this I edited go/src/github.com/juruen/rmapi/config/config.go
adding return "/etc/cups/rmapi.conf" to the begining of func ConfigPath() string {
and then re-run go build.
my lpadmin command was:
lpadmin -E -L 'my.reMarkable Cloud' -D 'my.reMarkable Cloud Printer' -m /Library/Printers/PPDs/Contents/Resources/ReMarkable.ppd.gz -p remarkable -v 'remarkable:/PrintOuts'
BR, -T