blob: d2de65d8b614e17175d93a22345bc4bdada44ef2 (
plain) (
blame)
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
63
64
|
#!/bin/bash
# variables
phone_remote=phone
phone_ip=$(grep -A4 "$phone_remote" "$(rclone config file | tail -1)" | awk '/host/ {print $3}')
destination="/mnt/pictures/personal"
if [ ! -d "$destination" ]; then
echo "Destination $destination does not exist."
exit 1
fi
# if ping phone
if ping -c 1 "$phone_ip" &>/dev/null; then
echo "Phone reachable, mounting remote"
directory_temp="$(mktemp -d)"
rclone mount "$phone_remote": "$directory_temp" --daemon
cd "$directory_temp" || exit
if [ -d "$directory_temp/DCIM/Camera" ]; then
echo "Sorting pictures..."
phockup "$directory_temp/DCIM/Camera" "$destination/" -m
else
echo "DCIM Camera directory does not exist, skipping."
fi
if [ -d "$directory_temp/Pictures/Whatsapp" ]; then
echo "Sorting WhatsApp..."
find "$directory_temp/Pictures/Whatsapp" -name '.nomedia*' -delete
phockup "$directory_temp/Pictures/Whatsapp" "$destination/" -m
else
echo "Whatsapp directory does not exist, skipping."
fi
if [ -d "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media" ]; then
if [ -d "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Images" ]; then
echo "Sorting WhatsApp Pictures..."
find "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Images" -name '.nomedia*' -delete
phockup "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Images" "$destination/" -m
fi
if [ -d "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Video" ]; then
echo "Sorting WhatsApp Videos..."
find "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Video" -name '.nomedia*' -delete
phockup "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Video" "$destination/" -m
fi
find "$directory_temp/Android/media/com.whatsapp/WhatsApp/Media" -maxdepth 2 -type d -not -path "*/\.*" -empty -delete -print 2>/dev/null
fi
if [ -d "$directory_temp/Pictures/Screenshots" ]; then
echo "Sorting screenshots..."
find "$directory_temp/Pictures/Screenshots" -type f -exec mv '{}' "$destination/screenshots/" -vi \;
else
echo "Pictures Screenshots directory does not exist, skipping."
fi
echo "Tidying up..."
find "$destination" -type f -iname 'thumbs.db' -delete -print
find "$destination" -type f -name '.nomedia*' -delete -print
rm -rf "$directory_temp/DCIM/.thumbnails" "$directory_temp/Pictures/.thumbnails"
find "$directory_temp" -maxdepth 2 -type d -not -path "*/\.*" -empty -delete -print 2>/dev/null
echo "Unmounting storage..."
sleep 2s
umount "$directory_temp" || fusermount -uz "$directory_temp"
echo "Deduplicating photos..."
jdupes "$destination" -r
find "/tmp/tmp.*" -maxdepth 1 -type d -not -path "*/\.*" -empty -delete -print 2>/dev/null
else
echo "Phone not reachable via ping, exiting" && exit 1
fi
|