aboutsummaryrefslogtreecommitdiff
path: root/copy-annotations-from-kobo
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2023-01-01 15:33:19 -0300
committerSilvio Rhatto <rhatto@riseup.net>2023-01-01 15:33:19 -0300
commitd2cf9cb06f3ee4d50071b6e56f28a50f4133c166 (patch)
treeb7e3e769d3b2635efef56de316131a2edfce4205 /copy-annotations-from-kobo
parent260b8fc6339dbc3a7895278e4893198c480739ab (diff)
downloadscripts-d2cf9cb06f3ee4d50071b6e56f28a50f4133c166.tar.gz
scripts-d2cf9cb06f3ee4d50071b6e56f28a50f4133c166.tar.bz2
Feat: adds copy-annotations-from-kobo
Diffstat (limited to 'copy-annotations-from-kobo')
-rwxr-xr-xcopy-annotations-from-kobo42
1 files changed, 42 insertions, 0 deletions
diff --git a/copy-annotations-from-kobo b/copy-annotations-from-kobo
new file mode 100755
index 0000000..40ad9e8
--- /dev/null
+++ b/copy-annotations-from-kobo
@@ -0,0 +1,42 @@
+#!/bin/bash
+#
+# A mini-wrapper to copu a remote kobo annotation into a local one.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+BASEFOLDER="$HOME/data/doc"
+REMOTE_BASE="/mnt/sd"
+REMOTE="kobo"
+PATTERN="$1"
+
+# Thanks https://serverfault.com/a/764403
+# https://serverfault.com/questions/36421/stop-ssh-login-from-printing-motd-from-the-client#38160
+function silentSsh {
+ local connectionString="$1"
+ local commands="$2"
+ if [ -z "$commands" ]; then
+ commands=`cat`
+ fi
+ ssh -T $connectionString "$commands"
+}
+
+# Check
+if [ -z "$PATTERN" ]; then
+ echo "usage: $BASENAME <pattern>"
+ exit 1
+fi
+
+# Dispatch
+show --search "$PATTERN" | while read item; do
+ #sdr="`echo $item | sed -e 's/\.pdf$//' -e 's/\.epub$//' -e 's/\.djvuf$//'`.sdr"
+ basename="`echo $item | sed -e 's/\.[^.]*$//'`"
+ extension="$(echo $item | sed -e "s|$basename.||")"
+ sdr="$basename.sdr"
+
+ mkdir -p "$BASEFOLDER/$sdr"
+ touch "$BASEFOLDER/$sdr/metadata.$extension.lua"
+ silentSsh kobo >"$BASEFOLDER/$sdr/metadata.$extension.lua" <<EOF
+ cat "$REMOTE_BASE/$sdr/metadata.$extension.lua"
+EOF
+done