Add the "failed command file" option
[ltp-debian.git] / IDcheck.sh
bloba492f2be3b190f0cdda47ce047400562c43b3410
1 #!/bin/sh
3 # Copyright (c) International Business Machines Corp., 2001
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 # the GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # FILE : IDcheck.sh
20 # DESCRIPTION : checks for req'd users/groups and will create them if requested.
21 # HISTORY :
22 # 11/28/2001 Robbie Williamson (robbiew@austin.ibm.com)
23 # written
24 # 03/05/2002 Jay Huie (wjh@us.ibm.com)
25 # Changed script to only ask regarding creation of IDs if
26 # necessary. Cleaner automation of the script and
27 # most distos now have IDs already added
28 # HISTORY : see the cvs log
31 # debian is good enough
33 exit 0
35 # Prompt user if ids/groups should be created
36 clear
37 echo "Checking for required user/group ids"
38 echo ""
40 # Check ids and create if needed.
41 NO_NOBODY_ID=1
42 NO_BIN_ID=1
43 NO_DAEMON_ID=1
44 NO_NOBODY_GRP=1
45 NO_BIN_GRP=1
46 NO_DAEMON_GRP=1
47 NO_USERS_GRP=1
48 NO_SYS_GRP=1
49 I_AM_ROOT=0
52 # id(1) for entry.
54 ife() {
55 id "$@" > /dev/null
59 # grep(1) for entry.
61 gfe() {
62 grep -q "$@"
65 prompt_for_create() {
66 if [ -n "$CREATE_ENTRIES" ] ; then
68 if [ $I_AM_ROOT -eq 0 ] ; then
69 echo "Not root; can't create user / group entries on local machine".
70 CREATE_ENTRIES=0
72 echo "CREATE_ENTRIES variable set to $CREATE_ENTRIES ..."
73 echo
75 else
77 if [ $NO_NOBODY_ID -ne 0 -o $NO_BIN_ID -ne 0 -o $NO_DAEMON_ID -ne 0 -o $NO_NOBODY_GRP -ne 0 -o $NO_BIN_GRP -ne 0 -o $NO_DAEMON_GRP -ne 0 -o $NO_USERS_GRP -ne 0 -o $NO_SYS_GRP -ne 0 -a $I_AM_ROOT -ne 0 ] ; then
78 echo -n "If any required user ids and/or groups are missing, would you like these created? [y/N]"
79 read ans
80 case "$ans" in
81 Y*|y*) CREATE_ENTRIES=1 ;;
82 *) CREATE_ENTRIES=0 ;;
83 esac
84 else
85 CREATE_ENTRIES=0
91 if [ -z ${EUID} ] ; then
92 EUID=$(id -u)
95 if [ -e /etc/passwd -a ! -r /etc/passwd ] ; then
96 echo "/etc/passwd not readable by uid $EUID"
97 exit 1
98 elif [ -e /etc/group -a ! -r /etc/group ] ; then
99 echo "/etc/group not readable by uid $EUID"
100 exit 1
103 ife bin; NO_BIN_ID=$?
104 ife daemon; NO_DAEMON_ID=$?
105 ife nobody; NO_NOBODY_ID=$?
107 gfe '^bin:' /etc/group; NO_BIN_GRP=$?
108 gfe '^daemon:' /etc/group; NO_DAEMON_GRP=$?
109 gfe '^nobody:' /etc/group; NO_NOBODY_GRP=$?
110 gfe '^sys:' /etc/group; NO_SYS_GRP=$?
111 gfe '^users:' /etc/group; NO_USERS_GRP=$?
113 if [ $EUID -eq 0 ] ; then
114 I_AM_ROOT=1
117 prompt_for_create
119 debug_vals() {
121 echo "Missing the following group / user entries:"
122 echo "nobody: $NO_NOBODY_ID"
123 echo "bin: $NO_BIN_ID"
124 echo "daemon: $NO_DAEMON_ID"
125 echo "nobody grp: $NO_NOBODY_GRP"
126 echo "bin grp: $NO_BIN_GRP"
127 echo "daemon grp: $NO_DAEMON_GRP"
128 echo "sys grp: $NO_SYS_GRP"
129 echo "users grp: $NO_USERS_GRP"
130 echo ""
131 echo "i am root: $I_AM_ROOT"
132 echo ""
136 #debug_vals
138 if [ $CREATE_ENTRIES -ne 0 ] ; then
139 if ! touch /etc/group ; then
140 echo "Couldn't touch /etc/group"
141 exit 1
145 make_user_group() {
146 local name=$1 id=$2 no_id=$3 no_grp=$4
148 if [ $no_id -eq 0 -a $no_grp -eq 0 ] ; then
149 echo "'$name' user id and group found."
150 elif [ $CREATE_ENTRIES -ne 0 ] ; then
151 echo "Creating entries for $name"
153 # Avoid chicken and egg issue with id(1) call
154 # made above and below.
155 if ! gfe "^${name}:" /etc/passwd && [ $no_id -ne 0 ] ; then
156 echo "${name}:x:${id}:${id}:${name}::" >> /etc/passwd
158 if [ $no_grp -ne 0 ] ; then
159 echo "${name}:x:$(id -u ${name}):" >> /etc/group
163 make_user_group nobody 99 $NO_NOBODY_ID $NO_NOBODY_GRP
164 make_user_group bin 1 $NO_BIN_ID $NO_BIN_GRP
165 make_user_group daemon 2 $NO_DAEMON_ID $NO_DAEMON_GRP
167 if [ $NO_USERS_GRP -eq 0 ] ; then
168 echo "Users group found."
169 elif [ $CREATE_ENTRIES -ne 0 ] ; then
170 echo 'users:x:100:' >> /etc/group
173 if [ $NO_SYS_GRP -eq 0 ] ; then
174 echo "Sys group found."
175 elif [ $CREATE_ENTRIES -ne 0 ] ; then
176 echo 'sys:x:3:' >> /etc/group
179 if ife nobody && ife bin && ife daemon &&
180 ife -g nobody && ife -g bin && ife -g daemon &&
181 gfe '^users:' /etc/group && gfe '^sys:' /etc/group &&
182 gfe '^nobody:' /etc/group
183 then
184 echo ""
185 echo "Required users/groups exist."
186 exit 0
189 echo ""
190 echo "*****************************************"
191 echo "* Required users/groups do NOT exist!!! *"
192 echo "* *"
193 echo "* Some kernel/syscall tests will FAIL! *"
194 echo "*****************************************"
195 exit 1