Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / nisclient-adl
1 #!/bin/bash
2 ###############################################################################
3 # This script sets a machine up to be an NIS client.
4 # Kevin Lister 10.28.98
5 ###############################################################################
6 # Variables
7 logfile=/nisclient.log
8 me=${0##*/}
9
10 admin=adl-support@cup.hp.com
11 nisdomain=adl
12 domainname=
13 namesvrs=/etc/rc.config.d/namesvrs
14 nsswitch=/etc/nsswitch.conf
15 pwfile=/etc/passwd
16 lclpwfile=/etc/passwd.loc
17 nispwfile=/etc/passwd-nis
18 grpfile=/etc/group
19 nisgrpfile=/etc/group-nis
20 crontab=/var/spool/cron/crontabs/root
21 newcrontab=/tmp/root-crontab
22 null=/dev/null
23 ypdir=/var/yp
24
25 # Functions
26 function error {
27   print -u2 "$me: Error: $1"
28   /usr/bin/mailx -s "$(uname -n): NIS setup error: $1" $admin < $null
29   exit 255;
30 } # error
31
32 function warning {
33   print -u2 "$me: Warning: $1"
34 } # warning
35
36 function display {
37   print "$1"
38 } # display
39
40 function info {
41   display "$me: Info: $1"
42 } # info
43
44 ##
45 ########## Main
46 ##
47
48 ##
49 ########## Check the status of the system before proceeding
50 ##
51
52 # Must be root to run this
53 if [ $(id -u) -ne 0 ]; then
54         error "Must be root to execute this command... Exiting."
55 fi
56
57 # Check to see if this script has already been ran
58 if [ -a $logfile ]; then
59         error "$me has already been ran on $(uname -n)... Exiting"
60 fi
61
62 # Check to see if domainname has been set
63 domainname=`/bin/domainname`
64 if [ "_$domainname" != "_" ]; then
65         error "NIS Domain name is already set to -> $domainname... Exiting."
66 fi
67
68 # Are we already running NIS?
69 /usr/bin/ypwhich >> $logfile 2>&1
70 if [ $? -eq 0 ]; then
71         error "This system is already running NIS... Exiting."
72 fi
73
74 # Check to see if there is a name service switch config file
75 if [ -a $nsswitch ]; then
76         error "This system has a name service switch config file...
77 Exiting."
78 fi
79
80 # Check to see if /var/yp exists
81 if [ ! -a $ypdir ]; then
82         error "Directory /var/yp does not exist... Exiting"
83 fi
84
85 ##
86 ########## System checks out. Set up the files and start NIS.
87 ##
88
89 # Set the NIS domain name - This is probably not needed
90 /bin/domainname $nisdomain >> $logfile 2>&1
91 if [ $? -ne 0 ]; then
92         error "Could not set NIS domain name... Exiting."
93 fi
94
95 # Setup the /etc/rc.config.d/namesvrs file
96 /usr/sbin/ch_rc -ap NIS_CLIENT=1 \
97        -p NIS_DOMAIN=adl \
98        -p WAIT_FOR_NIS_SERVER=FALSE
99
100 # Email us if there are local passwd entries other than root
101 if [ $( /bin/wc -l $lclpwfile | /bin/cut -d " " -f 1) != "1"  ]; then
102         /usr/bin/mailx -s "$(uname -n): passwd.loc has more than 1 line"
103 $admin < $lclpwfile
104 fi
105
106 # Create NIS passwd file
107 if [ -a $lclpwfile ]; then
108         /bin/grep "^root" $lclpwfile > $nispwfile
109 else
110         /bin/grep "^root" $pwfile > $nispwfile
111 fi
112
113 /bin/cat >> $nispwfile <<:END
114 adm:*:4:4::/usr/adm:/usr/bin/sh
115 anon:*:21:5:placeholder for future:/:/usr/bin/sync
116 bin:*:2:2::/usr/bin:/bin/sh
117 daemon:*:1:5::/:/usr/bin/sh
118 ftp:*:500:10:anonymous ftp:/home/ftp:/usr/bin/false
119 lp:*:9:7:[Line Printer]:/usr/spool/lp:/usr/bin/sh
120 nuucp:*:6:1:0000-uucp(0000):/usr/spool/uucppublic:/usr/lib/uucp/uucico
121 sync:*:20:1::/:/usr/bin/sync
122 tftp:*:510:1:Trivial FTP user:/usr/tftpdir:/usr/bin/false
123 uucp:*:5:3::/usr/spool/uucppublic:/usr/lib/uucp/uucico
124 who:*:90:1::/:/usr/bin/who
125 :END
126
127 /bin/grep -v "^root" $lclpwfile >> $nispwfile
128
129 /bin/cat >> $nispwfile <<:END2
130 -@dangerous-users
131 +@sysadmin
132 +@site-ux
133 +:
134 :END2
135
136 mv $pwfile $pwfile.preNIS
137 mv $nispwfile $pwfile
138 chmod 444 $pwfile
139 chown root:other $pwfile
140
141 /bin/cat >> $nisgrpfile <<:GRPEND
142 root:*:0:root
143 other:*:1:root,hpdb
144 bin:*:2:root,bin
145 sys:*:3:root,uucp
146 adm:*:4:root,adm
147 daemon:*:5:root,daemon
148 mail:*:6:root
149 lp::7:root,lp
150 nogroup:*:-2:
151 +:
152 :GRPEND
153
154 mv $grpfile $grpfile-preNIS
155 mv $nisgrpfile $grpfile
156 chmod 444 $grpfile
157 chown bin:bin $grpfile
158
159 # Start the NIS Client daemons
160 /sbin/init.d/nis.client start >> $logfile 2>&1
161 if [ $? -ne 0 ]; then
162         error "Problem starting the NIS client daemons... Exiting."
163 fi
164
165 # Email us that a machine was updated
166 /usr/bin/mailx -s "$(uname -n): NIS setup complete" $admin < $null