blob: 7e09d4a08f86ca9560b4c25226d2e64b2c4664ff [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
24
25
26
robbiewd23f7242001-11-21 17:33:40 +000027# Prompt user if ids/groups should be created
robbiewc0f37e62001-11-27 19:14:19 +000028clear
29echo "Checking for required user/group ids"
30echo ""
robbiewd23f7242001-11-21 17:33:40 +000031echo -n "If any required user ids and/or groups are missing, would you like these created? Y/N "
32read ans
33case $ans in
34 Y*|y*)
35 CREATE=1
36 ;;
37 *)
38 CREATE=0
39 ;;
40esac
41
42# Check ids and create if needed.
43NOBODY_ID=0
44BIN_ID=0
45DAEMON_ID=0
46NOBODY_GRP=0
47BIN_GRP=0
48DAEMON_GRP=0
49
50id nobody > /dev/null
51if [ $? != "0" ]; then
52 NOBODY_ID=1
53fi
54
55id bin > /dev/null
56if [ $? != "0" ]; then
57 BIN_ID=1
58fi
59
60id daemon > /dev/null
61if [ $? != "0" ]; then
62 DAEMON_ID=1
63fi
64
65id -g nobody > /dev/null
66if [ $? != "0" ]; then
67 NOBODY_GRP=1
68fi
69
70id -g bin > /dev/null
71if [ $? != "0" ]; then
72 BIN_GRP=1
73fi
74
75id -g daemon > /dev/null
76if [ $? != "0" ]; then
77 DAEMON_GRP=1
78fi
79
80if [ $NOBODY_ID != "1" ] && [ $NOBODY_GRP != "1" ]; then
81 echo "Nobody user id and group exist."
82else
83 if [ $NOBODY_ID -eq "1" ] && [ $CREATE -eq "1" ]; then
84 echo nobody:x:99:99:Nobody:: >> /etc/passwd
85 fi
86 if [ $NOBODY_GRP -eq "1" ] && [ $CREATE -eq "1" ]; then
87 echo nobody:x:`id -u nobody`: >> /etc/group
88 fi
89fi
90
91if [ $BIN_ID != "1" ] && [ $BIN_GRP != "1" ]; then
92 echo "Bin user id and group exist."
93else
94 if [[ $BIN_ID -eq "1" ]] && [[ $CREATE -eq "1" ]]; then
95 echo bin:x:1:1:bin:: >> /etc/passwd
96 fi
97 if [[ $BIN_GRP -eq "1" ]] && [[ $CREATE -eq "1" ]]; then
98 echo bin:x:`id -u bin`:bin >> /etc/group
99 fi
100fi
101
102if [[ $DAEMON_ID -ne "1" ]] && [[ $DAEMON_GRP -ne "1" ]]; then
103 echo "Daemon user id and group exist."
104else
105 if [[ $DAEMON_ID -eq "1" ]] && [[ $CREATE -eq "1" ]]; then
106 echo daemon:x:2:2:daemon:: >> /etc/passwd
107 fi
108 if [[ $DAEMON_GRP -eq "1" ]] && [[ $CREATE -eq "1" ]]; then
109 echo daemon:x:`id -u daemon`:daemon >> /etc/group
110 fi
111fi
112
113id nobody > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000114if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000115 id bin > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000116 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000117 id daemon > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000118 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000119 id -g nobody > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000120 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000121 id -g bin > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000122 if [ $? -eq "0" ]; then
robbiewd23f7242001-11-21 17:33:40 +0000123 id -g daemon > /dev/null
robbiew3f9a8802001-10-12 20:39:17 +0000124 if [ $? -eq "0" ]; then
125 echo "Required users/groups exist."
126 exit 0
127 fi
128 fi
129 fi
130 fi
131 fi
132fi
robbiewd23f7242001-11-21 17:33:40 +0000133echo "*****************************************"
134echo "* Required users/groups do NOT exist!!! *"
135echo "* *"
136echo "* Some kernel/syscall tests will FAIL! *"
137echo "*****************************************"
138exit 1