Skip to content

Commit 0fd9803

Browse files
committed
remarkable: Scripts for Remarkable notepad.
1 parent 3bf1582 commit 0fd9803

File tree

1 file changed

+189
-0
lines changed

1 file changed

+189
-0
lines changed
+189
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
#!/bin/sh
2+
# Transfer PDF and EPUB file(s) to a reMarkable
3+
# Adrian Daerr and contributors, 2017 -- 2022 - public domain
4+
# https://github.com/adaerr/reMarkableScripts
5+
#
6+
# - The files will appear in reMarkable's top-level "My Files" directory,
7+
# - After finishing all transfers, you have to restart the xochitl
8+
# service on the tablet in order to force a scan of its document
9+
# directory ${REMARKABLE_XOCHITL_DIR} (so that you see the newly
10+
# transferred files), e.g. by sending the tablet the following
11+
# command:
12+
# ssh remarkable systemctl restart xochitl
13+
# This script will do that for you at the end if you
14+
# (set the environment variable RESTART_XOCHITL_DEFAULT to 1)
15+
# xor (specify "-r" as first command line parameter).
16+
# - See list of prerequisites, and more environment variables below.
17+
#
18+
# Disclaimer and liability limitation:
19+
# [see also all-caps text borrowed from GPL below]
20+
# - This is a dirty hack based on superficial reverse-engineering.
21+
# - Expect this script to break at any time, especially upon a
22+
# reMarkable system upgrade
23+
# - I am not responsible for any damage caused by this script,
24+
# including (but not limited to) bricking your reMarkable, erasing
25+
# your documents etc. YOU ARE USING THIS SOFTWARE ON YOUR OWN RISK.
26+
#
27+
# Disclaimer of Warranty.
28+
#
29+
# THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
30+
# APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
31+
# COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM
32+
# “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
33+
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34+
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE
35+
# RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
36+
# SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
37+
# NECESSARY SERVICING, REPAIR OR CORRECTION.
38+
#
39+
# Limitation of Liability.
40+
#
41+
# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
42+
# WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO
43+
# MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE
44+
# LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
45+
# INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
46+
# INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
47+
# DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
48+
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
49+
# WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS
50+
# BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
51+
#
52+
# Prerequisites:
53+
#
54+
# * The ssh access has to be configured under the host alias 'remarkable'
55+
# (or another alias specified in the env variable REMARKABLE_HOST),
56+
# e.g. by putting the following in .ssh/config :
57+
# | host remarkable
58+
# | Hostname 10.11.99.1
59+
# | User root
60+
# | ForwardX11 no
61+
# | ForwardAgent no
62+
# (and setup ssh public key authentication to avoid typing your passwd)
63+
#
64+
# * Beyond core utilities (date, basename,...), the following software
65+
# has to be installed on the host computer:
66+
# - uuidgen
67+
68+
# This is where ssh will try to copy the files associated with the document
69+
REMARKABLE_HOST=${REMARKABLE_HOST:-remarkable}
70+
REMARKABLE_XOCHITL_DIR=${REMARKABLE_XOCHITL_DIR:-.local/share/remarkable/xochitl/}
71+
TARGET_DIR="${REMARKABLE_HOST}:${REMARKABLE_XOCHITL_DIR}"
72+
73+
# Check if we have something to do
74+
if [ $# -lt 1 ]; then
75+
echo "Transfer PDF or EPUB document(s) to a reMarkable tablet."
76+
echo "See comments/documentation at start of script."
77+
echo "usage: $(basename $0) [ -r ] path-to-file [path-to-file]..."
78+
exit 1
79+
fi
80+
81+
RESTART_XOCHITL_DEFAULT=${RESTART_XOCHITL_DEFAULT:-0}
82+
RESTART_XOCHITL=${RESTART_XOCHITL_DEFAULT}
83+
if [ "$1" = "-r" ] ; then
84+
shift
85+
if [ $RESTART_XOCHITL_DEFAULT -eq 0 ] ; then
86+
echo Switching
87+
RESTART_XOCHITL=1
88+
else
89+
RESTART_XOCHITL=0
90+
fi
91+
fi
92+
93+
# Create directory where we prepare the files as the reMarkable expects them
94+
tmpdir=$(mktemp -d)
95+
96+
# Loop over the command line arguments,
97+
# which we expect are paths to the files to be transferred
98+
for filename in "$@" ; do
99+
100+
# reMarkable documents appear to be identified by universally unique IDs (UUID),
101+
# so we generate one for the document at hand
102+
uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')
103+
104+
extension="${filename##*.}"
105+
106+
# Copy the file itself
107+
cp -- "$filename" "${tmpdir}/${uuid}.${extension}"
108+
109+
# Add metadata
110+
# The lastModified item appears to contain the date in milliseconds since Epoch
111+
cat <<EOF >>${tmpdir}/${uuid}.metadata
112+
{
113+
"deleted": false,
114+
"lastModified": "$(date +%s)000",
115+
"metadatamodified": false,
116+
"modified": false,
117+
"parent": "",
118+
"pinned": false,
119+
"synced": false,
120+
"type": "DocumentType",
121+
"version": 1,
122+
"visibleName": "$(basename -- "$filename" ".$extension")"
123+
}
124+
EOF
125+
126+
if [ "$extension" = "pdf" ]; then
127+
# Add content information
128+
cat <<EOF >${tmpdir}/${uuid}.content
129+
{
130+
"extraMetadata": {
131+
},
132+
"fileType": "pdf",
133+
"fontName": "",
134+
"lastOpenedPage": 0,
135+
"lineHeight": -1,
136+
"margins": 100,
137+
"pageCount": 1,
138+
"textScale": 1,
139+
"transform": {
140+
"m11": 1,
141+
"m12": 1,
142+
"m13": 1,
143+
"m21": 1,
144+
"m22": 1,
145+
"m23": 1,
146+
"m31": 1,
147+
"m32": 1,
148+
"m33": 1
149+
}
150+
}
151+
EOF
152+
153+
# Add cache directory
154+
mkdir ${tmpdir}/${uuid}.cache
155+
156+
# Add highlights directory
157+
mkdir ${tmpdir}/${uuid}.highlights
158+
159+
# Add thumbnails directory
160+
mkdir ${tmpdir}/${uuid}.thumbnails
161+
162+
elif [ "$extension" = "epub" ]; then
163+
164+
# Add content information
165+
cat <<EOF >${tmpdir}/${uuid}.content
166+
{
167+
"fileType": "epub"
168+
}
169+
EOF
170+
171+
else
172+
echo "Unknown extension: $extension, skipping $filename"
173+
rm -rf ${tmpdir}/*
174+
continue
175+
fi
176+
177+
# Transfer files
178+
echo "Transferring $filename as $uuid"
179+
scp -r ${tmpdir}/* "${TARGET_DIR}"
180+
rm -rf ${tmpdir}/*
181+
done
182+
183+
rm -rf ${tmpdir}
184+
185+
if [ $RESTART_XOCHITL -eq 1 ] ; then
186+
echo "Restarting Xochitl..."
187+
ssh ${REMARKABLE_HOST} "systemctl restart xochitl"
188+
echo "Done."
189+
fi

0 commit comments

Comments
 (0)