NanoGal/bin/remove_gps_datas.sh
2024-08-23 16:13:41 +02:00

80 lines
2.4 KiB
Bash

#!/bin/bash
deleteGPSData() {
local directory=$1
local overwrite_param=$2
find "$directory" -type f | while IFS= read -r line; do
echo "Processing file '$line'"
exiftool -gps:all= "$line" "$overwrite_param"
done
}
if ! [ -x "$(command -v exiftool)" ]; then
echo 'Error: exiftool is not installed.' >&2
echo 'Install exiftool before. See your distro documentation.' >&2
exit 1
fi
echo '-------------------------------'
echo 'Success: exiftool is installed.'
echo '-------------------------------'
echo ''
# Ask for directory scan, if empty use ../public/photos
default_directory="../public/photos"
read -p "Please specify a subdirectory within $default_directory or press Enter to use the default: " user_directory
echo ''
if [ -z "$user_directory" ]; then
target_directory="$default_directory"
else
target_directory="$default_directory/$user_directory"
if [[ ! -d "$target_directory" ]] || [[ "$target_directory" != "$default_directory"* ]]; then
echo "Error: The directory you specified is invalid or outside of $default_directory."
exit 1
fi
fi
while true; do
echo ''
read -p "Are you sure you want to delete all GPS data from the files in $target_directory?
This operation is irreversible.
Do you want to continue ? [Y/N] " yesno
echo ''
case $yesno in
[Yy]*)
echo "You answered yes"
# Ask user for overwrite original file
echo ''
read -p "Do you want to overwrite the original files? This cannot be undone. [Y/N] " overwrite
echo ''
case $overwrite in
[Yy]*)
overwrite_param="-overwrite_original"
echo "You chose to overwrite the original files."
;;
[Nn]*)
overwrite_param=""
echo "You chose not to overwrite the original files."
;;
*)
echo "Invalid choice, defaulting to no overwrite."
overwrite_param=""
;;
esac
deleteGPSData "$target_directory" "$overwrite_param"
exit
;;
[Nn]*)
echo "You answered no, exiting"
exit
;;
*)
echo "Answer either Y/y (Yes) or N/n (No)!"
;;
esac
done