diff options
| -rwxr-xr-x | copy-annotations-from-kobo | 2 | ||||
| -rwxr-xr-x | copy-annotations-to-kobo | 58 | ||||
| -rwxr-xr-x | docshower | 55 | ||||
| -rwxr-xr-x | export-koreader-note | 3 |
4 files changed, 116 insertions, 2 deletions
diff --git a/copy-annotations-from-kobo b/copy-annotations-from-kobo index 3d386c9..f883319 100755 --- a/copy-annotations-from-kobo +++ b/copy-annotations-from-kobo @@ -59,7 +59,7 @@ EOT fi # Update - silentSsh kobo >"$BASEFOLDER/$sdr/metadata.$extension.lua" <<EOF + silentSsh $REMOTE > "$BASEFOLDER/$sdr/metadata.$extension.lua" <<EOF cat "$REMOTE_BASE/$sdr/metadata.$extension.lua" EOF diff --git a/copy-annotations-to-kobo b/copy-annotations-to-kobo new file mode 100755 index 0000000..591fa00 --- /dev/null +++ b/copy-annotations-to-kobo @@ -0,0 +1,58 @@ +#!/bin/bash +# +# A mini-wrapper to copy a remote kobo annotation into a local one. +# + +# Parameters +BASENAME="`basename $0`" +DIRNAME="`dirname $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" + shift + local commands="$*" + if [ -z "$commands" ]; then + commands=`cat` + fi + ssh -T $connectionString "$commands" +} + +# Check +if [ -z "$PATTERN" ]; then + echo "usage: $BASENAME <pattern>" + exit 1 +fi + +# Dispatch +$DIRNAME/docshower --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" + + # Check if local file exists + test -e "$BASEFOLDER/$sdr/metadata.$extension.lua" + + # Skip if local file does not exist + if [ "$?" != "0" ]; then + echo "Skipping $item as it's not available at $BASEFOLDER..." + continue + fi + + echo "Processing $item..." + + # Make sure that the annotation folder exists + silentSsh $REMOTE <<EOT + mkdir -p "$REMOTE_BASE/$sdr" + touch "$REMOTE_BASE/$sdr/metadata.$extension.lua" +EOT + + # Update + scp "$BASEFOLDER/$sdr/metadata.$extension.lua" $REMOTE:"$REMOTE_BASE/$sdr/metadata.$extension.lua" +done @@ -16,9 +16,61 @@ ARG="$1" EXTRA_ARG="$2" DATE="`date +%s`" MAX_AGE="86400" +LOCK="$DOCS/.sync-media.lock" + +# Fatal error +# Adapted from borger +function fatal { + info [fatal] $* + exit 1; +} + +# Create lockfile +# Adapted from borger +function __set_lockfile { + if [ ! -z "$LOCKFILE" ]; then + mkdir -p `dirname $LOCKFILE` + + if ( set -o noclobber; echo "$$" > "$LOCKFILE" ) &> /dev/null; then + trap '__unset_lockfile' INT TERM EXIT + else + fatal "Could not create lockfile $LOCKFILE, exiting" + fi + fi +} + +# Remove lockfile +# Adapted from borger +function __unset_lockfile { + if [ ! -z "$LOCKFILE" ]; then + rm -f $LOCKFILE || echo "Could not remove lockfile $LOCKFILE" + fi +} + +# Check lockfile +# Adapted from borger +function __check_lockfile { + local pid process + + if [ ! -z "$LOCKFILE" ] && [ -f "$LOCKFILE" ]; then + pid="`cat $LOCKFILE`" + process="`ps --no-headers -o comm $pid`" + + if [ "$?" == "0" ] && [ "`ps --no-headers -o comm $$`" == "$process" ]; then + fatal "Another program is running for $LOCKFILE, skipping run" + else + echo "Found old lockfile $LOCKFILE, removing it" + __unset_lockfile + fi + fi +} # Update the filelist function __update_filelist { + # Lock file handling + __check_lockfile + __set_lockfile + echo "Generating new filelist..." # Unnanex if it was erroneously annexed @@ -31,6 +83,9 @@ function __update_filelist { # Stage git add $LIST + + # Unlock file handling + __unlock_repo } # Check diff --git a/export-koreader-note b/export-koreader-note index 307e575..c70a96a 100755 --- a/export-koreader-note +++ b/export-koreader-note @@ -36,7 +36,8 @@ bookmarks = data.bookmarks annotations = data.annotations -- Sort -table.sort(bookmarks, compare) +table.sort(bookmarks, compare) +table.sort(annotations, compare) -- Iterate over bookmarks for key, item in ipairs(bookmarks) do |
