1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#!/bin/sh
set -e
PROG=arb
GROUP=${PROG}
PROGUSERS=""
DEBCONF_DEBUG=developer
. /usr/share/debconf/confmodule
db_version 2.0
## Add group ${PROG} if not existent
## This returns the group including the members of the group which are needed later
TESTGROUP=`getent group ${GROUP}` || true
if [ -z "${TESTGROUP}" ] ; then
addgroup --system "${GROUP}" >/dev/null
# if the group was just created it can not have any users ...
PROGUSERS="none"
fi
# store user info in TMPFILE
TMPFILE=`tempfile`
[ -s /etc/adduser.conf ] && . /etc/adduser.conf
if [ _"$FIRST_UID" = _"" ] ; then
FIRST_UID=1000
fi
(IFS=":"
while read user pass uid gid name rest ; do
if [ "$uid" != "" ] ; then
# in case NIS is used on the machine $uid remains
# empty and breaks the following condition.
if [ $uid -ge $FIRST_UID -a "$user" != "" ] ; then
name=`echo $name | sed "s/,.*//"`
echo "$user ($name)" >> ${TMPFILE}
fi
fi
done < /etc/passwd
)
# Login names of all users of the system as comma separated list
USERS=`sort -u "${TMPFILE}" | tr '\n' ',' | sed 's/,/&\ /g' | sed 's/, *$//g'`
# "login (Real Name)" of group "${PROG}" as comma separated list
if [ "$PROGUSERS" != "none" ] ; then
PROGUSERS=`echo "${TESTGROUP}" | sed "s/.*:\([^:]*\)/\1/" | tr ',' '\n'`
# check whether the TESTGROUP contains any user or is just empty
if [ _"$PROGUSERS" != _"" ] ; then
TMPFILE2=`tempfile`
for user in "${PROGUSERS}" ; do
# add "|| true" because of -e option which would cause an exit otherwise
grep -w "$user" "$TMPFILE" >> "$TMPFILE2" || true
done
mv "$TMPFILE2" "$TMPFILE"
PROGUSERS=`sort -u "${TMPFILE}" | tr '\n' ',' | sed 's/,/&\ /g' | sed 's/, *$//g'`
fi
else
PROGUSERS=""
fi
rm -rf "${TMPFILE}"
# Check for system users who just belong to group ${PROG}
if [ ! _"$PROGUSERS" = _"" ] ; then
db_set ${GROUP}/group "$PROGUSERS" || true
fi
# Initialize List of Systemusers for debconf question
db_subst ${GROUP}/group users "$USERS" || true
db_get ${GROUP}/group || true
db_input high ${GROUP}/group || true
db_go || true
|