2 ###############################################################################
3 # This script sets a machine up to be an NIS client.
4 # Kevin Lister 10.28.98
6 ###############################################################################
11 admin=cll-support@cup.hp.com
14 netnfsrc=/etc/netnfsrc
15 nsswitch=/etc/nsswitch.conf
17 lclpwfile=/etc/passwd.loc
18 nispwfile=/etc/passwd.nis
19 crontab=/usr/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...
79 # Check to see if /etc/yp exists
80 if [ ! -a $ypdir ]; then
81 error "Directory /etc/yp does not exist... Exiting"
85 ########## System checks out. Set up the files and start NIS.
88 # Set the NIS domain name - This is probably not needed
89 /bin/domainname $nisdomain >> $logfile 2>&1
91 error "Could not set NIS domain name... Exiting."
94 # Setup the /etc/netnfsrc file
95 mv $netnfsrc $netnfsrc.preNIS
96 cp $netnfsrc.preNIS $netnfsrc
97 sed -e "s/^NIS_CLIENT=0/NIS_CLIENT=1/" \
98 -e "s/^NISDOMAIN=/NISDOMAIN=cll/" \
99 < $netnfsrc > $netnfsrc-tmp
100 mv $netnfsrc-tmp $netnfsrc
102 chown bin:bin $netnfsrc
104 # Email us if there are local passwd entries other than root
105 if [ $( /bin/wc -l $lclpwfile | /usr/bin/cut -d " " -f 1) != "1" ]; then
106 /usr/bin/mailx -s "$(uname -n): passwd.loc has more than 1 line"
110 # Create NIS passwd file
111 if [ -a $lclpwfile ]; then
112 /bin/grep "^root" $lclpwfile > $nispwfile
114 /bin/grep "^root" $pwfile > $nispwfile
117 /bin/cat >> $nispwfile <<:END
118 adm:*:4:4:,_MoA_:/usr/adm:/bin/sh
119 anon:*:21:5:placeholder for future,_MoA_:/:/bin/sync
120 bin:*:2:2:,_MoA_:/bin:/bin/sh
121 daemon:*:1:5:,_MoA_:/:/bin/sh
122 ftp:*:24:5:Anonymous &,,,_LcL_:/home/ftp:/bin/sync
123 ftp:*:500:10:anonymous ftp,_MoA_:/home/ftp:/bin/false
124 lp:*:9:7:[Line Printer],,,,_MoA_:/usr/spool/lp:/bin/sh
125 nuucp:*:6:1:0000-uucp(0000),_MoA_:/usr/spool/uucppublic:/usr/lib/uucp/uucico
126 sync:*:20:1:,_MoA_:/:/bin/sync
127 tftp:*:510:1:Trivial FTP user,_MoA_:/usr/tftpdir:/bin/false
128 uucp:*:5:3:,_MoA_:/usr/spool/uucppublic:/usr/lib/uucp/uucico
129 who:*:90:1:,_MoA_:/:/bin/who
132 /bin/grep -v "^root" $lclpwfile >> $nispwfile
134 /bin/cat >> $nispwfile <<:END2
141 mv $pwfile $pwfile.preNIS
142 mv $nispwfile $pwfile
144 chown root:other $pwfile
146 # Remove MoA from the root crontab
147 sed -e "/MoA/d" -e "/mkpass/d" < $crontab > $newcrontab
148 mv $crontab $crontab-preNIS
149 /usr/bin/crontab $newcrontab
151 chown root:other $crontab
153 # Start the NIS Client daemons
154 /etc/ypbind -ypset >> $logfile 2>&1
156 /usr/bin/ypwhich >> $logfile 2>&1
157 if [ $? -ne 0 ]; then
158 error "Problem starting the NIS client daemons... Exiting."
161 # Create /net symlink if automounter is NOT running
162 /bin/ps -ef | /bin/grep automount | /bin/grep -v grep >> $logfile 2>&1
163 if [ $? -ne 0 ]; then
164 /bin/ln -s /nfs /net >> $logfile 2>&1
167 # Create symlinks to shells so new passwd file doesn't blow up
168 /bin/ln -s /bin/sh /usr/bin/sh
169 /bin/ln -s /bin/csh /usr/bin/csh
170 /bin/ln -s /bin/ksh /usr/bin/ksh
172 # Create symlinks to ypdir, not required, just friendlier
173 /bin/ln -s /usr/etc/yp /var/yp
175 # Email us that a machine was updated
176 /usr/bin/mailx -s "$(uname -n): NIS setup complete" $admin < $null