[Cdd-commits] cdd/common/cdd/share/cdd/unixgroups cdd-actions,1.12,1.13
Andreas Tille
debian-custom@lists.debian.org
Tue, 22 Jun 2004 20:55:18 +0000
Update of /cvsroot/cdd/cdd/common/cdd/share/cdd/unixgroups
In directory haydn:/tmp/cvs-serv22879/cdd/share/cdd/unixgroups
Modified Files:
cdd-actions
Log Message:
Fixes various stupid bugs in transition from get-group-users to cdd-tools
Index: cdd-actions
===================================================================
RCS file: /cvsroot/cdd/cdd/common/cdd/share/cdd/unixgroups/cdd-actions,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cdd-actions 18 Jun 2004 12:43:55 -0000 1.12
+++ cdd-actions 22 Jun 2004 20:55:15 -0000 1.13
@@ -88,56 +88,64 @@
}
# echoes list of users having role $2 in CDD $1
-# if $3 exists use ',' as separator between user names
+# if $4 exists use ',' as separator between user names
getUsersInRole() {
RET=0
CDD=$1
ROLE=$2
- if [ "$#" -eq 2 ]; then
- USERS=`getent group ${ROLE} | sed -ne "s/.*:\(.*\)$/\1/p" | tr "," " "`
- cddDebug "getUsersInRole(): users covering role ${ROLE} for CDD ${CDD}: ${USERS}"
- echo ${USERS}
- elif [ "$#" -eq 3 ]; then
- USERS=`getent group ${ROLE} | sed -ne "s/.*:\(.*\)$/\1/p"`
- cddDebug "getUsersInRole(): users covering role ${ROLE} for CDD ${CDD}: ${USERS}"
- echo ${USERS}
- else
- RET=64 # EX_USAGE
+ SIMPLE=$3
+ USERS=""
+ if [ "$#" -ne 3 -a "$#" -ne 4 ]; then
+ return RET=64 # EX_USAGE
fi
+ for user in `getent group ${ROLE} | sed -ne "s/.*:\(.*\)$/\1/p" | tr "," " "` ; do
+ REALNAME=" "
+ if [ $SIMPLE -ne 1 ] ; then
+ REALNAME=" (`grep \"^$user:\" /etc/passwd | sed \"s/^$user:[^:]\+:[0-9]\+:[0-9]\+:\([^:]\+\):.*/\1/\" | sed \"s/,.*//\"`)"
+ fi
+ if [ "$#" -eq 4 ]; then
+ if [ "$USERS" != "" ] ; then
+ USERS="${USERS},"
+ fi
+ fi
+ if [ "$USERS" != "" ] ; then
+ USERS="${USERS} "
+ fi
+ USERS="${USERS}${user}${REALNAME}"
+ done
+ echo $USERS
return ${RET}
}
# echoes list of all users of the system
# $1 = 1 - simply login names, $1 = 0 (or anything else) - login names and real name
-# if $1 exists use ',' as separator between user names
+# if $2 exists use ',' as separator between user names
getAllUsers() {
RET=0
if [ "$#" -ne 1 -a "$#" -ne 2 ]; then
RET=64 # EX_USAGE
else
SIMPLE=$1
- KOMMA=" "
- # Append ',' if second argument is given
- if [ "$#" -eq 2 ]; then
- KOMMA=", "
- fi
- USERS=""
+ TMPFILE=`tempfile`
(IFS=":"
while read user pass uid gid name rest ; do
if [ $uid -ge $FIRST_UID -a "$user" != "nobody" ] ; then
name=`echo $name | sed "s/,.*//"`
- if [ "$USERS" != "" ] ; then
- USERS="$USERS$KOMMA"
- fi
if [ $SIMPLE -eq 1 ] ; then
- USERS="$USERS$user"
+ echo "$user" >> ${TMPFILE}
else
- USERS="$USERS$user ($name)"
+ echo "$user ($name)" >> ${TMPFILE}
fi
fi
done < /etc/passwd
- echo $USERS
)
+ # Append ',' if second argument is given
+ if [ "$#" -eq 2 ]; then
+ sort -u "${TMPFILE}" | tr '\n' ',' | sed 's/,/&\ /g' | sed 's/, *$//g'
+ else
+ sort -u "${TMPFILE}"
+ fi
+ rm -f "${TMPFILE}"
fi
return ${RET}
}