new fortune, new script for ebook synching.
[feisty_meow.git] / scripts / files / synch_to_mtp_device.sh
1 #!/bin/bash
2
3 sourcedir="$1"; shift
4 targetdir="$1"; shift
5
6 # where we will look for mtp devices.
7 mtp_base_path="/run/user/$UID/gvfs/mtp\:host\="
8
9 if [ -z "$sourcedir" -o -z "$targetdir" ]; then
10   echo "This script needs source and target directory names that can be synched"
11   echo "between the computer's file system and a USB drive mounted with the mtp"
12   echo "protocol.  The folder on the USB drive should include the entire path except"
13   echo "for the device mount location.  For example:"
14   echo "    $(basename $0) ebooks \"/Internal\ Storage/My\ Files/ebooks\""
15   exit 1
16 fi
17
18 # the mtp part will flux.  if there is more than one device mounted, this will hose up.
19 #checking for more than one device there:
20 mtpdevices=("$mtp_base_path"*)
21 if [ ${#mtpdevices[@]} -ne 1 ]; then
22   echo "There is more than one MTP device mounted.  This script requires exactly one"
23   echo "MTP device mounted at a time.  Sorry."
24   exit 1
25 elif [ ! -d "${#mtpdevices[@]}" ]; then
26   echo "The MTP device does not seem to be mounted currently.  The path did not"
27   echo "expand properly."   
28   exit 1
29 fi
30
31 rsync -rv --exclude *.git --exclude *.svn "$sourcedir" "${mtpdevices[0]}/$targetdir"
32