i.group revision b26a64ae582e72d0b4c710cd8eba9c4afd4a9fdd
#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# ident "%Z%%M% %I% %E% SMI"
#
# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH
while read src dest
do
if [ ! -f $dest ] ; then
cp $src $dest
else
#
# Strip off any leading "/a"
#
dest_file=`echo $dest | sed "s=^/a/=/="`
#
# Add the sysadmin group (gid 14) to support admintool
#
grep '^sysadmin:.*:14:.*' $dest 2>&1 >/dev/null
if [ $? = 0 ] ; then
/usr/bin/true
elif grep '^sysadmin:' $dest 2>&1 >/dev/null; then
cur_name="sysadmin"
echo "SYSADMIN_NOT_14 $dest_file none" >> /tmp/CLEANUP
echo "sysadmin::14:" >> $dest
elif grep ':14:' $dest 2>&1 >/dev/null; then
cur_name=`grep ':14:' $dest | awk -F: '{print $1}'`
echo "GROUP14_IN_USE $dest_file none" >> /tmp/CLEANUP
echo "sysadmin::14:" >> $dest
else # add the group
echo "sysadmin::14:" >> $dest
fi
#
# Add the 'nogroup' group from 4.x so that people don't
# assign it to a regular user and confuse themselves
#
NOGROUP_LINE="nogroup::65534:"
if grep "$NOGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^noaccess::60002:\na\n%s\n.\nw\nq\n' \
"$NOGROUP_LINE" | ed -s $dest > /dev/null
fi
# Remove redundant /etc/group entries that overlap with
# primary groups from /etc/passwd
sed '
/^root:/s/\([:,]\)root,/\1/;
/^root:/s/,root$//;
/^root:/s/:root$/:/;
/^bin:/s/\([:,]\)bin,/\1/;
/^bin:/s/,bin$//;
/^bin:/s/:bin$/:/;
/^sys:/s/\([:,]\)sys,/\1/;
/^sys:/s/,sys$//;
/^sys:/s/:sys$/:/;
/^adm:/s/\([:,]\)adm,/\1/;
/^adm:/s/,adm$//;
/^adm:/s/:adm$/:/;
/^tty:/s/\([:,]\)tty,/\1/;
/^tty:/s/,tty$//;
/^tty:/s/:tty$/:/;
/^uucp:/s/\([:,]\)uucp,/\1/;
/^uucp:/s/,uucp$//;
/^uucp:/s/:uucp$/:/;
/^nuucp:/s/\([:,]\)nuucp,/\1/;
/^nuucp:/s/,nuucp$//;
/^nuucp:/s/:nuucp$/:/;
/^daemon:/s/\([:,]\)daemon,/\1/;
/^daemon:/s/,daemon$//;
/^daemon:/s/:daemon$/:/;
/^smmsp:/s/\([:,]\)smmsp,/\1/;
/^smmsp:/s/,smmsp$//;
/^smmsp:/s/:smmsp$/:/;
/^lp:/s/\([:,]\)lp,/\1/;
/^lp:/s/,lp$//;
/^lp:/s/:lp$/:/' $dest > /tmp/g.$$ &&
cp /tmp/g.$$ $dest
rm -f /tmp/g.$$
#add 'root' to user-list of group1
# line 1,2: skip any line with root in the user field
# line 3: users already in list, add "root,"
# line 4: no users in list, add "root"
sed '
/[:,]root,/b
/[:,]root$/b
s/:1:\([^:][^:]*\)$/:1:root,\1/;
s/:1:$/:1:root/;
' $dest > /tmp/g.$$ &&
cp /tmp/g.$$ $dest
rm -f /tmp/g.$$
#
# Add the 'smmsp' group for sendmail 8.12
#
SMMSPGROUP_LINE="smmsp::25:"
if grep "$SMMSPGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^nogroup::65534:\na\n%s\n.\nw\nq\n' \
"$SMMSPGROUP_LINE" | ed -s $dest > /dev/null
fi
#
# Add the 'gdm' group if it doesn't already exist.
#
GDMGROUP_LINE="gdm::50:"
cur_name=`awk -F: '$3 == 50 {print $1}' $dest`
if [ ! -z "$cur_name" -a "$cur_name" != "gdm" ]; then
echo "ERROR: Reserved GID 50 already assigned" \
"to '$cur_name'" >> /tmp/CLEANUP
elif grep "$GDMGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^smmsp::25:\na\n%s\n.\nw\nq\n' \
"$GDMGROUP_LINE" | ed -s $dest > /dev/null
fi
#
# Add the 'webservd' group if it doesn't already exist.
#
WEBSERVDGROUP_LINE="webservd::80:"
cur_name=`awk -F: '$3 == 80 {print $1}' $dest`
if [ ! -z "$cur_name" -a "$cur_name" != "webservd" ]; then
echo "ERROR: Reserved GID 80 already assigned" \
"to '$cur_name'" >> /tmp/CLEANUP
elif grep "$WEBSERVDGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^gdm::50:\na\n%s\n.\nw\nq\n' \
"$WEBSERVDGROUP_LINE" | ed -s $dest > /dev/null
fi
#
# Add the 'postgres' group if it doesn't already exist.
#
POSTGRESGROUP_LINE="postgres::90:"
cur_name=`awk -F: '$3 == 90 {print $1}' $dest`
cur_id=`awk -F: '$1 == "postgres" {print $3}' $dest`
if [ ! -z "$cur_name" -a "$cur_name" != "postgres" ]; then
echo "ERROR: Reserved GID 90 already assigned" \
"to '$cur_name'" >> /tmp/CLEANUP
elif [ ! -z "$cur_id" -a "$cur_id" != "90" ]; then
echo "NOTE: postgres group already assigned" \
"to id '$cur_id'" >> /tmp/CLEANUP
elif grep "$POSTGRESGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^webservd::80:\na\n%s\n.\nw\nq\n' \
"$POSTGRESGROUP_LINE" | ed -s $dest > /dev/null
fi
#
# Add the 'mysql' group if it doesn't already exist.
#
MYSQLGROUP_LINE="mysql::70:"
cur_name=`awk -F: '$3 == 70 {print $1}' $dest`
cur_id=`awk -F: '$1 == "mysql" {print $3}' $dest`
if [ ! -z "$cur_name" -a "$cur_name" != "mysql" ]; then
echo "ERROR: Reserved GID 70 already assigned" \
"to '$cur_name'" >> /tmp/CLEANUP
elif [ ! -z "$cur_id" -a "$cur_id" != "70" ]; then
echo "NOTE: mysql group already assigned" \
"to id '$cur_id'" >> /tmp/CLEANUP
elif grep "$MYSQLGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^postgres::90:\na\n%s\n.\nw\nq\n' \
"$MYSQLGROUP_LINE" | ed -s $dest > /dev/null
fi
#
# Add the 'games' group if it doesn't already exist.
#
GAMESGROUP_LINE="games::20:"
cur_name=`awk -F: '$3 == 20 {print $1}' $dest`
cur_id=`awk -F: '$1 == "games" {print $3}' $dest`
if [ ! -z "$cur_name" -a "$cur_name" != "games" ]; then
echo "ERROR: Reserved GID 20 already assigned" \
"to '$cur_name'" >> /tmp/CLEANUP
elif [ ! -z "$cur_id" -a "$cur_id" != "20" ]; then
echo "NOTE: games group already assigned" \
"to id '$cur_id'" >> /tmp/CLEANUP
elif grep "$GAMESGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^smmsp::25:\ni\n%s\n.\nw\nq\n' \
"$GAMESGROUP_LINE" | ed -s $dest > /dev/null
fi
#
# Add the 'xvm' group if it doesn't already exist.
#
XVMGROUP_LINE="xvm::60:"
cur_name=`awk -F: '$3 == 60 {print $1}' $dest`
cur_id=`awk -F: '$1 == "xvm" {print $3}' $dest`
if [ ! -z "$cur_name" -a "$cur_name" != "xvm" ]; then
echo "ERROR: Reserved GID 60 already assigned" \
"to '$cur_name'" >> /tmp/CLEANUP
elif [ ! -z "$cur_id" -a "$cur_id" != "60" ]; then
echo "NOTE: xvm group already assigned" \
"to id '$cur_id'" >> /tmp/CLEANUP
elif grep "$XVMGROUP_LINE" $dest 2>&1 >/dev/null; then
:
else
printf '/^mysql::70:\ni\n%s\n.\nw\nq\n' \
"$XVMGROUP_LINE" | ed -s $dest > /dev/null
fi
fi
done
exit 0