···
3
-
# Transfer PDF and EPUB file(s) to a reMarkable
4
-
# Adrian Daerr and contributors, 2017 -- 2022 - public domain
5
-
# https://github.com/adaerr/reMarkableScripts
7
-
# - The files will appear in reMarkable's top-level "My Files" directory,
8
-
# - After finishing all transfers, you have to restart the xochitl
9
-
# service on the tablet in order to force a scan of its document
10
-
# directory ${REMARKABLE_XOCHITL_DIR} (so that you see the newly
11
-
# transferred files), e.g. by sending the tablet the following
13
-
# ssh remarkable systemctl restart xochitl
14
-
# This script will do that for you at the end if you
15
-
# (set the environment variable RESTART_XOCHITL_DEFAULT to 1)
16
-
# xor (specify "-r" as first command line parameter).
17
-
# - See list of prerequisites, and more environment variables below.
19
-
# Disclaimer and liability limitation:
20
-
# [see also all-caps text borrowed from GPL below]
21
-
# - This is a dirty hack based on superficial reverse-engineering.
22
-
# - Expect this script to break at any time, especially upon a
23
-
# reMarkable system upgrade
24
-
# - I am not responsible for any damage caused by this script,
25
-
# including (but not limited to) bricking your reMarkable, erasing
26
-
# your documents etc. YOU ARE USING THIS SOFTWARE ON YOUR OWN RISK.
28
-
# Disclaimer of Warranty.
30
-
# THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
31
-
# APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
32
-
# COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM
33
-
# “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
34
-
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35
-
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE
36
-
# RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
37
-
# SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
38
-
# NECESSARY SERVICING, REPAIR OR CORRECTION.
40
-
# Limitation of Liability.
42
-
# IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
43
-
# WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO
44
-
# MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE
45
-
# LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
46
-
# INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
47
-
# INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
48
-
# DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
49
-
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
50
-
# WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS
51
-
# BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
55
-
# * The ssh access has to be configured under the host alias 'remarkable'
56
-
# (or another alias specified in the env variable REMARKABLE_HOST),
57
-
# e.g. by putting the following in .ssh/config :
59
-
# | Hostname 10.11.99.1
63
-
# (and setup ssh public key authentication to avoid typing your passwd)
65
-
# * Beyond core utilities (date, basename,...), the following software
66
-
# has to be installed on the host computer:
69
-
# This is where ssh will try to copy the files associated with the document
70
-
REMARKABLE_HOST=${REMARKABLE_HOST:-remarkable2.vpn}
71
-
REMARKABLE_XOCHITL_DIR=${REMARKABLE_XOCHITL_DIR:-.local/share/remarkable/xochitl/}
72
-
TARGET_DIR="${REMARKABLE_HOST}:${REMARKABLE_XOCHITL_DIR}"
74
-
# Check if we have something to do
75
-
if [ $# -lt 1 ]; then
76
-
echo "Transfer PDF or EPUB document(s) to a reMarkable tablet."
77
-
echo "See comments/documentation at start of script."
78
-
echo "usage: $(basename $0) [ -r ] path-to-file [path-to-file]..."
82
-
RESTART_XOCHITL_DEFAULT=${RESTART_XOCHITL_DEFAULT:-0}
83
-
RESTART_XOCHITL=${RESTART_XOCHITL_DEFAULT}
84
-
if [ "$1" = "-r" ] ; then
86
-
if [ $RESTART_XOCHITL_DEFAULT -eq 0 ] ; then
94
-
# Create directory where we prepare the files as the reMarkable expects them
97
-
# Loop over the command line arguments,
98
-
# which we expect are paths to the files to be transferred
99
-
for filename in "$@" ; do
101
-
# reMarkable documents appear to be identified by universally unique IDs (UUID),
102
-
# so we generate one for the document at hand
103
-
uuid=$(uuidgen | tr '[:upper:]' '[:lower:]')
105
-
extension="${filename##*.}"
107
-
# Copy the file itself
108
-
cp -- "$filename" "${tmpdir}/${uuid}.${extension}"
111
-
# The lastModified item appears to contain the date in milliseconds since Epoch
112
-
cat <<EOF >>${tmpdir}/${uuid}.metadata
115
-
"lastModified": "$(date +%s)000",
116
-
"metadatamodified": false,
121
-
"type": "DocumentType",
123
-
"visibleName": "$(basename -- "$filename" ".$extension")"
127
-
if [ "$extension" = "pdf" ]; then
128
-
# Add content information
129
-
cat <<EOF >${tmpdir}/${uuid}.content
135
-
"lastOpenedPage": 0,
154
-
# Add cache directory
155
-
mkdir ${tmpdir}/${uuid}.cache
157
-
# Add highlights directory
158
-
mkdir ${tmpdir}/${uuid}.highlights
160
-
# Add thumbnails directory
161
-
mkdir ${tmpdir}/${uuid}.thumbnails
163
-
elif [ "$extension" = "epub" ]; then
165
-
# Add content information
166
-
cat <<EOF >${tmpdir}/${uuid}.content
173
-
echo "Unknown extension: $extension, skipping $filename"
179
-
echo "Transferring $filename as $uuid"
180
-
scp -r ${tmpdir}/* "${TARGET_DIR}"
186
-
if [ $RESTART_XOCHITL -eq 1 ] ; then
187
-
echo "Restarting Xochitl..."
188
-
ssh ${REMARKABLE_HOST} "systemctl restart xochitl"