Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / nisclient-11.x
1 #!/bin/bash
2 ###############################################################################
3 # This script sets a machine up to be an NIS client.
4 # Kevin Lister 10.28.98
5 ###############################################################################
6
7 # Variables
8 logfile=/nisclient.log
9 me=${0##*/}
10
11 admin=cll-support@cup.hp.com
12 nisdomain=cll
13 domainname=
14 namesvrs=/etc/rc.config.d/namesvrs
15 nsswitch=/etc/nsswitch.conf
16 pwfile=/etc/passwd
17 lclpwfile=/etc/passwd.loc
18 nispwfile=/etc/passwd.nis
19 crontab=/var/spool/cron/crontabs/root
20 newcrontab=/tmp/root-crontab
21 null=/dev/null
22 ypdir=/var/yp
23
24 # Functions
25 function error {
26   print -u2 "$me: Error: $1"
27   /usr/bin/mailx -s "$(uname -n): NIS setup error: $1" $admin < $null
28   #exit 255;
29 } # error
30
31 function warning {
32   print -u2 "$me: Warning: $1"
33 } # warning
34
35 function display {
36   print "$1"
37 } # display
38
39 function info {
40   display "$me: Info: $1"
41 } # info
42
43 ##
44 ########## Main
45 ##
46
47 ##
48 ########## Check the status of the system before proceeding
49 ##
50
51 # Must be root to run this
52 if [ $(id -u) -ne 0 ]; then
53         error "Must be root to execute this command... Exiting."
54 fi
55
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"
59 fi
60
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."
65 fi
66
67 # Are we already running NIS?
68 /usr/bin/ypwhich >> $logfile 2>&1
69 if [ $? -eq 0 ]; then
70         error "This system is already running NIS... Exiting."
71 fi
72
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."
76 fi
77
78 # Check to see if /var/yp exists
79 if [ ! -a $ypdir ]; then
80         error "Directory /var/yp does not exist... Exiting"
81 fi
82
83 ##
84 ########## System checks out. Set up the files and start NIS.
85 ##
86
87 # Set the NIS domain name - This is probably not needed
88 /bin/domainname $nisdomain >> $logfile 2>&1
89 if [ $? -ne 0 ]; then
90         error "Could not set NIS domain name... Exiting."
91 fi
92
93 # Setup the /etc/rc.config.d/namesvrs file
94 /usr/sbin/ch_rc -ap NIS_CLIENT=1 \
95        -p NIS_DOMAIN=cll \
96        -p YPBIND_OPTIONS="-ypsetme"
97
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
101 fi
102
103 # Create NIS passwd file
104 if [ -a $lclpwfile ]; then
105         /bin/grep "^root" $lclpwfile > $nispwfile
106 else
107         /bin/grep "^root" $pwfile > $nispwfile
108 fi
109
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
122 :END
123
124 /bin/grep -v "^root" $lclpwfile >> $nispwfile
125
126 /bin/cat >> $nispwfile <<:END2
127 -@dangerous-users
128 +@sysadmin
129 +@site-ux
130 +:
131 :END2
132
133 mv $pwfile $pwfile.preNIS
134 mv $nispwfile $pwfile
135 chmod 444 $pwfile
136 chown root:other $pwfile
137
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
142 chmod 444 $crontab
143 chown root:other $crontab
144
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."
149 fi
150
151 # Email us that a machine was updated
152 /usr/bin/mailx -s "$(uname -n): NIS setup complete" $admin < $null