#!/bin/sh -e

##########################################################################
#   Script description:
#       Search directories for files owned by a user and chown to
#       a new user.
#       
#   History:
#   Date        Name        Modification
#   2019-02-05  Jason Bacon - UITS/CEAS - Systems Manager,EMS 974Begin
##########################################################################

usage()
{
    printf "Usage: $0 [--silent] old-username|uid new-username|uid directory [directory ...]\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# -lt 3 ]; then
    usage
fi

if [ $1 = --silent ]; then
    shift
    verbose=""
else
    verbose=-v
fi

old_user=$1
new_user=$2
shift
shift

dirs="$@"

# BSD and GNU find allow a name or id with -user and -group.
# GNU find requires a UID with -uid or -gid.  Use -user and -group to
# be flexible and portable.
find $dirs -fstype nfs -prune -o \
    -user $old_user -exec chown $verbose -h $new_user '{}' +
