#!/bin/bash # Original... # Copyright (c) 2000,2004 Matthias S. Benkmann
# You may do everything with this code except misrepresent its origin. # PROVIDED `AS IS' WITH ABSOLUTELY NO WARRANTY OF ANY KIND! # Copyright (C) 2014 Steve Youngs # Handle chgrp options and chgrp'ing outside the user's group list. DAISY_CHAIN="" for p in $(type -ap chgrp) ; do if [ ! $p -ef $0 ]; then DAISY_CHAIN=$p break fi done if [ ! -n "$DAISY_CHAIN" ]; then echo 1>&2 '***' Cannot find real ${0##*/} command exit 1 fi if [ $(id -u) == 0 ]; then echo 1>&2 '***' $(dirname $0) should not be in root\'s \$PATH echo 1>&2 '***' call '"'$DAISY_CHAIN $@'"' directly exit 1 fi # Preserve the command line because we're about to mess with it. cmdline=$@ # Remove any options so $1 becomes the group name. while [ -n "$1" ]; do case $1 in (-*) shift ;; (*) break ;; esac done # If you're not root you can only chgrp to groups you are in, so lets # find out. GRP_CHAIN="" # name or GID? printf '%d' "$1" &>/dev/null if [ $? -eq 0 ]; then GRP_LIST=$(id -G) else GRP_LIST=$(id -Gn) fi for g in ${GRP_LIST}; do if [ "$1" == "$g" ]; then GRP_CHAIN=$g break fi done if [ -z "$GRP_CHAIN" ]; then echo 1>&2 '***' chgrp ${cmdline} else $DAISY_CHAIN ${cmdline} || exit $? fi exit 0 # Local variables: # sh-basic-offset: 4 # End: