#!/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/photos/" -m else echo "DCIM Camera directory does not exist, skipping." 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..." 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