aboutsummaryrefslogtreecommitdiffstats
path: root/add-group
blob: ea9e92028e8aba61d58d8c4c495ee99dbf06ef25 (plain)
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
#!/bin/sh
#---------------------------------------------------------------
# Project         : Mandriva Linux
# Module          : rpm-helper
# File            : add-group
# Version         : $Id$
# Author          : Frederic Lepied
# Created On      : Mon Jul 29 15:07:28 2002
# Purpose         : helper script for rpm scriptlets to add a
#		    system group.
#---------------------------------------------------------------

if [ $# -lt 3 ]; then
    echo "usage: $0 <pkg name> <num installed> <group name> [<user1>,<user2>...]" 1>&2
    exit 1
fi

pkg=$1				# name of the package
num=$2				# number of packages installed
name=$3				# name of the group
users=$4			# users to add to this group

if ! getent group $name /dev/null 2>&1; then
    /usr/sbin/groupadd -r $name > /dev/null

    if [ -n "$users" ]; then
	SAVED_IFS="$IFS"
	export IFS="$IFS",
	set $users
	IFS="$SAVED_IFS"

	for u in $*; do
	    old=`egrep "[:,]$u(,|$)" /etc/group | cut -d : -f 1 | xargs echo`
	    if [ -n "$old" ]; then
		old=`echo ",$old" | sed 's/ /,/g'`
	    fi
	    /usr/sbin/usermod -G $name$old $u > /dev/null
	done
    fi
fi

exit 0

# add-group ends here