#!/bin/sh -e

##########################################################################
#   Title:
#       Optional, defaults to the name of the script sans extention
#
#   Section:
#       8
#
#   Synopsis:
#       
#   Description:
#       Search directories for files owned by a user and chown to
#       a new user.
#       
#   Arguments:
#       
#   Returns:
#
#   Examples:
#
#   Files:
#
#   Environment:
#
#   See also:
#       
#   History:
#   Date        Name        Modification
#   2024-09-23  Jason Bacon Add man page template and usage
##########################################################################

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 '{}' +
