Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / make_motd
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         whosdown
5 # Description:  Pings machines listed in machines database and produces a report
6 #               about which machines are down
7 # Author:       Andrew@DeFaria.com
8 # Created:      Thu Oct  5 09:32:21 PDT 2000
9 # Language:     Korn Shell
10 #
11 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
12 #
13 ################################################################################
14 # Set me to command name
15 me=$(basename $0)
16
17 # Set adm_base
18 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
19
20 # Set adm_fpath
21 adm_fpath=${adm_fpath:-$adm_base/functions}
22
23 # Source functions
24 . $adm_fpath/common
25
26 # Set OS
27 OS=$(uname -s | sed 's/CYGWIN_//')
28
29 uname=$(uname -a | tr [:upper:] [:lower:])
30
31 function usage {
32   display "$me [-v|verbose] [-d|debug] [-usage]"
33   display "        -v|verbose:     Turns on verbose mode"
34   display "        -d|debug:       Turns on debug mode"
35   display "        -usage:         Print this usage message"
36   display " "
37   display "The following options will be prompted for if not supplied on the"
38   display "command line. If any parameter has spaces in it then you need to"
39   display "surround it in quotes (e.g. -owners_fullname \"Andrew DeFaria\"."
40   display "You'll probably need to do this for the first 3 in the list below:"
41   display " "
42   display "     -owners_fullname  Specify owners full name"
43   display "     -machine_usage    Specify what this machine is to be used for"
44   display "     -location         Specify where this machine is located"
45   display "     -owners_email     Specify email address (no @salira.com)"
46   display "     -owners_extension Specify phone extenstion"
47   display
48
49   error "$1"
50   exit 1
51 } # usage
52
53 function display_options {
54   display "Setup this machine according to the following profile:"
55   display --------------------------------------------------------------------------------
56   display "Machine Name:\t\t$machine_name"
57   display "Machine Usage:\t\t$machine_usage"
58   display "Machine Location:\t$location"
59   display "Owner's Fullname:\t$owners_fullname"
60   display "Owner's Email:\t\t$owners_email@Salira.com"
61   display "Owner's Extension:\t$owners_extension"
62 } # display_options
63
64 function prompt_for_options {
65   # Prompt for options not specified on the command line
66   if [ "_$owners_fullname" = "_" -o "$owners_fullname" = "Unknown" ]; then
67     echo -e "Owner's Fullname"
68     echo -e "> \c"
69     read owners_fullname
70     if [ "_$owners_fullname" = "_" ]; then
71       owners_fullname=Unknown
72     fi
73   fi
74
75   if [ "_$machine_usage" = "_" -o "$machine_usage" = "Unknown" ]; then
76     echo -e "What is this machine used for?"
77     echo -e "> \c"
78     read machine_usage
79     if [ "_$machine_usage" = "_" ]; then
80       machine_usage=Unknown
81     fi
82   fi
83
84   if [ "_$location" = "_" -o "$location" = "Unknown" ]; then
85     echo -e "Where is this machine located?"
86     echo -e "> \c"
87     read location
88     if [ "_$location" = "_" ]; then
89       location=Unknown
90     fi
91   fi
92
93   if [ "_$owners_email" = "_" -o "$owners_email" = "Unknown" ]; then
94     echo -e "Owner's Email address:"
95     echo -e "(Should be the same as username. This script will supply the @salira.com)"
96     echo -e "> \c"
97     read owners_email
98     if [ "_$owners_email" = "_" ]; then
99       owners_email=Unknown
100     fi
101   fi
102
103   if [ "_$owners_extension" = "_" -o "$owners_extension" = "Unknown" ]; then
104     echo -e "Owner's Phone extention:"
105     echo -e "(Should be of the format XXX)"
106     echo -e "> \c"
107     read owners_extension
108     if [ "_$owners_extension" = "_" ]; then
109       owners_extension=Unknown
110     fi
111   fi
112 } # prompt_for_options
113
114 # Set initial parm values
115 owners_fullname=Unknown
116 owners_email=Unknown
117 owners_extension=Unknown
118 machine_usage=Unknown
119 location=Unknown
120 machine_name=$(hostname | tr [:upper:] [:lower:])
121
122 # Get parameters
123 while [ $# -ge 1 ]; do
124   case "$1" in
125     -usage)
126       usage
127       ;;
128
129     -v|-verbose)
130       verbose=yes
131       ;;
132
133     -d|-debug)
134       debug=yes
135       ;;
136
137     -owners_fullname)
138       if [ $# -le 1 ]; then
139         usage "Owner's Full Name is not specified!"
140       fi
141       shift
142       owners_fullname="$1"
143       ;;
144
145     -machine_usage)
146       if [ $# -le 1 ]; then
147         usage "Machine Usage was not specified!"
148       fi
149       shift
150       machine_usage="$1"
151       ;;
152
153     -location)
154       if [ $# -le 1 ]; then
155         usage "Location was not specified!"
156       fi
157       shift
158       location="$1"
159       ;;
160
161     -owners_email)
162       if [ $# -le 1 ]; then
163         usage "Owner's Email was not specified!"
164       fi
165       shift
166       owners_email="$1"
167       ;;
168
169     -owners_extension)
170       if [ $# -le 1 ]; then
171         usage "Owner's Extention was not specified!"
172       fi
173       shift
174       owners_extension="$1"
175       ;;
176
177     *)
178       usage "Unrecognized parameter $1"
179       ;;
180   esac
181   shift
182 done
183
184 anwser="y"
185 until [ "$answer" = "done" ]; do
186   prompt_for_options
187   display_options
188
189   display
190   display "Correct (Y/n)?\c"
191
192   answer="y"
193   read answer
194     case "$answer" in
195       y|Y|yes|Yes|YES|"")
196         answer="done"
197       ;;
198
199       *)
200         owners_fullname=Unknown
201         owners_email=Unknown
202         owners_extension=Unknown
203         machine_usage=Unknown
204         location=Unknown
205     esac
206 done
207
208 echo "$uname" > /etc/motd
209 cat >> /etc/motd <<:END
210 -------------------------------------------------------------------------------
211 - This is a private system operated for Salira. Authorization from Salira     -
212 - management is required to use this system. Use by unauthorized persons is   -
213 - prohibited. For system support email: Support@Salira.com                    -
214 -------------------------------------------------------------------------------
215 Usage:    $machine_usage
216 Owner:    $owners_fullname <$owners_email@Salira.com>
217 Phone:    (408)-325-8700x$owners_extension
218 Location: $location
219 -------------------------------------------------------------------------------
220 :END