forked from ports/contrib
48 lines
1.4 KiB
Bash
48 lines
1.4 KiB
Bash
#!/bin/sh
|
|
#
|
|
# - add $ADD_USER user, $ADD_GROUP group
|
|
# - change files permissions
|
|
# - reflect changes in config
|
|
#
|
|
# We'll assume 'passwd', 'group' and 'shadow' files are in sync.
|
|
|
|
ADD_GID=72
|
|
ADD_UID=72
|
|
ADD_USER=snmpd
|
|
ADD_USER_HOME=/var/empty
|
|
ADD_USER_SHELL=/bin/false
|
|
ADD_GROUP=snmpd
|
|
|
|
ADD_STATUS=0
|
|
if [ -z `getent group | gawk -F: '{ print $1 }' | grep ^$ADD_GROUP$` ]; then
|
|
while [ `getent group | gawk -F: '{ print $3 }' | grep ^$ADD_GID$` ]
|
|
do
|
|
let ADD_GID+=1
|
|
done
|
|
/usr/sbin/groupadd -g $ADD_GID $ADD_GROUP || exit 1
|
|
echo "$0: Created $ADD_GROUP group, GID=$ADD_GID"
|
|
else
|
|
echo "$0: $ADD_GROUP group already exists, trying to create user..."
|
|
fi
|
|
|
|
if [ -z `getent passwd | gawk -F: '{ print $1 }' | grep ^$ADD_USER$` ]; then
|
|
while [ `getent passwd | gawk -F: '{ print $3 }' | grep ^$ADD_UID$` ]
|
|
do
|
|
let ADD_UID+=1
|
|
done
|
|
/usr/sbin/useradd -d $ADD_USER_HOME -s $ADD_USER_SHELL -u $ADD_UID -g $ADD_GROUP $ADD_USER || exit 1
|
|
echo "$0: Created $ADD_USER user, UID=$ADD_UID"
|
|
else
|
|
echo $0: "$ADD_USER user already exists"
|
|
if [[ `getent passwd | grep ^$ADD_USER: | gawk -F: '{ print $4 }'` != `getent group | grep ^$ADD_GROUP: | gawk -F: '{ print $3 }'` ]]; then
|
|
echo "$0: existing $ADD_USER user is not in $ADD_GROUP group (fix it by hand)."
|
|
ADD_STAUS=2
|
|
fi
|
|
fi
|
|
|
|
# additional
|
|
sed -i s/"\-u\ daemon\ \-g\ daemon"/"\-u\ $ADD_USER\ \-g\ $ADD_GROUP"/ /etc/rc.d/snmpd
|
|
chown -R $ADD_USER:$ADD_GROUP $PKG/var/{lib,run,log}/snmp
|
|
|
|
exit $ADD_STATUS
|