1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
#!/bin/bash
#***********************************************************
# Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#***********************************************************/
#
# simple script to create the test user needed for testing certain
# test cases. Also creates a file to indicate that the user exists and
# tests can proceed.
#
# Must be run as root or sudo
#
# todo: add -f option so tests will run with data install errors?
## create user and group
# Because we are doing these by name, in the multi-machine install case
# we may end up with uid/gid being different across machines. This will
# either need to be fixed by hand or with NFSv4 you can use rpc.idmapd
# to do uid/gid mapping. More details will be provided in the multi-machine
# documentation.
function add_group() {
#
# expects name of project group
if [ -z $1 ]
then return 1
else
groupname=$1
fi
# check for group
if grep -q "^$groupname:" /etc/group; then
echo "NOTE: group '$groupname' already exists, good."
return 0
else
# use addgroup if it exists since it supports --system
if [ -f /usr/sbin/addgroup -a ! -L /usr/sbin/addgroup ]; then
addgroup --system $groupname
else
groupadd $groupname
fi
if [ "$?" != "0" ] ; then
echo "ERROR: Unable to create group '$groupname'"
return 1
else
echo "NOTE: group '$groupname' created"
return 0
fi
fi
} # add_group
function add_user() {
#
# expects name of the user and groupname
if [ -z $1 ]
then return 1
else
username=$1
fi
if [ -z $2 ]
then return 1
else
groupname=$2
fi
# check for user
if grep -q "^$username:" /etc/passwd; then
echo "NOTE: user '$username' already exists, good."
USERSHELL=`grep "^$username:" /etc/passwd |cut -d: -f 7`
if [ "$USERSHELL" = "/bin/false" ]; then
echo "ERROR: $username shell must be a real shell"
return 1
fi
return 0
else
# use adduser if it exists since it supports --system, but
# not if it's a symlink (probably to /usr/sbin/useradd)
if [ -f /usr/sbin/adduser -a ! -L /usr/sbin/adduser ]; then
adduser --gecos "Fossolgy Test User" --ingroup $groupname --system \
--shell /bin/bash --home "/home/$username" $username
else
useradd -c "UI_Test" -g $groupname -m \
-s /bin/bash -d "/home/$username" $username
fi
if [ "$?" != "0" ] ; then
echo "ERROR: Unable to create user '$username'"
return 1
else
echo "NOTE: user '$username' created"
/usr/sbin/usermod -G fossy,sudo,users $username
/usr/sbin/chpasswd <<< "$username:$username"
return 0
fi
fi
}
##############################################################################
# Main
##############################################################################
# This must run as root.
if [ `id -u` != "0" ] ; then
echo "ERROR: $0 must run as root."
echo "Aborting."
exit 1
fi
# add groups
add_group fosstester
if [ $? -ne 0 ]
then
echo "ERROR! could not create fosstester"
exit 1
fi
add_group noemail
if [ $? -ne 0 ]
then
echo "ERROR! could not create noemail group"
exit 1
fi
# fosstester
add_user fosstester fosstester
if [ $? -ne 0 ]
then
echo "ERROR! could not create fosstester user"
exit 1
fi
# noemail
add_user noemail noemail
if [ $? -ne 0 ]
then
echo "ERROR! could not create noemail user"
exit 1
fi
# remove this for now, don't want this script doing it.
#if [ -x ./installTestData.sh ]
##then
# ./installTestData.sh
# if [ $? -ne 0 ]
# then
# echo "ERROR! durnig run of installTestData.sh"
# exit 1
# fi
#else
# echo "ERROR! Either ./installTestData.sh doesn't exist or is not executable"
# exit 1
#fi
#
# set up the all clear file
# Some tests look for this file to make sure there is data for use.
touch /home/fosstester/allClear
chmod a+rx /home/fosstester/allClear
chown fosstester:fosstester /home/fosstester/allClear
exit 0
|