UPD synchronization Iphone-Skript
Dieser Commit ist enthalten in:
+56
-31
@@ -1,35 +1,41 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Define required programs and libraries
|
||||||
program_list=("ifuse" "ldconfig" "rsync")
|
program_list=("ifuse" "ldconfig" "rsync")
|
||||||
library_list=("libimobiledevice")
|
library_list=("libimobiledevice")
|
||||||
|
|
||||||
sync_folder="$HOME/iPhone"
|
sync_folder="$HOME/iPhone"
|
||||||
sync_mount="${sync_folder}/.mnt"
|
sync_mount="${sync_folder}/.mnt"
|
||||||
sync_data="${sync_folder}/data"
|
sync_data="${sync_folder}/data"
|
||||||
|
|
||||||
# iteration thru list of programs
|
# Check if required programs are installed
|
||||||
for program in "${program_list[@]}"
|
for program in "${program_list[@]}"; do
|
||||||
do
|
|
||||||
if command -v "${program}" >/dev/null 2>&1
|
if command -v "${program}" >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
echo "OK, ${program} exists."
|
echo "OK, ${program} exists."
|
||||||
else
|
else
|
||||||
echo "Sorry, ${program} does not exists,"
|
echo "Error: ${program} is missing. Please install: ${program_list[*]}"
|
||||||
echo "you have to install all of these programs first: ${program_list[@]}"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# iteration thru list of libraries
|
# iteration thru list of libraries
|
||||||
for library in "${library_list[@]}"
|
for library in "${library_list[@]}"; do
|
||||||
do
|
|
||||||
if ldconfig -p | grep ${library} >/dev/null 2>&1
|
if ldconfig -p | grep ${library} >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
echo "OK, ${library} exists."
|
echo "OK, ${library} exists."
|
||||||
else
|
else
|
||||||
echo "Sorry, the library ${library} is not installed."
|
echo "Error: Library ${library} is missing. Please install: ${library_list[*]}"
|
||||||
echo "You have to install the libraries first: ${library_list[@]}"
|
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
done
|
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} ..."
|
echo "Create the folder ${sync_mount} ..."
|
||||||
if mkdir -p ${sync_mount} >/dev/null 2>&1
|
if mkdir -p ${sync_mount} >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
@@ -43,36 +49,55 @@ if ifuse ${sync_mount}
|
|||||||
then
|
then
|
||||||
echo "ok."
|
echo "ok."
|
||||||
else
|
else
|
||||||
echo "did not work. Check your connection to the iPhone."
|
echo "did not work. Check your connection to the iPhone. Check PIN on the iPhone."
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "RSYNC the iPhone ..."
|
# Display storage capacity of the iPhone
|
||||||
FROM="$sync_mount"/
|
echo -e "\n--- IPHONE STORAGE USAGE ---"
|
||||||
TO="$sync_data"/
|
df -h "${sync_mount}"
|
||||||
|
echo -e "----------------------------\n"
|
||||||
|
|
||||||
while true
|
echo "RSYNC the iPhone ..."
|
||||||
do
|
FROM="${sync_mount}/"
|
||||||
|
TO="${sync_data}/"
|
||||||
|
|
||||||
|
while true; do
|
||||||
echo "** Synchronization from ${FROM} to ${TO} **"
|
echo "** Synchronization from ${FROM} to ${TO} **"
|
||||||
read -n 1 -p"Sync iPhone and delete old files (y)es/(n)o/(c)ancel? " response
|
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
|
echo
|
||||||
case ${response} in
|
case ${response} in
|
||||||
[Nn]* ) rsync -avP "${FROM}" "${TO}"; break;;
|
[Nn]* )
|
||||||
[YyJj]* ) rsync -avP --delete "${FROM}" "${TO}"; break;;
|
mkdir -p "${sync_data}"
|
||||||
[Cc]* ) break;;
|
rsync -avP "${FROM}" "${TO}"
|
||||||
* ) echo "Please answer yes, no or cancel.";;
|
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
|
esac
|
||||||
done
|
done
|
||||||
echo "Memory usage on the iPhone:" && du -hs ${sync_mount}
|
|
||||||
|
|
||||||
echo "Unmount the iPhone ..."
|
echo "Unmounting iPhone..."
|
||||||
if umount ${sync_mount}
|
if fusermount -u "${sync_mount}" 2>/dev/null || umount "${sync_mount}" 2>/dev/null; then
|
||||||
then
|
echo "Successfully unmounted."
|
||||||
echo "done."
|
rmdir "${sync_mount}"
|
||||||
else
|
else
|
||||||
echo "The umounting procedure did not work."
|
echo "WARNING: Unmount failed. A process might still be accessing the mount directory."
|
||||||
fi
|
fi
|
||||||
echo "Remove temporary mount point ..."
|
|
||||||
rmdir ${sync_mount}
|
echo "Process finished."
|
||||||
echo "done."
|
|
||||||
echo "Disk usage:" && du -hs ${sync_folder}
|
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren