Added client work scripts
[clearscm.git] / clients / HP / bin / make_motd
1 #!/usr/bin/ksh
2
3 # Logfile
4 logfile=make_motd.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 unames=$(uname -s)
14 unamen=$(uname -n)
15 unamer=$(uname -r)
16 unamev=$(uname -v)
17 unamem=$(model)
18 unamei=$(uname -i)
19 unamel=$(uname -l)
20
21 # Set step_nbr
22 integer step_nbr=0
23
24 function error {
25   print -u2 "$me: Error: $1"
26 } # error
27
28 function warning {
29   print -u2 "$me: Warning: $1"
30 } # warning
31
32 function display {
33   print "$1"
34 } # display
35
36 function info {
37   display "$me: Info: $1"
38 } # info
39
40 function verbose {
41   if [ ! -z "$verbose" ]; then
42     display "$1"
43   fi
44 } # verbose
45
46 function debug {
47   if [ ! -z "$debug" ]; then
48     print -u2 "$me: Debug: $1"
49   fi
50 } # debug
51
52 function usage {
53   display "$me [-v|verbose] [-d|debug] [-usage]"
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 display_options {
81   display "Setup this machine according to the following profile:"
82   print  -
83 --------------------------------------------------------------------------------
84
85   display "Machine Name:\t\t$new_machine_name"
86   display "Machine Usage:\t\t$machine_usage"
87   display "Macine Location:\t$location"
88   display "Owner's Fullname:\t$owners_fullname"
89   display "Owner's Email:\t\t$owners_email"
90   display "Owner's Extension:\t$owners_extension"
91 } # display_options
92
93 # Set initial parm values
94 display
95 display "\t\tWelcome to the motd creation script"
96 display
97 verbose=
98 debug=
99 owners_fullname=
100 owners_email=
101 owners_extension=
102 machine_usage=
103 location=
104 new_machine_name=
105
106 if [ $(id -u) -ne 0 ]; then
107         error "Must be root to create or modify /etc/motd"
108         exit 1
109 fi
110
111 # Get parameters
112 while [ $# -ge 1 ]; do
113   case "$1" in
114     -usage)
115       usage
116       ;;
117
118     -v|-verbose)
119       verbose=yes
120       ;;
121
122     -d|-debug)
123       debug=yes
124       ;;
125
126     -owners_fullname)
127       if [ $# -le 1 ]; then
128         usage "Owner's Full Name is not specified!"
129       fi
130       shift
131       owners_fullname="$1"
132       ;;
133
134     -machine_usage)
135       if [ $# -le 1 ]; then
136         usage "Machine Usage was not specified!"
137       fi
138       shift
139       machine_usage="$1"
140       ;;
141
142     -location)
143       if [ $# -le 1 ]; then
144         usage "Location was not specified!"
145       fi
146       shift
147       location="$1"
148       ;;
149
150     -owners_email)
151       if [ $# -le 1 ]; then
152         usage "Owner's Email was not specified!"
153       fi
154       shift
155       owners_email="$1"
156       ;;
157
158     -owners_extension)
159       if [ $# -le 1 ]; then
160         usage "Owner's Extention was not specified!"
161       fi
162       shift
163       owners_extension="$1"
164       ;;
165
166     -new_machine_name)
167       if [ $# -le 1 ]; then
168         usage "New Machine Name not specified!"
169       fi
170       shift
171       new_machine_name="$1"
172       ;;
173
174     *)
175       usage "Unrecognized parameter $1"
176       ;;
177   esac
178   shift
179 done
180
181 # Prompt for options not specified on the command line
182
183 if [ "_$owners_fullname" = "_" ]; then
184   print "Owner's Fullname"
185   print "> \c"
186   read owners_fullname
187   if [ "_$owners_fullname" = "_" ]; then
188     owners_fullname=Unknown
189   fi
190 fi
191
192 if [ "_$machine_usage" = "_" ]; then
193   print "What is this machine used for?"
194   print "> \c"
195   read machine_usage
196   if [ "_$machine_usage" = "_" ]; then
197     machine_usage="This machine is used by \<whom\> for \<what\>"
198   fi
199 fi
200
201 if [ "_$location" = "_" ]; then
202   print "Where is this machine located?"
203   print "> \c"
204   read location
205   if [ "_$location" = "_" ]; then
206     location="\<Physical Location\>"
207   fi
208 fi
209
210 if [ "_$owners_email" = "_" ]; then
211   print "Owner's Email address:"
212   print "(Should be the same as username. This script will supply the @cup.hp.com)"
213   print "> \c"
214   read owners_email
215   if [ "_$owners_email" = "_" ]; then
216     owners_email=Unknown
217   fi
218 fi
219
220 if [ "_$owners_extension" = "_" ]; then
221   print "Owner's Phone extention:"
222   print "(Should be of the format 7-XXXX This script will prepend \"t-44\" to"
223   print "the entered extension)"
224   print "> \c"
225   read owners_extension
226   if [ "_$owners_extension" = "_" ]; then
227     owners_extension=7-XXXX
228   fi
229 fi
230
231 until [ "_$new_machine_name" != "_" ]; do
232   new_machine_name="garbage"
233   print "New machine name:"
234   print "> \c"
235   read new_machine_name
236
237   if [ "_$new_machine_name" = "_" ]; then
238     error "Must enter a new machine name"
239   fi
240 done
241
242 display_options
243
244 display
245 display "Continue Installation (Y/n)?\c"
246 answer=y
247 read answer
248 case "$answer" in
249   y|Y|yes|Yes|YES|"")
250     continue
251     ;;
252   *)
253     display "Installation aborted. Rerun $me if you wish to install again"
254     exit 1
255     ;;
256 esac
257
258 function do_installation {
259 #display_options
260
261 banner $new_machine_name > /etc/motd
262 echo $unames $unamen $unamer $unamev $unamem $unamei $unamel >> /etc/motd
263 cat >> /etc/motd <<:END
264
265 *******************************************************************************
266 * This is a private system operated for the Hewlett-Packard Company business. *
267 * Authorization from HP management is required to use this system.            *
268 * Use by unauthorized persons is prohibited.                                  *
269 *******************************************************************************
270 For System Support: Mon-Fri 8:00-5:00 Email (site-ux@cup.hp.com)
271 Phone: t-447-1212 After hours/weekend Pre-arrange: t-447-0629
272 -------------------------------------------------------------------------------
273 Usage:    $machine_usage
274 Owner:    $owners_fullname ($owners_email@cup.hp.com) Phone:
275 t-44$owners_extension
276 Location: $location
277 -------------------------------------------------------------------------------
278 :END
279
280 display "/etc/motd successfully created"
281
282 } # do_installation
283
284 do_installation | tee $logfile