#
# FUNKTION: Datei für die Löschung der EXIF-Daten der Bilder.
#
INC_NAME_EXIF='inc_tools_exif_data.txt'
GALLERY_MESSAGE_PLEASE_WAIT=${GALLERY_MESSAGE_PLEASE_WAIT:='PLEASE WAIT .....'}

# Einträge des Menü's
TOOLS_MENUE_EXIF_DATA_HEAD_LINE_A=${TOOLS_MENUE_EXIF_DATA_HEAD_LINE_A:='EMPTY'}
TOOLS_MENUE_VALUE_BREAK=${TOOLS_MENUE_VALUE_BREAK:='EMPTY'}
TOOLS_MENUE_PROGRAM_STOP=${TOOLS_MENUE_PROGRAM_STOP:='EMPTY'}
TOOLS_MENUE_EXIF_DATA_VALUE_1=${TOOLS_MENUE_EXIF_DATA_VALUE_1:='EMPTY'}
TOOLS_MENUE_EXIF_DATA_FEED_LINE_A=${TOOLS_MENUE_EXIF_DATA_FEED_LINE_A:='EMPTY'}
TOOLS_MENUE_EXIF_DATA_FEED_LINE_B=${TOOLS_MENUE_EXIF_DATA_FEED_LINE_B:='EMPTY'}
TOOLS_MENUE_EXIF_DATA_FEED_LINE_C=${TOOLS_MENUE_EXIF_DATA_FEED_LINE_C:='EMPTY'}
PICTURE_DIRECTORY_PATH=${PICTURE_DIRECTORY_PATH:='EMPTY'}
THUMBNAILS_DIRECTORY_PATH=${THUMBNAILS_DIRECTORY_PATH:='EMPTY'}
CSS_DIRECTORY=${CSS_DIRECTORY:='EMPTY'}
EXTRA_DIRECTORY=${EXTRA_DIRECTORY:='EMPTY'}
if [ "${PICTURE_DIRECTORY_PATH}" = 'EMPTY' ] || [ "${THUMBNAILS_DIRECTORY_PATH}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 1-1 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
exit 1
fi
if [ "${EXTRA_DIRECTORY}" = 'EMPTY' ] || [ "${CSS_DIRECTORY}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 1-2 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
exit 1
fi

clear 2> /dev/null
echo -e "\n\t\t${TOOLS_MENUE_EXIF_DATA_HEAD_LINE_A}\n\n"
echo -e "  ${TOOLS_MENUE_VALUE_BREAK} ... (0)"
echo -e "  ${TOOLS_MENUE_EXIF_DATA_VALUE_1} ... (1)"
echo ""
echo -n "${TOOLS_MENUE_EXIF_DATA_FEED_LINE_A} "

# Verzeichnisse überprüfen
if [ ! -d ${PICTURE_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 2-1 \nDIRECTORY: »${PICTURE_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
exit 1
fi
if [ ! -d ${THUMBNAILS_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 2-2 \nDIRECTORY: »${THUMBNAILS_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
exit 1
fi
CSS_DIRECTORY_PATH="../${CSS_DIRECTORY}"
if [ ! -d ${CSS_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 2-3 \nDIRECTORY: »${CSS_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
exit 1
fi
EXTRA_DIRECTORY_PATH="../${EXTRA_DIRECTORY}"
if [ ! -d ${EXTRA_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 2-4 \nDIRECTORY: »${EXTRA_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
exit 1
fi

# Benutzereingaben entgegennehmen und überprüfen
START=${START:+0}
STOP=${STOP:+3}
STEP=${STEP:+1}
Q=${Q:+$START}
while [ $Q -lt $STOP ]
do
Q=$[$Q+$STEP]
read EXIF_DATA_MENUE_VALUE
  if [ $(echo "${EXIF_DATA_MENUE_VALUE}" | grep -c "^[1]$") -eq 1 ]
  then
    clear 2> /dev/null
    echo -e "\n\t\t${TOOLS_MENUE_EXIF_DATA_HEAD_LINE_A}\n"
    if [ ${EXIF_DATA_MENUE_VALUE} -eq 1 ]
    then
    echo -e "${GALLERY_MESSAGE_PLEASE_WAIT}\n"
    # Exif-Daten aus den Bildern entfernen
    find ${PICTURE_DIRECTORY_PATH} -maxdepth 1 -type f -iregex "^.*\(\.jpg\|\.jpeg\|\.png\)$" -exec exiv2 -da {} \; 2> /dev/null
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 3-1 \nDIRECTORY: »${PICTURE_DIRECTORY_PATH}« \nFILE: CAN NOT DELETE EXIF-DATA \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
      exit 1
      fi
    # Exif-Daten aus den Thumbnails entfernen
    find ${THUMBNAILS_DIRECTORY_PATH} -maxdepth 1 -type f -iregex "^.*\(\.jpg\|\.jpeg\|\.png\)$" -exec exiv2 -da {} \; 2> /dev/null
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 3-2 \nDIRECTORY: »${THUMBNAILS_DIRECTORY_PATH}« \nFILE: CAN NOT DELETE EXIF-DATA \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
      exit 1
      fi
    find ${CSS_DIRECTORY_PATH} -maxdepth 1 -type f -iregex "^.*\(\.jpg\|\.jpeg\|\.png\|\.gif\)$" -exec exiv2 -da {} \; 2> /dev/null
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 3-3 \nDIRECTORY: »${CSS_DIRECTORY_PATH}« \nFILE: CAN NOT DELETE EXIF-DATA \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
      exit 1
      fi
    find ${EXTRA_DIRECTORY_PATH} -maxdepth 2 -type f -iregex "^.*\(\.jpg\|\.jpeg\|\.png\|\.gif\)$" -exec exiv2 -da {} \; 2> /dev/null
      if [ $? -ge 1 ]
      then
      echo -e "\nERROR-CODE: GALLERY TOOLS EXIF-DATA 3-4 \nDIRECTORY: »${EXTRA_DIRECTORY_PATH}« \nFILE: CAN NOT DELETE EXIF-DATA \nSCRIPT-NAME: ${INC_NAME_EXIF}\n"
      exit 1
      fi
      echo -e "  ${TOOLS_MENUE_EXIF_DATA_FEED_LINE_B}\n"
    fi
  Q=${Q:+$STOP}
  elif [ $(echo "${EXIF_DATA_MENUE_VALUE}" | grep -c "^[0]$") -eq 1 ] || [ "${EXIF_DATA_MENUE_VALUE}" = '' ]
  then
  echo -e "\n${TOOLS_MENUE_PROGRAM_STOP}\n"
  exit 1
  else
  echo "${TOOLS_MENUE_EXIF_DATA_FEED_LINE_C}"
    if [ $Q -lt $STOP ]
    then
    echo -n "${TOOLS_MENUE_EXIF_DATA_FEED_LINE_A} "
    fi
    if [ ${Q} -ge ${STOP} ]
    then
    echo -e "\n${TOOLS_MENUE_PROGRAM_STOP}\n"
    exit 1
    fi
  fi
done
