2 ###############################################################################
3 # This script sets a machine up to be an NIS client.
4 # Kevin Lister 10.28.98
5 ###############################################################################
11 admin=cll-support@cup.hp.com
14 namesvrs=/etc/rc.config.d/namesvrs
15 nsswitch=/etc/nsswitch.conf
17 lclpwfile=/etc/passwd.loc
18 nispwfile=/etc/passwd.nis
19 crontab=/var/spool/cron/crontabs/root
20 newcrontab=/tmp/root-crontab
26 print -u2 "$me: Error: $1"
27 /usr/bin/mailx -s "$(uname -n): NIS setup error: $1" $admin < $null
32 print -u2 "$me: Warning: $1"
40 display "$me: Info: $1"
48 ########## Check the status of the system before proceeding
51 # Must be root to run this
52 if [ $(id -u) -ne 0 ]; then
53 error "Must be root to execute this command... Exiting."
56 # Check to see if this script has already been ran
57 if [ -a $logfile ]; then
58 error "$me has already been ran on $(uname -n)... Exiting"
61 # Check to see if domainname has been set
62 domainname=`/bin/domainname`
63 if [ "_$domainname" != "_" ]; then
64 error "NIS Domain name is already set to -> $domainname... Exiting."
67 # Are we already running NIS?
68 /usr/bin/ypwhich >> $logfile 2>&1
70 error "This system is already running NIS... Exiting."
73 # Check to see if there is a name service switch config file
74 if [ -a $nsswitch ]; then
75 error "This system has a name service switch config file... Exiting."
78 # Check to see if /var/yp exists
79 if [ ! -a $ypdir ]; then
80 error "Directory /var/yp does not exist... Exiting"
84 ########## System checks out. Set up the files and start NIS.
87 # Set the NIS domain name - This is probably not needed
88 /bin/domainname $nisdomain >> $logfile 2>&1
90 error "Could not set NIS domain name... Exiting."
93 # Setup the /etc/rc.config.d/namesvrs file
94 /usr/sbin/ch_rc -ap NIS_CLIENT=1 \
96 -p YPBIND_OPTIONS="-ypsetme"
98 # Email us if there are local passwd entries other than root
99 if [ $( /bin/wc -l $lclpwfile | /bin/cut -d " " -f 1) != "1" ]; then
100 /usr/bin/mailx -s "$(uname -n): passwd.loc has more than 1 line" $admin < $lclpwfile
103 # Create NIS passwd file
104 if [ -a $lclpwfile ]; then
105 /bin/grep "^root" $lclpwfile > $nispwfile
107 /bin/grep "^root" $pwfile > $nispwfile
110 /bin/cat >> $nispwfile <<:END
111 adm:*:4:4::/usr/adm:/usr/bin/sh
112 anon:*:21:5:placeholder for future:/:/usr/bin/sync
113 bin:*:2:2::/usr/bin:/bin/sh
114 daemon:*:1:5::/:/usr/bin/sh
115 ftp:*:500:10:anonymous ftp:/home/ftp:/usr/bin/false
116 lp:*:9:7:[Line Printer]:/usr/spool/lp:/usr/bin/sh
117 nuucp:*:6:1:0000-uucp(0000):/usr/spool/uucppublic:/usr/lib/uucp/uucico
118 sync:*:20:1::/:/usr/bin/sync
119 tftp:*:510:1:Trivial FTP user:/usr/tftpdir:/usr/bin/false
120 uucp:*:5:3::/usr/spool/uucppublic:/usr/lib/uucp/uucico
121 who:*:90:1::/:/usr/bin/who
124 /bin/grep -v "^root" $lclpwfile >> $nispwfile
126 /bin/cat >> $nispwfile <<:END2
133 mv $pwfile $pwfile.preNIS
134 mv $nispwfile $pwfile
136 chown root:other $pwfile
138 # Remove MoA from the root crontab
139 sed -e "/MoA/d" -e "/mkpass/d" < $crontab > $newcrontab
140 mv $crontab $crontab-preNIS
141 /usr/bin/crontab $newcrontab
143 chown root:other $crontab
145 # Start the NIS Client daemons
146 /sbin/init.d/nis.client start >> $logfile 2>&1
147 if [ $? -ne 0 ]; then
148 error "Problem starting the NIS client daemons... Exiting."
151 # Email us that a machine was updated
152 /usr/bin/mailx -s "$(uname -n): NIS setup complete" $admin < $null