Tool to monitor ebook device connection and sync remote (webdav) folder to ebook... master
authorRoman Bazalevskiy <rvb@rvb.name>
Mon, 6 Apr 2015 21:23:55 +0000 (00:23 +0300)
committerRoman Bazalevskiy <rvb@rvb.name>
Mon, 6 Apr 2015 21:23:55 +0000 (00:23 +0300)
ebook.conf [new file with mode: 0644]
mount-gvfs [new file with mode: 0755]
mount-watcher [new file with mode: 0755]
sync-ebook [new file with mode: 0755]

diff --git a/ebook.conf b/ebook.conf
new file mode 100644 (file)
index 0000000..a3bff68
--- /dev/null
@@ -0,0 +1,7 @@
+USER=user
+PASSWD=mystrongpasswd
+DAVFS=davs://server/path
+EBOOK=/media/rvb/EbookLabel
+SRCDIR="Books"
+DSTDIR="My Books"
+TEMPLATE="*.fb2,*.fb2.zip"
diff --git a/mount-gvfs b/mount-gvfs
new file mode 100755 (executable)
index 0000000..58a68a9
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/expect
+
+set timeout 10
+spawn gvfs-mount [lindex $argv 0]
+expect "User:"
+send "[lindex $argv 1]\r"
+expect "Password:"
+send "[lindex $argv 2]\r"
+expect eof
+
diff --git a/mount-watcher b/mount-watcher
new file mode 100755 (executable)
index 0000000..de64e73
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+. ~/.config/ebook.conf
+
+udisksctl monitor | grep --line-buffered MountPoints | while read -r line
+do
+
+  MOUNTED=`echo $line | awk '{ print $2 }'`
+  if [ "$MOUNTED" == "$EBOOK" ];
+  then
+    sleep 5
+    sync-ebook
+  fi
+
+done
diff --git a/sync-ebook b/sync-ebook
new file mode 100755 (executable)
index 0000000..4e9a665
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+. ~/.config/ebook.conf
+
+mount-gvfs $DAVFS $USER $PASSWD
+
+MOUNT=$XDG_RUNTIME_DIR/gvfs/
+DIR=`gvfs-info $DAVFS | grep "id::filesystem" | awk '{ print $2; }'`
+
+if [ "$DIR" != "" ]
+then
+
+MOUNT=$XDG_RUNTIME_DIR/gvfs/$DIR
+
+if [ -d $EBOOK ]
+then
+
+rsync -ru --include=$TEMPLATE --exclude=.* "$MOUNT/$SRCDIR/" "$EBOOK/$DSTDIR/"
+
+fi
+
+fi
\ No newline at end of file