Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / insert
1 #!/usr/bin/ksh
2
3 # Logfile
4 logfile=/new.system.1.log
5
6 ## Set global env variables
7 # Set me
8 me=${0##*/}
9
10 # Set OS
11 OS=$(uname -r | cut -c3-)
12
13 # Get configfiles from Bismol (IP address is used because the machine is not
14 # currently setup enough to know how to resolve bismol to an IP address)
15 configfiles_machine=15.0.96.154
16
17 # Set step_nbr
18 integer step_nbr=0
19
20 # Filename for configuration files
21 configfiles=${OS}configfiles.shar
22
23 function error {
24   print -u2 "$me: Error: $1"
25 } # error
26
27 function warning {
28   print -u2 "$me: Warning: $1"
29 } # warning
30
31 function display {
32   print "$1"
33 } # display
34
35 function info {
36   display "$me: Info: $1"
37 } # info
38
39 function verbose {
40   if [ ! -z "$verbose" ]; then
41     display "$1"
42   fi
43 } # verbose
44
45 function debug {
46   if [ ! -z "$debug" ]; then
47     print -u2 "$me: Debug: $1"
48   fi
49 } # debug
50
51 function usage {
52   display "$ME -c/learcase [-v|verbose] [-d|debug] [-usage]"
53   display "     -c/learcase     Perform ClearCase installation"
54   display "        -v|verbose:     Turns on verbose mode"
55   display "        -d|debug:       Turns on debug mode"
56   display "        -usage:         Print this usage message"
57   display " "
58   display "The following options will be prompted for if not supplied on the"
59   display "command line. If any parameter has spaces in it then you need to"
60   display "surround it in quotes (e.g. -owners_fullname \"Andrew DeFaria\"."
61   display "You'll probably need to do this for the first 3 in the list below:"
62   display " "
63   display "     -owners_fullname  Specify owners full name"
64   display "     -machine_usage    Specify what this machine is to be used for"
65   display "     -location         Specify where this machine is located"
66   display "     -owners_email     Specify email address (no @cup.hp.com)"
67   display "     -owners_extension Specify phone extenstion in the format of"
68   display "                       7-XXXX (the t-44 will be prepended)"
69   display "     -new_machine_name Specify the name of this system (REQUIRED)"
70
71   error "$1"
72   exit 1
73 } # usage
74
75 function step {
76   let step_nbr=step_nbr+1
77   display "Step #$step_nbr: $@"
78 } # step
79
80 function get_configfiles {
81   user=anonymous
82   passwd=$LOGNAME@$(uname -n).cup.hp.com
83   directory=pub/Configuration
84   cd /
85   ftp -n $configfiles_machine <<@EOD
86 user $user $passwd
87 cd $directory
88 get $configfiles
89 quit
90 @EOD
91
92   return $?
93 } # get_configfiles
94
95 function export_disks {
96   # First check to see if all local disks are exported
97   cut -f1 -d' ' /etc/xtab > /tmp/xtab
98   bdf -t hfs | grep "/dev" | grep -v "/stand" | awk '{print $NF}' >
99 /tmp/exports
100
101   if $(diff /tmp/exports /tmp/xtab > /dev/null 2>&1); then
102     verbose "All local disks exported"
103   else
104     verbose "Some local disks are not exported"
105     if [ "$mode" != "check" ]; then
106       verbose "Fixing the problem..."
107       cp /etc/exports /etc/exports.old
108       cp /tmp/exports /etc/exports
109       verbose "Exporting all disks..."
110       /usr/sbin/exportfs -a
111       verbose "Done"
112     fi
113   fi
114 } # export_disks
115
116 function display_options {
117   display "Setup this machine according to the following profile:"
118   print  -
119 --------------------------------------------------------------------------------
120
121   display "Clearcase:\t\t\c"
122   if [ "_$clearcase" = "_" ]; then
123     display "No"
124   else
125     display "Yes"
126   fi
127
128   display "Verbose Mode:\t\t\c"
129   if [ "_$verbose" = "_" ]; then
130     display "Off"
131   else
132     display "On"
133   fi
134
135   display "Debug Mode:\t\t\c"
136   if [ "_$debug" = "_" ]; then
137     display "Off"
138   else
139     display "On"
140   fi
141
142   display "Machine Name:\t\t$new_machine_name"
143   display "Machine Usage:\t\t$machine_usage"
144   display "Macine Location:\t$location"
145   display "Owner's Fullname:\t$owners_fullname"
146   display "Owner's Email:\t\t$owners_email"
147   display "Owner's Extension:\t$owners_extension"
148 } # display_options
149
150 # Set initial parm values
151 display
152 display "\t\tWelcome to the new system setup script"
153 display "\t\tThis is the first script of 4 that you"
154 display "\t\twill need to run to setup a new Virtual"
155 display "\t\tWorkstation Server or Buildpool Server."
156 display
157 clearcase=
158 verbose=
159 debug=
160 owners_fullname=
161 owners_email=
162 owners_extension=
163 machine_usage=
164 location=
165 new_machine_name=
166
167 # Get parameters
168 while [ $# -ge 1 ]; do
169   case "$1" in
170     -usage)
171       usage
172       ;;
173
174     -v|-verbose)
175       verbose=yes
176       ;;
177
178     -d|-debug)
179       debug=yes
180       ;;
181
182     -c|-clearcase)
183       clearcase=y
184       ;;
185
186     -owners_fullname)
187       if [ $# -le 1 ]; then
188         usage "Owner's Full Name is not specified!"
189       fi
190       shift
191       owners_fullname="$1"
192       ;;
193
194     -machine_usage)
195       if [ $# -le 1 ]; then
196         usage "Machine Usage was not specified!"
197       fi
198       shift
199       machine_usage="$1"
200       ;;
201
202     -location)
203       if [ $# -le 1 ]; then
204         usage "Location was not specified!"
205       fi
206       shift
207       location="$1"
208       ;;
209
210     -owners_email)
211       if [ $# -le 1 ]; then
212         usage "Owner's Email was not specified!"
213       fi
214       shift
215       owners_email="$1"
216       ;;
217
218     -owners_extension)
219       if [ $# -le 1 ]; then
220         usage "Owner's Extention was not specified!"
221       fi
222       shift
223       owners_extension="$1"
224       ;;
225
226     -new_machine_name)
227       if [ $# -le 1 ]; then
228         usage "New Machine Name not specified!"
229       fi
230       shift
231       new_machine_name="$1"
232       ;;
233
234     *)
235       usage "Unrecognized parameter $1"
236       ;;
237   esac
238   shift
239 done
240
241 # Prompt for options not specified on the command line
242
243 if [ "_$clearcase" = "_" ]; then
244   print "Do you wish to install Clearcase?"
245   print "[y/n]> \c"
246   read clearcase
247   if [ "_$clearcase" = "_" ]; then
248     error "You must specify y or n"
249     exit 1 fi
250 fi
251
252 if [ "_$owners_fullname" = "_" ]; then
253   print "Owner's Fullname"
254   print "> \c"
255   read owners_fullname
256   if [ "_$owners_fullname" = "_" ]; then
257     owners_fullname=Unknown
258   fi
259 fi
260
261 if [ "_$machine_usage" = "_" ]; then
262   print "What is this machine used for?"
263   print "> \c"
264   read machine_usage
265   if [ "_$machine_usage" = "_" ]; then
266     machine_usage="This machine is used by \<whom\> for \<what\>"
267   fi
268 fi
269
270 if [ "_$location" = "_" ]; then
271   print "Where is this machine located?"
272   print "> \c"
273   read location
274   if [ "_$location" = "_" ]; then
275     location="\<Physical Location\>"
276   fi
277 fi
278
279 if [ "_$owners_email" = "_" ]; then
280   print "Owner's Email address:"
281   print "(Should be the same as username. This script will supply the cup.hp.com)"
282   print "> \c"
283   read owners_email
284   if [ "_$owners_email" = "_" ]; then
285     owners_email=Unknown
286   fi
287 fi
288
289 if [ "_$owners_extension" = "_" ]; then
290   print "Owner's Phone extention:"
291   print "(Should be of the format 7-XXXX This script will prepend \"t-44\" to"
292   print "the entered extension)"
293   print "> \c"
294   read owners_extension
295   if [ "_$owners_extension" = "_" ]; then
296     owners_extension=7-XXXX
297   fi
298 fi
299
300 until [ "_$new_machine_name" != "_" ]; do
301   new_machine_name="garbage"
302   print "New machine name:"
303   print "> \c"
304   read new_machine_name
305
306   if [ "_$new_machine_name" = "_" ]; then
307     error "Must enter a new machine name"
308   fi
309 done
310
311 if [ $(id -u) -ne 0 ]; then
312   error "Must be root to execute this command"
313   exit 1
314 fi
315
316 display_options
317
318 display
319 display "Continue Installation (Y/n)?\c"
320 answer=y
321 read answer
322 case "$answer" in
323   y|Y|yes|Yes|YES|"")
324     continue
325     ;;
326   *)
327     display "Installation aborted. Rerun $me if you wish to install again"
328     exit 1
329     ;;
330 esac
331
332 function do_installation {
333 display_options
334
335 step "Get configuration files"
336
337 get_configfiles
338
339 if [ $? -ne 0 ]; then
340   error "Unable to ftp $configfiles from $configfiles_machine"
341   exit 1
342 fi
343
344 step "Unpack configuration files"
345
346 cd /
347 sh $configfiles >> $logfile 2>&1
348 rm -f $configfiles
349
350 step "Change GenericSysName in /etc/issue"
351
352 sed "s/GenericSysName/$new_machine_name/" /etc/issue > /etc/issue.new
353 mv /etc/issue /etc/issue.old
354 mv /etc/issue.new /etc/issue
355
356 step "Allow Access to at(1)"
357
358 touch /var/adm/cron/at.deny
359 rm -f /var/adm/cron/at.allow
360
361 step "Setup ClearCase Build Hosts File"
362 echo `uname -n` > /.bldhost.hppa
363 cat /etc/bldhost.hppa >> /.bldhost.hppa
364 rm /etc/bldhost.hppa
365
366 step "Symlink /nfs -> /net"
367
368 ln -s /net /nfs 2>> $logfile
369
370 step "Symlink /usr/preserve -> /var/preserve"
371
372 ln -s /var/preserve /usr/preserve 2>> $logfile
373
374 step "Setup Application Server"
375
376 /net/bismol/app/admin/bin/setup
377
378 step "Setup Mother of All Passwords (AKA MoA)"
379
380 /net/bismol/app/admin/bin/mkpass -f
381
382 step "Create /etc/motd"
383
384 banner $new_machine_name > /etc/motd
385 uname -a >> /etc/motd
386 cat >> /etc/motd <<:END
387
388 *******************************************************************************
389 * This is a private system operated for the Hewlett-Packard Company business. *
390 * Authorization from HP management is required to use this system.            *
391 * Use by unauthorized persons is prohibited.                                  *
392 *******************************************************************************
393 For System Support: Mon-Fri 8:00-5:00 Email (site-ux@cup.hp.com)
394 Phone: t-447-1212 After hours/weekend Pre-arrange: t-447-0629
395 -------------------------------------------------------------------------------
396 Usage:    $machine_usage
397 Owner:    $owners_fullname ($owners_email@cup.hp.com) Phone:
398 t-44$owners_extension
399 Location: $location
400 -------------------------------------------------------------------------------
401 :END
402
403 step "Edit /etc/gettydefs: Change \"Console login:\" to \"$new_machine_name login:\""
404
405 sed "s/Console Login:/$new_machine_name Login:/" /etc/gettydefs \
406   > /etc/gettydefs.new
407 mv /etc/gettydefs /etc/gettydefs.old
408 mv /etc/gettydefs.new /etc/gettydefs
409
410 step "Ninstalling lp, adm and net3 packages"
411
412 /usr/local/bin/ninstall -h bismol lp adm net3 >> $logfile 2>&1
413
414 step "Run netdaemon.dy"
415
416 /usr/adm/netdist/netdaemon.dy 2>> $logfile
417
418 step "Fix /usr/sbin/rlp"
419
420 chmod +x /usr/sbin/rlp
421
422 step "Install root crontab"
423
424 crontab /crontab.root >> $logfile 2>&1
425 rm -f /crontab.root
426
427 step "Allow usage of crontab for ordinary users"
428
429 touch /var/adm/cron/cron.deny
430 rm -f /var/adm/cron/cron.allow
431
432 if [ "$clearcase" = "y" ]; then
433   step "Make symlink for the Build Environment"
434
435   ln -s /CLO/BUILD_ENV/usr/lib /usr/shlib 2>> $logfile
436
437   step "Symlinking clearmake for parallel build support"
438
439   ln -s /usr/eclipse/bin/clearmake /usr/contrib/bin/clearmake
440 fi
441
442 step "Adjust nfsd/biod's"
443
444 integer nfsd=4
445 integer biod=4
446 case $(uname -m) in
447   9000/712|9000/715)
448     ;;
449
450   9000/755)
451     nfsd=24
452     biod=8
453     ;;
454
455   9000/780|9000/813|9000/829|9000/849|9000/889|9000/898)
456     nfsd=48
457     biod=16
458     ;;
459
460   *)
461      warning "Unknown machine model $(uname -m)!"
462      warning "Leaving nfsd/biod's as default"
463      ;;
464 esac
465
466 if [ $nfsd -ne 4 ]; then
467   cp /etc/rc.config.d/nfsconf /etc/rc.config.d/nfsconf.old
468   sed "s/NUM_NFSD=4/NUM_NFSD=$nfsd/" /etc/rc.config.d/nfsconf \
469    > /etc/rc.config.d/nfsconf.new
470   mv /etc/rc.config.d/nfsconf.new /etc/rc.config.d/nfsconf
471   sed "s/NUM_NFSIOD=4/NUM_NFSIOD=$biod/" /etc/rc.config.d/nfsconf \
472    > /etc/rc.config.d/nfsconf.new
473   mv /etc/rc.config.d/nfsconf.new /etc/rc.config.d/nfsconf
474 fi
475
476 step "Setting up for 9.x build environment"
477
478 mv /usr/lib/libisamstub.1 /usr/lib/libisamstub.0
479 cp /net/bismol/app/admin/lib/libisamstub.1 /usr/lib/libisamstub.1
480 chmod 555 /usr/lib/libisamstub.1
481 chown bin:bin /usr/lib/libisamstub.1
482
483 step "Setup DTS"
484
485 ln -s /net/bismol/aspirin/DTS /usr/DTS 2>> $logfile
486
487 step "Setup automounter to use hard mounts"
488
489 echo "/net -hosts -intr" > /etc/auto_master
490
491 step "Link /var/mail"
492
493 mv /var/mail /var/mail.orig
494 ln -s /net/cllmail/var/mail/ /var/mail
495
496 step "Fix Root's name entry in /etc/passwd.loc"
497
498 sed "s/Root user/Root\@$(uname -n)/" /etc/passwd.loc > /tmp/passwd.loc
499 mv /tmp/passwd.loc /etc/passwd.loc
500
501 step "Fix permissions on /dev/lan*"
502
503 chmod 644 /dev/lan*
504
505 step "Installing OptionalSoftware"
506
507 display
508 display "This step will take several minutes and then the machine will
509 reboot."
510 display "After the machine is back up continue with new.system.2."
511
512 /usr/sbin/swinstall
513         -s wampus:/Depots/$OS \
514         -x autoreboot=true \
515         OptionalSoftware \
516 >> $logfile 2>&1
517
518 info "Swinstall complete, system will reboot if there were no errors"
519
520 } # do_installation
521
522 do_installation | tee $logfile