-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsync-smartphone.sh
62 lines (54 loc) · 1.52 KB
/
rsync-smartphone.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
set -x
# rsync photos for Android devices connected in MTP mode
# Check for arguments before running script:
if [ -z "$1" ]; then
echo
echo " $(basename $0) Error: No argument. Enter device name"
echo
echo " Example: $(basename $0) Nexus-5x"
echo
exit 1
fi
DEVICE=$1
HOME="/home/${USER}"
ORIG=$(mount | grep gvfs | awk '{ print $3 }')
DEST="${HOME}/${DEVICE}"
[ ! -d $DEST ] && mkdir -p $DEST
FOUND="$(find $ORIG -maxdepth 1 -name 'mtp*' -type d | wc -l)"
if [ $FOUND -eq 0 ];then
echo "Error: Device not found - File system gvfs not mounted"
exit 10
elif [ $FOUND -gt 1 ];then
echo "Error: Found $FOUND devices"
echo "Disconect one or more devices; you must have only one connected device"
exit 11
elif [ $FOUND -eq 1 ];then
echo "OK: Found $FOUND devices"
fi
cd $ORIG
cd mtp*
CWD=$(pwd)
while read LINE; do
cd "$CWD"
mkdir -p "${DEST}/${LINE}"
cd "$CWD/${LINE}"
pwd
# exclude ".Statuses" WhapsApp directory because rsync returns read errors failed verification
rsync -av --exclude '*.Statuses*' --exclude '.thumbnails' --exclude '.aux' --exclude '*.db.crypt*' . "${DEST}/${LINE}"
done < <(find . -maxdepth 3 -name 'WhatsApp' -o \
-name 'DCIM' -o \
-name 'Music' -o \
-name 'Screenshots' -o \
-name 'Video' -o \
-name 'Movies' -o \
-iname 'bluetooth' -o \
-name 'Download' -o \
-name 'Documents' -o \
-name 'kpx' -o \
-name 'mycar' -o \
-name 'Telegram' -o \
-name 'Threema' -o \
-name 'Pictures' -type d)
# togliere mycar, kpx, Threema e Telegram se non sono installati
# vim: ts=2 sw=2 noet ai nohls