blob: 34a31498b591733932d85ca5dfdaa4d97e5df047 (
plain)
1 #!/bin/sh
2 #
3 # - add $ADD_USER user, $ADD_GROUP group
4 # - change files permissions
5 # - reflect changes in config
6 #
7 # We'll assume 'passwd', 'group' and 'shadow' files are in sync.
8
9 ADD_GID=72
10 ADD_UID=72
11 ADD_USER=snmpd
12 ADD_USER_HOME=/var/empty
13 ADD_USER_SHELL=/bin/false
14 ADD_GROUP=snmpd
15
16 ADD_STATUS=0
17 if [ -z `getent group | gawk -F: '{ print $1 }' | grep ^$ADD_GROUP$` ]; then
18 while [ `getent group | gawk -F: '{ print $3 }' | grep ^$ADD_GID$` ]
19 do
20 let ADD_GID+=1
21 done
22 /usr/sbin/groupadd -g $ADD_GID $ADD_GROUP || exit 1
23 echo "$0: Created $ADD_GROUP group, GID=$ADD_GID"
24 else
25 echo "$0: $ADD_GROUP group already exists, trying to create user..."
26 fi
27
28 if [ -z `getent passwd | gawk -F: '{ print $1 }' | grep ^$ADD_USER$` ]; then
29 while [ `getent passwd | gawk -F: '{ print $3 }' | grep ^$ADD_UID$` ]
30 do
31 let ADD_UID+=1
32 done
33 /usr/sbin/useradd -d $ADD_USER_HOME -s $ADD_USER_SHELL -u $ADD_UID -g $ADD_GROUP $ADD_USER || exit 1
34 echo "$0: Created $ADD_USER user, UID=$ADD_UID"
35 else
36 echo $0: "$ADD_USER user already exists"
37 if [[ `getent passwd | grep ^$ADD_USER: | gawk -F: '{ print $4 }'` != `getent group | grep ^$ADD_GROUP: | gawk -F: '{ print $3 }'` ]]; then
38 echo "$0: existing $ADD_USER user is not in $ADD_GROUP group (fix it by hand)."
39 ADD_STAUS=2
40 fi
41 fi
42
43 # additional
44 sed -i s/"\-u\ daemon\ \-g\ daemon"/"\-u\ $ADD_USER\ \-g\ $ADD_GROUP"/ /etc/rc.d/snmpd
45 chown -R $ADD_USER:$ADD_GROUP $PKG/var/{lib,run,log}/snmp
46
47 exit $ADD_STATUS
|