#!/bin/bash # Define required programs and libraries program_list=("ifuse" "ldconfig" "rsync") library_list=("libimobiledevice") sync_folder="$HOME/iPhone" sync_mount="${sync_folder}/.mnt" sync_data="${sync_folder}/data" # Check if required programs are installed for program in "${program_list[@]}"; do if command -v "${program}" >/dev/null 2>&1 then echo "OK, ${program} exists." else echo "Error: ${program} is missing. Please install: ${program_list[*]}" exit 1 fi done # iteration thru list of libraries for library in "${library_list[@]}"; do if ldconfig -p | grep ${library} >/dev/null 2>&1 then echo "OK, ${library} exists." else echo "Error: Library ${library} is missing. Please install: ${library_list[*]}" exit 2 fi done # Clear older dead mounts if they block the directory if [ -d "${sync_mount}" ]; then fusermount -u "${sync_mount}" >/dev/null 2>&1 || umount -l "${sync_mount}" >/dev/null 2>&1 rmdir "${sync_mount}" >/dev/null 2>&1 fi echo "Create the folder ${sync_mount} ..." if mkdir -p ${sync_mount} >/dev/null 2>&1 then echo "done." else echo "Folder ${sync_mount} already exists." fi echo "Mount the iPhone into that folder using ifuse ..." if ifuse ${sync_mount} then echo "ok." else echo "did not work. Check your connection to the iPhone. Check PIN on the iPhone." exit 3 fi # Display storage capacity of the iPhone echo -e "\n--- IPHONE STORAGE USAGE ---" df -h "${sync_mount}" echo -e "----------------------------\n" echo "RSYNC the iPhone ..." FROM="${sync_mount}/" TO="${sync_data}/" while true; do echo "** Synchronization from ${FROM} to ${TO} **" read -n 1 -p "Action: (s)ync & delete / (n)ormal sync / (m)ount only & exit / (c)ancel? " response # read -n 1 -p"Action: Sync iPhone and delete old files (y)es/(m)ount only/(n)o/(c)ancel? " response echo case ${response} in [Nn]* ) mkdir -p "${sync_data}" rsync -avP "${FROM}" "${TO}" break ;; [Ss]* ) mkdir -p "${sync_data}" rsync -avP --delete "${FROM}" "${TO}" break ;; [Mm]* ) echo "iPhone remains mounted at ${sync_mount}. Remember to unmount manually later!" exit 0 ;; [Cc]* ) echo "Synchronization skipped by user." break ;; * ) echo "Invalid selection. Please choose y, n, m, or c." ;; esac done echo "Unmounting iPhone..." if fusermount -u "${sync_mount}" 2>/dev/null || umount "${sync_mount}" 2>/dev/null; then echo "Successfully unmounted." rmdir "${sync_mount}" else echo "WARNING: Unmount failed. A process might still be accessing the mount directory." fi echo "Process finished."