]> git.pld-linux.org Git - packages/rpm.git/blob - rpm-user_group.sh
- %addusertogroup macro for RPM
[packages/rpm.git] / rpm-user_group.sh
1 #!/bin/sh
2
3 [ -f /etc/sysconfig/rpm ] && . /etc/sysconfig/rpm
4 [ -z "$RPM_SCRIPTVERBOSITY" ] && RPM_SCRIPTVERBOSITY=5
5
6 if [ "$1" = user -o "$1" = group ]; then
7         MODE=$1
8 else
9         echo ERROR
10         exit 2
11 fi
12 shift
13
14 testrm()
15 {
16         [ "$RPM_USERDEL" != yes ] && return 1
17         [ -z "$1" ] && return 2
18         rpm -q --whatprovides "${MODE}($1)" >/dev/null 2>&1
19         # no package Provides it (strange)
20         [ $? -ne 0 ] && return 0
21         # only current package Provides it
22         [ `rpm -q --whatprovides "${MODE}($1)" | wc -l` -lt 2 ] && return 0
23         return 1
24 }
25
26 if [ "$1" = "testrm" ]; then
27         testrm $2
28         exit $?
29 elif [ "$1" = del ]; then
30         if testrm $2; then
31                 [ "$RPM_SCRIPTVERBOSITY" -lt 2 ] || echo "Removing $MODE $2"
32                 /usr/sbin/${MODE}del $2 || :
33         fi
34 elif [ "$MODE" = "user" -a "$1" = "addtogroup" ]; then
35         USER=$2
36         GROUP=$3
37         GROUPS=`id -n -G $USER | sed -e's/^[^ ]* //;s/ /,/g'`
38         if ! echo ",$GROUPS," | grep -q ",$GROUP," ; then
39             [ "$RPM_SCRIPTVERBOSITY" -lt 2 ] || echo "Adding user $USER to group $GROUP"
40             usermod -G "$GROUPS,$GROUP" $USER
41         fi
42 else
43         echo ERROR
44         exit 2
45 fi
This page took 0.033037 seconds and 4 git commands to generate.