#!/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 particular user and
#       group and change the group ownership.
#       
#   Arguments:
#       
#   Returns:
#
#   Examples:
#
#   Files:
#
#   Environment:
#
#   See also:
#       
#   History:
#   Date        Name        Modification
#   2024-11-11  Jason Bacon Add man page template and usage
##########################################################################

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


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

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

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

user=$1
old_group=$2
new_group=$3
shift
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 $user -group $old_group -exec chgrp $verbose -h $new_group '{}' +
