copy-to-remarkable 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/sh
  2. # Transfer PDF file(s) to a reMarkable
  3. # Adrian Daerr 2017/2018 - public domain
  4. #
  5. # - The files will appear in reMarkable's top-level "My Files" directory,
  6. # - After finishing all transfers, you have to restart the xochitl
  7. # service on the tablet in order to force a scan of its document
  8. # directory ${xochitldir} (so that you see the newly transferred
  9. # files), e.g. by sending the tablet the following command:
  10. # ssh remarkable systemctl restart xochitl
  11. #
  12. # Disclaimer and liability limitation:
  13. # [see also all-caps text borrowed from GPL below]
  14. # - This is a dirty hack based on superficial reverse-engineering.
  15. # - Expect this script to break at any time, especially upon a
  16. # reMarkable system upgrade
  17. # - I am not responsible for any damage caused by this script,
  18. # including (but not limited to) bricking your reMarkable, erasing
  19. # your documents etc. YOU ARE USING THIS SOFTWARE ON YOUR OWN RISK.
  20. #
  21. # Disclaimer of Warranty.
  22. #
  23. # THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
  24. # APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
  25. # COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM
  26. # “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
  27. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE
  29. # RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
  30. # SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
  31. # NECESSARY SERVICING, REPAIR OR CORRECTION.
  32. #
  33. # Limitation of Liability.
  34. #
  35. # IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
  36. # WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO
  37. # MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE
  38. # LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
  39. # INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  40. # INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
  41. # DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
  42. # YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
  43. # WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS
  44. # BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  45. #
  46. # Prerequisites:
  47. #
  48. # * The ssh access has to be configured under the host alias 'remarkable',
  49. # e.g. by putting the following in .ssh/config :
  50. # | host remarkable
  51. # | Hostname 10.11.99.1
  52. # | User root
  53. # | ForwardX11 no
  54. # | ForwardAgent no
  55. # See also the variable "xochitldir" below
  56. #
  57. # * Beyond core utilities (date, basename,...), the following software
  58. # has to be installed on the host computer:
  59. # - uuidgen
  60. # - imagemagick (or graphicsmagick)
  61. # This is where ssh will try to copy the files associated with the document
  62. xochitldir=remarkable:.local/share/remarkable/xochitl/
  63. # Check if we have something to do
  64. if [ $# -lt 1 ]; then
  65. echo "Transfer PDF document to a reMarkable tablet"
  66. echo "usage: $(basename $0) path-to-pdf-file [path-to-pdf-file]..."
  67. exit 1
  68. fi
  69. # Create directory where we prepare the files as the reMarkable expects them
  70. tmpdir=$(mktemp -d)
  71. # Loop over the command line arguments,
  72. # which we expect are paths to the PDF files to be transfered
  73. for pdfname in $@ ; do
  74. # reMarkable documents appear to be identified by universally unique IDs (UUID),
  75. # so we generate one for the document at hand
  76. uuid=$(uuidgen)
  77. # Copy the PDF file itself
  78. cp $pdfname ${tmpdir}/${uuid}.pdf
  79. # Add metadata
  80. # The lastModified item appears to contain the date in milliseconds since Epoch
  81. cat <<EOF >>${tmpdir}/${uuid}.metadata
  82. {
  83. "deleted": false,
  84. "lastModified": "$(date +%s)000",
  85. "metadatamodified": false,
  86. "modified": false,
  87. "parent": "",
  88. "pinned": false,
  89. "synced": false,
  90. "type": "DocumentType",
  91. "version": 1,
  92. "visibleName": "$(basename $pdfname .pdf)"
  93. }
  94. EOF
  95. # Add content information
  96. cat <<EOF >${tmpdir}/${uuid}.content
  97. {
  98. "extraMetadata": {
  99. },
  100. "fileType": "pdf",
  101. "fontName": "",
  102. "lastOpenedPage": 0,
  103. "lineHeight": -1,
  104. "margins": 100,
  105. "pageCount": 1,
  106. "textScale": 1,
  107. "transform": {
  108. "m11": 1,
  109. "m12": 1,
  110. "m13": 1,
  111. "m21": 1,
  112. "m22": 1,
  113. "m23": 1,
  114. "m31": 1,
  115. "m32": 1,
  116. "m33": 1
  117. }
  118. }
  119. EOF
  120. # Add cache directory
  121. mkdir ${tmpdir}/${uuid}.cache
  122. # Add highlights directory
  123. mkdir ${tmpdir}/${uuid}.highlights
  124. # Add thumbnails directory
  125. mkdir ${tmpdir}/${uuid}.thumbnails
  126. # Generate preview thumbnail for the first page
  127. # Different sizes were found (possibly depending on whether created by
  128. # the reMarkable itself or some synchronization app?): 280x374 or
  129. # 362x512 pixels. In any case the thumbnails appear to be baseline
  130. # jpeg images - JFIF standard 1.01, resolution (DPI), density 228x228
  131. # or 72x72, segment length 16, precision 8, frames 3
  132. #
  133. # The following will look nice only for PDFs that are higher than about 32mm.
  134. convert -density 300 $pdfname'[0]' -colorspace Gray -separate -average -shave 5%x5% -resize 280x374 ${tmpdir}/${uuid}.thumbnails/0.jpg
  135. # Transfer files
  136. echo "Transferring $pdfname$ as $uuid$"
  137. scp -r ${tmpdir}/* ${xochitldir}
  138. rm -rf ${tmpdir}/*
  139. done
  140. rm -rf ${tmpdir}
  141. ssh remarkable "systemctl restart xochitl"