blob: 704a2a927cdadfb86ae9a80516294eaab66fe55c [file] [log] [blame]
robbiew3f9a8802001-10-12 20:39:17 +00001#!/bin/sh
2
robbiew599ddd72001-11-28 21:31:41 +00003# Copyright (c) International Business Machines Corp., 2001
4#
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.
9#
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.
14#
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
18
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
robbiew631a9f52002-03-05 22:42:55 +000024# 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
robbiew599ddd72001-11-28 21:31:41 +000028
29
30
robbiewd23f7242001-11-21 17:33:40 +000031# Prompt user if ids/groups should be created
robbiewc0f37e62001-11-27 19:14:19 +000032clear
33echo "Checking for required user/group ids"
34echo ""
robbiewd23f7242001-11-21 17:33:40 +000035
36# Check ids and create if needed.
37NOBODY_ID=0
38BIN_ID=0
39DAEMON_ID=0
40NOBODY_GRP=0
41BIN_GRP=0
42DAEMON_GRP=0
43
44id nobody > /dev/null
45if [ $? != "0" ]; then
46 NOBODY_ID=1
47fi
48
49id bin > /dev/null
50if [ $? != "0" ]; then
51 BIN_ID=1
52fi
53
54id daemon > /dev/null
55if [ $? != "0" ]; then
56 DAEMON_ID=1
57fi
58
59id -g nobody > /dev/null
60if [ $? != "0" ]; then
61 NOBODY_GRP=1
62fi
63
64id -g bin > /dev/null
65if [ $? != "0" ]; then
66 BIN_GRP=1
67fi
68
69id -g daemon > /dev/null
70if [ $? != "0" ]; then
71 DAEMON_GRP=1
72fi
73
robbiew631a9f52002-03-05 22:42:55 +000074if [ $NOBODY_ID != "0" ] || [ $BIN_ID != "0" ] || [ $DAEMON_ID != "0" ] || [ $NOBODY_GRP != "0" ] || [ $BIN_GRP != "0" ] || [ $DAEMON_GRP != "0" ];
75then
76 echo -n "If any required user ids and/or groups are missing, would you like these created? Y/N "
77 read ans
78 case $ans in
79 Y*|y*)
80 CREATE=1
81 ;;
82 *)
83 CREATE=0
84 ;;
85 esac
86fi
87
robbiewd23f7242001-11-21 17:33:40 +000088if [ $NOBODY_ID != "1" ] && [ $NOBODY_GRP != "1" ]; then
89 echo "Nobody user id and group exist."
90else
91 if [ $NOBODY_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
92 echo nobody:x:99:99:Nobody:: >> /etc/passwd
93 fi
94 if [ $NOBODY_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
95 echo nobody:x:`id -u nobody`: >> /etc/group
96 fi
97fi
98
99if [ $BIN_ID != "1" ] && [ $BIN_GRP != "1" ]; then
100 echo "Bin user id and group exist."
101else
nstrazf9598e42001-12-19 15:45:24 +0000102 if [ $BIN_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000103 echo bin:x:1:1:bin:: >> /etc/passwd
104 fi
nstrazf9598e42001-12-19 15:45:24 +0000105 if [ $BIN_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000106 echo bin:x:`id -u bin`:bin >> /etc/group
107 fi
108fi
109
nstrazf9598e42001-12-19 15:45:24 +0000110if [ $DAEMON_ID -ne "1" ] && [ $DAEMON_GRP -ne "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000111 echo "Daemon user id and group exist."
112else
nstrazf9598e42001-12-19 15:45:24 +0000113 if [ $DAEMON_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000114 echo daemon:x:2:2:daemon:: >> /etc/passwd
115 fi
nstrazf9598e42001-12-19 15:45:24 +0000116 if [ $DAEMON_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000117 echo daemon:x:`id -u daemon`:daemon >> /etc/group
118 fi
119fi
120
121id nobody > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000122if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000123 id bin > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000124 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000125 id daemon > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000126 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000127 id -g nobody > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000128 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000129 id -g bin > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000130 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000131 id -g daemon > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000132 if [ $? -eq "0" ]; then
133 echo "Required users/groups exist."
134 exit 0
135 fi
136 fi
137 fi
138 fi
139 fi
140fi
robbiewd23f7242001-11-21 17:33:40 +0000141echo "*****************************************"
142echo "* Required users/groups do NOT exist!!! *"
143echo "* *"
144echo "* Some kernel/syscall tests will FAIL! *"
145echo "*****************************************"
146exit 1