#!/usr/bin/env 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" ]; then echo "Sorting pictures..." phockup "$directory_temp/Pictures" "$destination/" -m else echo "Pictures 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