2 ###############################################################################
3 # This script sets a machine up to be an NIS client.
4 # Kevin Lister 10.28.98
5 ###############################################################################
10 admin=adl-support@cup.hp.com
13 namesvrs=/etc/rc.config.d/namesvrs
14 nsswitch=/etc/nsswitch.conf
16 lclpwfile=/etc/passwd.loc
17 nispwfile=/etc/passwd-nis
19 nisgrpfile=/etc/group-nis
20 crontab=/var/spool/cron/crontabs/root
21 newcrontab=/tmp/root-crontab
27 print -u2 "$me: Error: $1"
28 /usr/bin/mailx -s "$(uname -n): NIS setup error: $1" $admin < $null
33 print -u2 "$me: Warning: $1"
41 display "$me: Info: $1"
49 ########## Check the status of the system before proceeding
52 # Must be root to run this
53 if [ $(id -u) -ne 0 ]; then
54 error "Must be root to execute this command... Exiting."
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"
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."
68 # Are we already running NIS?
69 /usr/bin/ypwhich >> $logfile 2>&1
71 error "This system is already running NIS... Exiting."
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...
80 # Check to see if /var/yp exists
81 if [ ! -a $ypdir ]; then
82 error "Directory /var/yp does not exist... Exiting"
86 ########## System checks out. Set up the files and start NIS.
89 # Set the NIS domain name - This is probably not needed
90 /bin/domainname $nisdomain >> $logfile 2>&1
92 error "Could not set NIS domain name... Exiting."
95 # Setup the /etc/rc.config.d/namesvrs file
96 /usr/sbin/ch_rc -ap NIS_CLIENT=1 \
98 -p WAIT_FOR_NIS_SERVER=FALSE
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"
106 # Create NIS passwd file
107 if [ -a $lclpwfile ]; then
108 /bin/grep "^root" $lclpwfile > $nispwfile
110 /bin/grep "^root" $pwfile > $nispwfile
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
127 /bin/grep -v "^root" $lclpwfile >> $nispwfile
129 /bin/cat >> $nispwfile <<:END2
136 mv $pwfile $pwfile.preNIS
137 mv $nispwfile $pwfile
139 chown root:other $pwfile
141 /bin/cat >> $nisgrpfile <<:GRPEND
147 daemon:*:5:root,daemon
154 mv $grpfile $grpfile-preNIS
155 mv $nisgrpfile $grpfile
157 chown bin:bin $grpfile
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."
165 # Email us that a machine was updated
166 /usr/bin/mailx -s "$(uname -n): NIS setup complete" $admin < $null