forked from acabal/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nook-sync
executable file
·41 lines (33 loc) · 1.27 KB
/
nook-sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
usage(){
fmt <<EOF
DESCRIPTION
Sync ebooks in ~/documents/ebooks/ to an attached Nook device, then eject it.
USAGE
nook-sync [-d,--dry-run]
-d,--dry-run Simulate the sync and don't eject the device aftewards.
EOF
exit
}
die(){ printf "Error: ${1}\n" 1>&2; exit 1; }
require(){ command -v $1 > /dev/null 2>&1 || { suggestion=""; if [ ! -z "$2" ]; then suggestion=" $2"; fi; die "$1 is not installed.${suggestion}"; } }
if [ $# -eq 1 ]; then if [ "$1" = "--help" -o "$1" = "-h" ]; then usage; fi fi
#End boilerplate
ebooksRoot="${HOME}/documents/ebooks/" #Trailing slash required
nookRoot="/media/NOOK"
require "rsync" "Try: apt-get install rsync"
if [ ! -d "${nookRoot}" ]; then
die "Nook not mounted."
fi
if [ $# -eq 1 ]; then
echo "Starting rsync dry run ..."
rsync -rlcvz --itemize-changes --dry-run --include="*/" --exclude="*.original.epub" --exclude="*.pdf" --include="*.epub" --exclude="*" --delete "${ebooksRoot}" "${nookRoot}/My Files/Books/"
else
echo "Starting rsync ..."
rsync -rlcvz --itemize-changes --include="*/" --exclude="*.original.epub" --exclude="*.pdf" --include="*.epub" --exclude="*" --delete "${ebooksRoot}" "${nookRoot}/My Files/Books/"
if [ $? -eq 0 ] ; then
echo "Ejecting Nook ..."
sudo eject "${nookRoot}"
echo "Done."
fi
fi;