Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions remarkable-cups/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#! /usr/bin/env bash

# Set bash to stop execution on failed commands. For sanity and safety
set -e

echo "Adding Unofficial remarkable printing driver"

# Compile ppd driver & copy to somewhere where CUPS can find it.
ppdc remarkable.drv; sudo cp ppd/remarkable.ppd /usr/share/cups/model/

# Find rmapi binary
RMAPI=$(which rmapi)
if [ -f $RMAPI ]; then
# Escape all '/' from rmapi path in order to use sed later
RMAPI=$(echo $RMAPI|sed 's/\//\\\//g')
# Replace original rmapi-location from rmapi.sh
template='s/#TEMPLATED_BY_INSTALL/rmapi='$RMAPI'/'
sed -i $template remarkable.sh
fi

# TODO Copy rmapi binary to print user (root)
# TODO Get rid of root user, use some lower privileged user for printing

# Copy & rename CUPS backend script
sudo cp remarkable.sh /usr/lib/cups/backend/remarkable

# Secure permissions
sudo chown root:root /usr/lib/cups/backend/remarkable
sudo chmod 700 /usr/lib/cups/backend/remarkable

# Add/Update "Remarkable" cups printer
sudo lpadmin -L 'Cloud Printer' -D 'my remarkable' -p "reMarkable" -E -v 'remarkable:/Print'

# Copy user credentials for printer driver user home
FILE=~/.rmapi
if [ -f "$FILE" ]; then
echo "Installing credentials for cups user (root in debian)"
sudo cp $FILE /root/
else
echo "$FILE does not exist, please authenticate with .rmapi file"
fi

echo "Do you want to print a test page?"
read -p 'test page? (y/N): ' tp

if [ "$tp" = "y" ]; then
echo "Hi there! Hopefully this printer works! Cheers to RMS!" >> /tmp/rminstall.txt
pandoc -i /tmp/rminstall.txt -o /tmp/test.pdf
lp -d reMarkable /tmp/test.pdf
rm /tmp/test.pdf /tmp/rminstall.txt
fi

echo "All done ✓, happy printing! "
7 changes: 6 additions & 1 deletion remarkable-cups/remarkable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ jobcopies=${4}
joboptions=${5}
jobfile=${6}

#Default value if templating does not find tha binary
rmapi=/home/mark/gosrc/bin/rmapi

#### Installation script will template a new path for rmapi-binary
#TEMPLATED_BY_INSTALL
#### End of templating

printtime=$(date +%Y-%b-%d-%H-%M)
sanitized_jobtitle="$(echo ${jobtitle} | tr [[:blank:]:/%\&=+?\\\\#\'\`\´\*] _)"
outname=/tmp/${printtime}_${sanitized_jobtitle}
Expand All @@ -30,7 +35,7 @@ case ${#} in
fi
rm ${outname}
;;

6)
cat ${6} > ${outname}
if [ ! -e ${DEVICE_URI#remarkable:} ]; then
Expand Down