blob: fcc9491ff6462c1e9f8489ec7c6ce2e75f1e25cf (
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=70
10 ADD_UID=70
11 ADD_USER=zbxagent
12 ADD_USER_HOME=/var/empty
13 ADD_USER_SHELL=/bin/bash
14 ADD_GROUP=zabbix
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 chown -R $ADD_USER:$ADD_GROUP /var/log/zabbix_agentd
45 chown -R $ADD_USER:$ADD_GROUP /var/run/zabbix_agentd
46 chown $ADD_USER:$ADD_GROUP /etc/zabbix/zabbix_agentd.conf
47 sed -i "s|su daemon -c /usr/bin/zabbix_agentd|su $ADD_USER -c /usr/bin/zabbix_agentd|" /etc/rc.d/zabbix_agentd
48
49 exit $ADD_STATUS
|