Last active
February 4, 2022 14:23
Revisions
-
Utopiah renamed this gist
Dec 6, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Utopiah created this gist
Dec 6, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ # script to (one-way) synchronize a NextCloud directory to a reMarkable device # use it manually as ssh remarkable /home/root/bin/syncNC or via Cron or systemd # # configure https://nextcloud.domain.tld/remote.php/dav/files/username/ with your own NextCloud Dav URL # add your username, password and path to /opt/etc/davfs2/secrets # install mount.davfs via opkg install davfs2 # make the required directories e.g ~/nextcloudSync2 /media/nextcloudselfhosted/ on the reMarkable # user reMarkable2_sync/ on your NextCould or change its location here # do a symlink between ~/xochitl-data/ and ~/.local/share/remarkable/xochitl/ # helpers adapted from https://gist.github.com/Utopiah/e2d5c944bbd632e3ae0530e602977f45 addPdfWithMetadata(){ cp "$1" ~/xochitl-data && echo "{'parent':'','type':'DocumentType','visibleName':'$1'}" | sed s/\'/\"/g > ~/xochitl-data/`echo $1 | sed "s/.pdf//"`.metadata; echo '{ "fileType": "pdf" }' > ~/xochitl-data/`echo $1 | sed "s/.pdf//"`.content; echo "$1" >> /tmp/newfilesaddedduringsync } addEpubWithMetadata(){ cp "$1" ~/xochitl-data && echo "{'parent':'','type':'DocumentType','visibleName':'$1'}" | sed s/\'/\"/g > ~/xochitl-data/`echo $1 | sed "s/.epub//"`.metadata; echo '{ "fileType": "epub" }' > ~/xochitl-data/`echo $1 | sed "s/.epub//"`.content; echo "$1" >> /tmp/newfilesaddedduringsync } addWithMetadataIfNew(){ if [ -f ~/xochitl-data/"$1" ]; then echo "File already added, skipping" else echo "File is new, adding" echo "$1" | grep .epub && addEpubWithMetadata "$1" echo "$1" | grep .pdf && addPdfWithMetadata "$1" fi } syncFromNextcloudSelfHosted(){ /opt/sbin/mount.davfs https://nextcloud.domain.tld/remote.php/dav/files/username/ /media/nextcloudselfhosted/ rsync /media/nextcloudselfhosted/reMarkable2_sync/ ~/nextcloudSync2/ -r # note that this is tricky for file modification, might add -c or -a but requires the endpoint to show the update pushd $PWD cd ~/nextcloudSync2/ rm -f /tmp/newfilesaddedduringsync for F in *pdf *epub; do addWithMetadataIfNew "$F"; done popd if [ -f ~/nextcloudSync2/configuration.txt ]; then if [ -f /tmp/newfilesaddedduringsync ]; then grep "force restart" ~/nextcloudSync2/configuration.txt && systemctl restart xochitl # should have something like force restart xochtil in it, otherwise, do so manually fi fi } syncFromNextcloudSelfHosted