summarylogtreecommitdiffstats
path: root/remarkable.sh
blob: ffad6df8b16f91abd9421f643621a52db4636845 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
set -e

jobid=$1
cupsuser=$2
jobtitle=$3
jobcopies=$4
joboptions=$5
jobfile=${6:--}

export RMAPI_CONFIG=/etc/rmapi.conf

printtime=$(date +%Y-%b-%d-%H-%M)
sanitized_jobtitle="$(echo "$jobtitle" | tr "[[:blank:]:/%\&=+?\\\\#\'\`\´\*]" _ | sed 's/ü/u/g;s/ä/a/g;s/ö/o/g;s/Ü/U/g;s/Ä/A/g;s/Ö/O/g;s/{\\ß}/ss/g' | cut -f 1 -d '.' ).pdf"
outname=/tmp/${printtime}_${sanitized_jobtitle}

if [ ${#} -eq 0 ]; then
    # this case is for "backend discovery mode"
    echo "Remarkable Printer \"Backend to print directly to Remarkable cloud\""
    exit 0
fi

if pdfinfo "$jobfile" > /dev/null ; then
    cp "$jobfile" "$outname"
else
    ps2pdf "$jobfile" "$outname"
fi
if [ ! -e "${DEVICE_URI#remarkable:}" ]; then
    rmapi mkdir "${DEVICE_URI#remarkable:}" > /dev/null
    rmapi put "$outname" "${DEVICE_URI#remarkable:}"
else
    rmapi put "$outname"
fi

rm "$outname"

echo 1>&2

exit 0