-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_hw_tools.sh
356 lines (308 loc) · 16 KB
/
setup_hw_tools.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/bash
# Include common_functions.h
if [[ -s /maint/scripts/common_functions.h ]]; then
source /maint/scripts/common_functions.h
elif [[ -s common_functions.h ]]; then
source common_functions.h
else
echo "Critical dependency failure: unable to locate common_functions.h"
exit 1
fi
# Start logging if applicable
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 - Hardware Tools Installation" | $LOG1
fi
IMGSRVIP=`f_GetImageServerIP`
VENDOR=`f_GetVendor`
#VENDOR=IBM
case $VENDOR in
IBM) if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Detected IBM hardware." | $LOG1
fi
echo "Detected IBM hardware."
# See if Director is already installed
INSTALLED_VERSION=`rpm -qa | grep ISDCommonAgent | awk -F'-' '{print $2}'`
if [[ -n $INSTALLED_VERSION ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 IBM Director version $INSTALLED_VERSION is already installed. Uninstall manually if you wish to re-install." | $LOG1
fi
echo "IBM Director version $INSTALLED_VERSION is already installed. Uninstall manually if you wish to re-install."
exit 0
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 IBM Director will be installed." | $LOG1
fi
echo "IBM Director will be installed"
fi
# Set up some base locations
BASEURL="http://${IMGSRVIP}/hw_tools/IBM"
LOCALDIR=/maint/scripts/hw_tools/IBM
if [[ ! -d "$LOCALDIR" ]]; then mkdir -p "$LOCALDIR"; fi
# Get version information from the server
if [[ "`f_InDMZ`" != "TRUE" ]]; then
REMOTEVER=`wget -q ${BASEURL}/current.txt -O - | grep -i VERSION | awk -F'=' '{print $2}'`
else
if [[ -f /maint/.forceDIRSKIP ]]; then
echo "Warning: IBM Director install has been administratively bypassed by touching /maint/.forceDIRSKIP" | $LOG1
echo "Skipping Director install because /maint/.forceDIRSKIP"
exit 0
fi
if [[ ! -s "${LOCALDIR}/current.txt" ]]; then
echo "Warning: IBM Director must be installed manually in the DMZ" | $LOG1
echo "Warning: IBM Director must be installed manually in the DMZ"
echo " Copy the following files from the image server, and re-run:"
echo " http://${IMGSRVIP}/hw_tools/IBM/current.txt -> /maint/scripts/hw_tools/IBM"
echo " http://${IMGSRVIP}/hw_tools/IBM/<Common Agent Tarball> -> /maint/scripts/hw_tools/IBM"
echo ""
echo " The <Common Agent Tarball> filename can be determined by reading current.txt"
echo ""
echo "To bypass Director Install, touch the file /maint/.forceDIRSKIP"
exit 20
fi
fi
# Get version information from the server
REMOTEVER=`wget -q ${BASEURL}/current.txt -O - | grep -i VERSION | awk -F'=' '{print $2}'`
if [[ -s "${LOCALDIR}/current.txt" ]]; then
LOCALVER=`grep -i ^VERSION "${LOCALDIR}/current.txt" | awk -F'=' '{print $2}'`
fi
if [[ -z $LOCALVER ]] && [[ -z $REMOTEVER ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Fatal Error: unable to get version information from ${LOCALDIR}/current.txt" | $LOG1
fi
echo "Fatal Error: unable to get version information from ${LOCALDIR}/current.txt"
exit 15
fi
# See if we need to download a new copy from the image server
if [[ -n $REMOTEVER ]] && [[ "$LOCALVER" != "$REMOTEVER" ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Detected different version of Director on image server, downloading..." | $LOG1
fi
echo "Detected different version of Director on image server, downloading..."
wget --progress=bar:force "${BASEURL}/${REMOTEVER}" -O "${LOCALDIR}/${REMOTEVER}" 2>&1 | f_WgetProgOnly
# If we successfully downloaded a new copy then make that the version we'll attempt to install
if [[ -s "${LOCALDIR}/${REMOTEVER}" ]]; then
LOCALVER=$REMOTEVER
echo "VERSION=${LOCALVER}" > "${LOCALDIR}/current.txt"
fi
fi
# Determine what server we're going to use
HCSERVLIST="10.27.115.96 10.70.1.14 10.27.115.25"
RSERVLIST=`wget -q ${BASEURL}/servlist.txt -O - | grep -i VERSION | awk -F'=' '{print $2}'`
if [[ -n "$RSERVLIST" ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Using Director Server list from $IMGSRVIP" | $LOG1
fi
echo "Using Director Server list from $IMGSRVIP"
SERVLIST=$RSERVLIST
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Using hard-coded Director Server List" | $LOG1
fi
echo "Using hard-coded Director Server List."
SERVLIST=$HCSERVLIST
fi
# Elect a Director Server
TMPLST=/tmp/dlist.${TS}
if [[ -f $TMPLST ]]; then /bin/rm $TMPLST; fi
best=
besttime=
for s in $SERVLIST; do
tput cuu1; tput el
echo -n "Checking server $s"
# Collect the average of 4 pings
time=`ping -q -c4 $s | grep rtt | awk '{print $4}' | awk -F'/' '{print $2}'`
echo "...ping time $time"
echo "$s,$time" >> $TMPLST
if [[ -z $besttime ]] || ( [[ -n $time ]] && [[ $time < $besttime ]] ); then
best=$s
besttime=$time
fi
done
if [[ -n $best ]]; then
EDIRIP=$best
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Elected Director Server IP ${EDIRIP}" | $LOG1
fi
echo "Elected Director Server IP ${EDIRIP}"
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Failure - no Director servers were reachable" | $LOG1
fi
echo "Failure - no Director servers were reachable"
exit 16
fi
# Unpack the agent tarball
DIR_TARBALL="${LOCALDIR}/${LOCALVER}"
SCRIPTNAME=`tar -tzf "$DIR_TARBALL" | grep "commonagent_linux" | head -1`
SCRIPTPATH="${LOCALDIR}/${SCRIPTNAME}"
if [[ -f "$SCRIPTPATH" ]]; then /bin/rm $SCRIPTPATH; fi
tar -C "${LOCALDIR}" -xzf "${DIR_TARBALL}" "${SCRIPTNAME}"
if [[ -s "$SCRIPTPATH" ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Unpacked Installer to $SCRIPTPATH" | $LOG1
fi
echo "Unpacked Installer to $SCRIPTPATH"
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Failure - unable to extract installer" | $LOG1
fi
echo "Failure - unable to extract installer"
exit 17
fi
# Create a diragent.rsp file
#/opt/ibm/director/agent/runtime/agent/toolkit/bin/configure.sh -amhost 10.27.115.96 -passwd D1r3ct0r!
RESPF="${LOCALDIR}/diragent.rsp"
echo "DEBUG_RPM=0" > $RESPF
echo "DEBUG_SCRIPTS=0" >> $RESPF
echo "FORCE=0" >> $RESPF
echo "LOGGING=1" >> $RESPF
echo "EXTRACT_ONLY=0" >> $RESPF
echo "INTERACTIVE=0" >> $RESPF
echo "AGENT_PORT=9510" >> $RESPF
echo "AGENT_NONSTOP_PORT_1=9514" >> $RESPF
echo "AGENT_NONSTOP_PORT_2=9515" >> $RESPF
echo "RPM_PATH=" >> $RESPF
echo "AGENT_MANAGER_HOSTNAME=${EDIRIP}" >> $RESPF
echo "AGENT_MANAGER_PASSWORD=D1r3ct0r!" >> $RESPF
# Install the agent with the diragent.rsp file
DIRINSTLOG=/var/log/install/ibm-director-install.log
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Beginning IBM Director Install - details will be logged at $DIRINSTLOG" | $LOG1
fi
echo "Beginning IBM Director Install - details will be logged at $DIRINSTLOG"
echo " Please be patient, this may take several minutes..."
# Begin logging
echo "" >> $DIRINSTLOG
echo "Beginning IBM Director Install `date`" >> $DIRINSTLOG
$SCRIPTPATH -i -r $RESPF >> $DIRINSTLOG 2>&1
RESULT=$?
# Double-check if the installation succeeded
INSTALLED_VERSION=`rpm -qa | grep ISDCommonAgent | awk -F'-' '{print $2}'`
# Report results
if [[ $RESULT != 0 ]] || [[ -z $INSTALLED_VERSION ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Failure: IBM Director has not been installed: see log for details" | $LOG1
fi
echo "Failure: IBM Director has not been installed: see log for details"
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 IBM Director installation succeeded." | $LOG1
fi
#echo "IBM Director installation succeeded - please log in to Director Server ${EDIRIP} to complete discovery."
echo "IBM Director installation succeeded - registering agent with ${EDIRIP} director server."
/opt/ibm/director/agent/runtime/agent/toolkit/bin/configure.sh -amhost ${EDIRIP} -passwd D1r3ct0r! >> $LOG1
# Server Statement of Origin
SSO=/etc/sso
echo "IBM_DIRECTOR_SERVER=${EDIRIP}" >> $SSO
fi
;;
HP) if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Detected HP hardware. Insight Agent will be installed." | $LOG1
fi
echo "Detected HP hardware. Insight Agent will be installed."
BASEURL="http://${IMGSRVIP}/hw_tools/HP"
LOCALDIR=/maint/scripts/hw_tools/HP
;;
VMWARE) if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Detected VMWare Virtual Machine." | $LOG1
fi
echo "Detected VMWare Virtual Machine."
# Check to see if VMware-tools is already installed
VMTM=/etc/vmware-tools/manifest.txt.shipped
if [[ -s $VMTM ]]; then
INSTALLED_VERSION=`grep "^vmtoolsd.version" $VMTM | awk -F '"' '{print $2}'`
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 VMTools version $INSTALLED_VERSION is already installed. Use /etc/vmware-tools/installer.sh uninstall if you wish to re-install." | $LOG1
fi
echo "VMTools version $INSTALLED_VERSION is already installed. Use /etc/vmware-tools/installer.sh uninstall if you wish to re-install."
exit 0
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 VMTools will be installed." | $LOG1
fi
echo "VMTools will be installed."
fi
BASEURL="http://${IMGSRVIP}/hw_tools/VMWare"
LOCALDIR=/maint/scripts/hw_tools/VMWare
if [[ ! -d "$LOCALDIR" ]]; then mkdir -p "$LOCALDIR"; fi
# Get version information from the server
REMOTEVER=`wget -q ${BASEURL}/current.txt -O - | grep -i VERSION | awk -F'=' '{print $2}'`
LOCALVER=`grep -i ^VERSION "${LOCALDIR}/current.txt" 2>&1 | grep -v "No such" | awk -F'=' '{print $2}'`
if [[ -z $LOCALVER ]] && [[ -z $REMOTEVER ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Fatal Error: unable to get version information for VMTools" | $LOG1
fi
echo "Fatal Error: unable to get version information for VMTools"
exit 15
fi
# See if we need to download a new copy from the image server
if [[ -n $REMOTEVER ]] && [[ "$LOCALVER" != "$REMOTEVER" ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Detected different version of VMTools on image server, downloading..." | $LOG1
fi
echo "Detected different version of VMTools on image server, downloading..."
wget --progress=bar:force "${BASEURL}/${REMOTEVER}" -O "${LOCALDIR}/${REMOTEVER}" 2>&1 | f_WgetProgOnly
# If we successfully downloaded a new copy then make that the version we'll attempt to install
if [[ -s "${LOCALDIR}/${REMOTEVER}" ]]; then
LOCALVER=$REMOTEVER
echo "VERSION=${LOCALVER}" > "${LOCALDIR}/current.txt"
fi
fi
# Unpack and install
# Read the top of the tarred directory structure so we know where it will unpack
VMTOOLS_TARBALL="${LOCALDIR}/${LOCALVER}"
VMTOOLS_INSTLOG=/var/log/install/vmtools_install.log
TOPDIR=`tar -tzf $VMTOOLS_TARBALL 2>&1 | head -1 | tr -d '/' | awk '{print $1}'`
# Extracting Tarball
tar -xzf $VMTOOLS_TARBALL -C /tmp
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Starting VMTools install - logs will be written to $VMTOOLS_INSTLOG" | $LOG1
fi
echo "Starting VMTools install - logs will be written to $VMTOOLS_INSTLOG"
# Running installer
#/tmp/${TOPDIR}/vmware-install.pl --default EULA_AGREED=yes 2>&1 >> $VMTOOLS_INSTLOG
/tmp/${TOPDIR}/vmware-install.pl --default EULA_AGREED=yes >> $VMTOOLS_INSTLOG 2>&1
RESULT=$?
if [[ $RESULT != 0 ]]; then
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 Failure: VMTools installer exited with non-zero code [$RESULT] see log for details" | $LOG1
fi
echo "Failure: VMTools installer exited with non-zero code [$RESULT] see log for details"
else
if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 VMTools installation succeeded." | $LOG1
fi
echo "VMTools installation succeeded."
# Set time based on Host
/usr/bin/vmware-toolbox-cmd timesync enable
# Make sure NTP is off
if [[ -s /etc/init.d/ntpd ]]; then /sbin/chkconfig ntpd off; fi
if [[ -n `ps --no-header -C ntpd -o pid` ]]; then
/etc/init.d/ntpd stop
fi
fi
# Setup VMWare kernel modules to automatically attempt to rebuild after a
# kernel update.
if [[ -f /etc/vmware-tools/locations ]]; then
echo -n "Updating VMTools modules to auto-update: "
sed -i.bak 's/answer AUTO_KMODS_ENABLED_ANSWER no/answer AUTO_KMODS_ENABLED_ANSWER yes/g; s/answer AUTO_KMODS_ENABLED no/answer AUTO_KMODS_ENABLED yes/g' /etc/vmware-tools/locations
RESULT=$?
if [[ $RESULT != 0 ]]; then
echo "FAILURE!"
echo "Unable to edit the /etc/vmware-tools/locations file - see error code above."
else
echo "Success"
fi
else
echo "ERROR: Unable to set VMTools to automatically rebuild after kernel update."
fi
if [[ -f /etc/init.d/vmware-tools ]]; then
sed -i 's/\/usr\/bin\/tpvmlpd/#\/usr\/bin\/tpvmlpd/g' /etc/init.d/vmware-tools
fi
;;
*) if [[ -n $LOGFILE ]] && [[ -n $VTS ]]; then
echo "`$VTS`:$0 No tools for hardware vendor $VENDOR - nothing to do." | $LOG1
fi
echo "No tools for hardware vendor $VENDOR - nothing to do."
;;
esac