#!/bin/sh

# shell script to find all mixed case *.fd and *enc.def files
# Offers to delete them if lowercase version exists in same diretory,
# otherwise to rename them to lowercase.

# Asks for every file whether to do the action (y/n).
# Could be made  to do all files, but I don't want to be responsible for
# distributing a find script that executes rm in any but the safest fashion.

# However if you want to apply this to a large directory you will want
# to disable the questions, in that case uncomment the second line
# below, to set force=true.

force=false
force=true

export force


# Tries to assume no fancy shell or perl or anything else.
# Does assume tr is available though.
 
find "$@" \( -name '[A-Z]*.fd' -o -name '[A-Z]*enc.def' \) -exec sh -c '
  B=`echo $1 | sed "s@.*/@@"`
  D=`echo $1 | sed "s@/[^/]*\\$@@"`
  L=`echo $B | tr "[A-Z]" "[a-z]"`
  if test -f $D/$L; then
    $force || {
      echo "$D/$L exists, delete $D/$B (y/n) ?"
      read ans
      test x$ans = xy
    } && rm $D/$B
  else
    $force || {
      echo "rename $D/$B to $D/$L (y/n) ?"
      read ans
      test x$ans = xy
    } && mv $D/$B $D/$L
  fi
' sh '{}' \;
