robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
robbiew | 599ddd7 | 2001-11-28 21:31:41 +0000 | [diff] [blame^] | 3 | # 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 | |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 27 | # Prompt user if ids/groups should be created |
robbiew | c0f37e6 | 2001-11-27 19:14:19 +0000 | [diff] [blame] | 28 | clear |
| 29 | echo "Checking for required user/group ids" |
| 30 | echo "" |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 31 | echo -n "If any required user ids and/or groups are missing, would you like these created? Y/N " |
| 32 | read ans |
| 33 | case $ans in |
| 34 | Y*|y*) |
| 35 | CREATE=1 |
| 36 | ;; |
| 37 | *) |
| 38 | CREATE=0 |
| 39 | ;; |
| 40 | esac |
| 41 | |
| 42 | # Check ids and create if needed. |
| 43 | NOBODY_ID=0 |
| 44 | BIN_ID=0 |
| 45 | DAEMON_ID=0 |
| 46 | NOBODY_GRP=0 |
| 47 | BIN_GRP=0 |
| 48 | DAEMON_GRP=0 |
| 49 | |
| 50 | id nobody > /dev/null |
| 51 | if [ $? != "0" ]; then |
| 52 | NOBODY_ID=1 |
| 53 | fi |
| 54 | |
| 55 | id bin > /dev/null |
| 56 | if [ $? != "0" ]; then |
| 57 | BIN_ID=1 |
| 58 | fi |
| 59 | |
| 60 | id daemon > /dev/null |
| 61 | if [ $? != "0" ]; then |
| 62 | DAEMON_ID=1 |
| 63 | fi |
| 64 | |
| 65 | id -g nobody > /dev/null |
| 66 | if [ $? != "0" ]; then |
| 67 | NOBODY_GRP=1 |
| 68 | fi |
| 69 | |
| 70 | id -g bin > /dev/null |
| 71 | if [ $? != "0" ]; then |
| 72 | BIN_GRP=1 |
| 73 | fi |
| 74 | |
| 75 | id -g daemon > /dev/null |
| 76 | if [ $? != "0" ]; then |
| 77 | DAEMON_GRP=1 |
| 78 | fi |
| 79 | |
| 80 | if [ $NOBODY_ID != "1" ] && [ $NOBODY_GRP != "1" ]; then |
| 81 | echo "Nobody user id and group exist." |
| 82 | else |
| 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 |
| 89 | fi |
| 90 | |
| 91 | if [ $BIN_ID != "1" ] && [ $BIN_GRP != "1" ]; then |
| 92 | echo "Bin user id and group exist." |
| 93 | else |
| 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 |
| 100 | fi |
| 101 | |
| 102 | if [[ $DAEMON_ID -ne "1" ]] && [[ $DAEMON_GRP -ne "1" ]]; then |
| 103 | echo "Daemon user id and group exist." |
| 104 | else |
| 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 |
| 111 | fi |
| 112 | |
| 113 | id nobody > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 114 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 115 | id bin > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 116 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 117 | id daemon > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 118 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 119 | id -g nobody > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 120 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 121 | id -g bin > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 122 | if [ $? -eq "0" ]; then |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 123 | id -g daemon > /dev/null |
robbiew | 3f9a880 | 2001-10-12 20:39:17 +0000 | [diff] [blame] | 124 | if [ $? -eq "0" ]; then |
| 125 | echo "Required users/groups exist." |
| 126 | exit 0 |
| 127 | fi |
| 128 | fi |
| 129 | fi |
| 130 | fi |
| 131 | fi |
| 132 | fi |
robbiew | d23f724 | 2001-11-21 17:33:40 +0000 | [diff] [blame] | 133 | echo "*****************************************" |
| 134 | echo "* Required users/groups do NOT exist!!! *" |
| 135 | echo "* *" |
| 136 | echo "* Some kernel/syscall tests will FAIL! *" |
| 137 | echo "*****************************************" |
| 138 | exit 1 |