~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools-august.merge

« back to all changes in this revision

Viewing changes to scripts/common/vm-support

  • Committer: Bazaar Package Importer
  • Author(s): Nate Muench
  • Date: 2011-07-22 16:41:03 UTC
  • mfrom: (1.4.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110722164103-xci04yu18mjvhr1j
Tags: 2011.07.19-450511-0ubuntu1
* Merge latest upstream git tag. Fixes Building on Oneiric
  (LP: #776103, LP: #807903)

* The Toolbox (GUI) has been removed.
* Changes in debian folder:
  - Contents of open-vm-toolbox.lintian-overrides have been moved to
    open-vm-tools.lintian-overrides.
  - The contents of open-vm-toolbox.manpages (excluding the first line,
    which relates to the Toolbox) have been moved to open-vm-tools.manpages.
* Changes in debian/control:
  - Convert open-vm-toolbox into a transitional package.
  - All dependencies for toolbox have been moved to open-vm-tools package.
  - Changed architecture for open-vm-toolbox package to all.
  - Added Replaces and Breaks fields to open-vm-tools.
* Changes in debian/rules:
  - Commented out references to the Toolbox (GUI), that no longer exist
    in the package itself.
  - Remaining references changed from open-vm-toolbox to open-vm-tools.
  - Added -Wno-unused-but-set-variable to CFLAGS to suppress remaining
    issues with GCC 4.6.0 or later.
* Files removed in debian/manpages:
  - vmmemctl.9 (Component no longer in package)
  - vmware-toolbox.1 (Component removed in this release)
  - vmxnet3.9 (vmxnet3 is now included in kernel itself)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
 
1
#!/bin/sh
2
2
##########################################################
3
3
# Copyright (C) 2006-2010 VMware, Inc. All rights reserved.
4
4
#
17
17
#
18
18
##########################################################
19
19
 
20
 
 
21
 
 
22
 
#       Function: usage prints how to use this script
23
 
 
24
 
function usage {
 
20
# usage(): prints how to use this script
 
21
usage()
 
22
{
25
23
        echo ""
26
24
        echo "Usage: $0 [-h]"
27
25
        echo "  -h prints this usage statement"
29
27
}
30
28
 
31
29
 
32
 
TARFILE=vm-$(date -I).$$.tgz
33
 
VER=0.87
 
30
TARFILE=vm-`date +%Y-%m-%d`.$$.tar
 
31
VER=0.88
34
32
OUTPUT_DIR=vm-support.$$
35
33
 
36
 
#       Function: banner prints any number of strings padded with
37
 
#       newlines before and after.
38
 
 
39
 
function banner {
 
34
# banner(): prints any number of strings padded with
 
35
# newlines before and after.
 
36
banner()
 
37
{
40
38
        echo
41
39
        for option in "$@"
42
40
        do
45
43
        echo
46
44
}
47
45
 
48
 
#       The status constants are important and have to be kept
49
 
#       in sync with VMware Workstation implementation
 
46
# The status constants are important and have to be kept
 
47
# in sync with VMware Workstation implementation
50
48
 
51
49
#       vm-support script is not running
52
50
VMSUPPORT_NOT_RUNNING=0
64
62
#internal state machine state for update
65
63
update=0
66
64
 
67
 
#       Updates the VM with the current state
68
 
 
69
 
function UpdateState {
 
65
# UpdateState($state): Updates the VM with the given state.
 
66
UpdateState()
 
67
{
70
68
   if [ $update -eq 1 ]; then
71
69
     vmware-xferlogs upd $1
72
70
   fi
73
71
}
74
72
 
75
 
function UpdateSpinner {
76
 
        case $SPINNER in
77
 
                "|")
78
 
                        SPINNER="/"
79
 
                ;;
80
 
 
81
 
                "/")
82
 
                        SPINNER="-"
83
 
                ;;
84
 
 
85
 
                "-")
86
 
                        SPINNER="\\"
87
 
                ;;
88
 
 
89
 
                "\\")
90
 
                        SPINNER="|"
91
 
                ;;
92
 
 
93
 
                *)
94
 
                        SPINNER="|"
95
 
                ;;
96
 
        esac
97
 
        echo -en "\rPreparing Files: $SPINNER"
98
 
}
99
 
 
100
 
#       Function: addtar copies whatever files and directories you give it to
101
 
#       a self contained output directory for later tar'ing
102
 
#       Working on copies could slow this down with VERY large files but:
103
 
#       1) We don't expect VERY large files
104
 
#       2) Since /proc files can be copied this preserves the tree without
105
 
#          having to cat them all into a file.
106
 
#       3) tar barfs on open files like logs if it changes while it's tar'ing.
107
 
#          Copying file first makes sure tar doesn't complain
108
 
 
109
 
 
110
 
function addtar {
111
 
        FILE=$1
112
 
 
113
 
        DIR=$(dirname "$FILE")
114
 
        if [ ! -d "${OUTPUT_DIR}$DIR" ]; then
115
 
                mkdir -p "${OUTPUT_DIR}$DIR"
116
 
 
117
 
                if [ $? != 0 ]; then
118
 
                        banner "Could not create ./${OUTPUT_DIR}$DIR... " \
119
 
                                "Have you run out of disk space?" "Continuing"
120
 
                        return
121
 
                fi
122
 
        fi
123
 
 
124
 
        # Ignore stdout and handle errors.
125
 
        UpdateSpinner
126
 
        cp -pr "$FILE" "${OUTPUT_DIR}$DIR" 2>/dev/null
127
 
 
128
 
        # We could have failed to copy for several reasons
129
 
        # If we path had a shell special character (* ? .)
130
 
        # or if the file is in /proc
131
 
        if [ $? != 0 ]; then
132
 
                FILENAME=${FILE##*/}
133
 
                for line in "$DIR"/$FILENAME
134
 
                do
135
 
                        if [ -e "$line" ]; then
136
 
                                # Ignore stdout and handle errors.
137
 
                                UpdateSpinner
138
 
                                cp -pr "$line" "${OUTPUT_DIR}$DIR" 2>/dev/null
139
 
 
140
 
                                # If a file from /proc does not copy,
141
 
                                # ignore - they're funny.
142
 
                                # Otherwise, exit for failed copy.
143
 
                                if [ $? != 0 ]; then
144
 
                                        echo "$line" | grep ^/proc > /dev/null
145
 
 
146
 
                                        if [ $? != 0 ]; then
147
 
                                                banner "Could not copy $line \
148
 
                                                        to the tar area."
149
 
                                                return
150
 
                                        fi      # Not proc
151
 
                                fi # is it proc
152
 
                        fi # does file exist
153
 
 
154
 
                done # for each file in the list
155
 
        fi # if copy failed
156
 
 
157
 
}
158
 
 
159
 
 
160
 
#       Function: runcmd executes the command ($1)
161
 
#       redirected to a file ($2) and then adds that
162
 
#       file to the list of files to tar.
163
 
#       It then deletes the temp file since addtar makes a copy in its own
164
 
#       selft contained area.
165
 
 
166
 
function runcmd {
 
73
# addfile(): copies whatever files and directories you give it to
 
74
# a self contained output directory for later tar'ing
 
75
# Working on copies could slow this down with VERY large files but:
 
76
# 1) We don't expect VERY large files
 
77
# 2) Since /proc files can be copied this preserves the tree without
 
78
#    having to cat them all into a file.
 
79
# 3) tar barfs on open files like logs if it changes while it's tar'ing.
 
80
#    Copying file first makes sure tar doesn't complain
 
81
addfile()
 
82
{
 
83
   file=$1
 
84
 
 
85
   dir=`dirname "$file"`
 
86
   if [ ! -d "${OUTPUT_DIR}$dir" ]; then
 
87
      mkdir -p "${OUTPUT_DIR}$dir"
 
88
 
 
89
      if [ $? != 0 ]; then
 
90
         banner "Could not create ./${OUTPUT_DIR}$dir... " \
 
91
                "Have you run out of disk space?" "Continuing"
 
92
         return
 
93
      fi
 
94
   fi
 
95
 
 
96
   # Ignore stdout and handle errors.
 
97
   cp -pRP "$file" "${OUTPUT_DIR}$dir" 2>/dev/null
 
98
   if [ $? != 0 ]; then
 
99
      banner "Could not copy '$file' to the tar area."
 
100
   fi
 
101
}
 
102
 
 
103
 
 
104
# addfiles(): adds a list of files to the archive.
 
105
addfiles()
 
106
{
 
107
   for i in "$@"; do
 
108
      addfile $i
 
109
   done
 
110
}
 
111
 
 
112
 
 
113
# runcmd($cmd, $out): executes the command redirected to a file and then adds
 
114
# that file to the list of files to tar. It then deletes the temp file since
 
115
# addfile makes a copy in its own self-contained area.
 
116
runcmd()
 
117
{
167
118
        $1 > $2 2>/dev/null
168
119
 
169
120
        if [ $? != 0 ]; then
 
121
           echo 3
170
122
                banner "Either could not run $1 or could not write to $2" \
171
 
"Do you have a full disk?" "Continuing..."
 
123
                       "Do you have a full disk? Continuing..."
172
124
        else
173
 
                addtar "$2"
174
 
                rm "$2"
175
 
 
176
 
                if [ $? != 0 ]; then
177
 
                        banner "Could not delete $2.  Continuing..."
178
 
                fi
 
125
                addfile "$2"
 
126
                rm -f "$2"
179
127
        fi
180
128
}
181
129
 
182
130
 
 
131
# error(): prints an error message using the "banner" funtion and quits.
 
132
error()
 
133
{
 
134
   banner "$@"
 
135
   UpdateState $VMSUPPORT_ERROR
 
136
   exit 1
 
137
}
 
138
 
183
139
# Parse args
184
140
for option in $@
185
141
do
186
 
        case $option in
187
 
                "-h")
188
 
                        usage
189
 
                ;;
190
 
                "-u")
191
 
                        update=1
192
 
                ;;
193
 
                *)
194
 
                        usage
195
 
                ;;
196
 
        esac
 
142
   case $option in
 
143
   "-h")
 
144
      usage
 
145
      ;;
 
146
   "-u")
 
147
      update=1
 
148
      ;;
 
149
   *)
 
150
      usage
 
151
      ;;
 
152
   esac
197
153
done
198
154
 
199
155
#       Start message
200
156
 
201
157
UpdateState $VMSUPPORT_BEGINNING
202
158
 
203
 
banner "VMware Linux Support Script $VER"
 
159
banner "VMware UNIX Support Script $VER"
204
160
 
205
161
#       Check for root privledge
206
162
 
207
 
if [ $(id -u) != "0" ]; then
208
 
        banner "You are not root, some system information can't be collected."
 
163
if [ `whoami` != 'root' ]; then
 
164
   banner "You are not root, some system information can't be collected."
209
165
fi
210
166
 
211
167
# Source /etc/profile.  If we can't find it, it's the users problem to get
212
168
# their paths straight.
213
 
 
214
169
if [ -f /etc/profile ]; then
215
170
        . /etc/profile
216
171
fi
217
172
 
218
173
# Protect against non-default values of $IFS (Not all scripts in /etc/profile.d/
219
174
# are good citizens).
220
 
unset IFS
 
175
if [ `uname` != 'SunOS' ]; then
 
176
   unset IFS 2>/dev/null
 
177
fi
221
178
 
222
179
#       make a subdir to put all your files in.  die if it does not create
223
180
mkdir $OUTPUT_DIR
224
181
 
225
182
if [ $? != 0 ]; then
226
 
        banner "Could not create ./${OUTPUT_DIR}... Exiting..." \
227
 
"Please cd to a directory to which you can write" # Thanks Adam!
228
 
        exit
229
 
fi
230
 
 
231
 
 
232
 
#       Add system configuration and log files. Wildcards
233
 
#       may be used.
234
 
 
235
 
 
236
 
# Try to collect bootloader config.
237
 
if [ -e /etc/lilo.conf ]; then
238
 
        addtar "/etc/lilo.conf"
239
 
fi
240
 
 
241
 
# And for grub we are not sure about the exact default location so collect them
242
 
# all.
243
 
if [ -e /boot/grub/grub.conf ]; then
244
 
        addtar "/boot/grub/grub.conf"
245
 
fi
246
 
if [ -e /boot/grub/menu.lst ]; then
247
 
        addtar "/boot/grub/menu.lst"
248
 
fi
249
 
if [ -e /etc/grub.conf ]; then
250
 
        addtar "/etc/grub.conf"
251
 
fi
252
 
 
253
 
addtar "/etc/crontab"
254
 
addtar "/etc/cron.daily"
255
 
addtar "/etc/cron.hourly"
256
 
addtar "/etc/cron.monthly"
257
 
addtar "/etc/cron.weekly"
258
 
addtar "/etc/modules.conf"
259
 
addtar "/etc/ntp.conf"
260
 
addtar "/etc/security/*"
261
 
 
262
 
 
263
 
# Add services
264
 
addtar "/etc/services"
265
 
 
266
 
addtar "/etc/vmware-tools/*"
267
 
addtar "/var/log/boot*"
268
 
addtar "/var/log/secure*"
269
 
addtar "/var/log/messages*"
270
 
addtar "/var/run/vmware-*"
271
 
 
272
 
# Add /proc with some exceptions.  stdout redirected to /dev/null.  Some files
273
 
# come and go and confuse find.  Just send whatever works and don't scare user.
274
 
 
275
 
for procfile in `find /proc -type f 2>/dev/null| egrep -v kcore\|kmsg\|acpi\|pagemap\|/proc/$$`
276
 
do
277
 
        addtar "$procfile"
278
 
done
279
 
 
280
 
#       Commands to run ($1) and redirect to logs ($2) for
281
 
#       inclusion.
282
 
 
 
183
        error "Could not create ./${OUTPUT_DIR}. Please cd to a directory to which "
 
184
              "you can write."
 
185
fi
 
186
 
 
187
banner "Collecting support information..."
 
188
 
 
189
# Common stuff that we gather for all OSes.
283
190
runcmd "echo vm-support version: $VER" "/tmp/vm-support-version.$$.txt"
284
 
runcmd "lspci -H1 -M" "/tmp/lspci1.$$.txt"
285
 
runcmd "lspci -H1 -M -vn" "/tmp/lspci2.$$.txt"
286
 
runcmd "/sbin/lsmod" "/tmp/modules.$$.txt"
287
 
runcmd "uname -a" "/tmp/uname.$$.txt"
 
191
 
 
192
addfiles /etc/vmware-tools
 
193
addfiles /var/log/boot*
 
194
addfiles /var/log/secure*
 
195
addfiles /var/log/messages*
 
196
addfiles /var/log/syslog*
 
197
addfiles /var/run/vmware-*
 
198
 
288
199
runcmd "df" "/tmp/df.$$.txt"
289
 
runcmd "cat /etc/issue" "/tmp/issue.$$.txt"
290
200
runcmd "ifconfig -a" "/tmp/ifconfig.$$.txt"
291
 
runcmd "rpm -qa" "/tmp/rpm-qa.$$.txt"
292
 
runcmd "netstat -lan" "/tmp/netstat-lan.$$.txt"
293
 
runcmd "route" "/tmp/route.$$.txt"
294
201
runcmd "mount" "/tmp/mount.$$.txt"
295
202
runcmd "dmesg" "/tmp/dmesg.$$.txt"
296
 
runcmd "free" "/tmp/free.$$.txt"
 
203
runcmd "ulimit -a" "/tmp/ulimit-a.$$.txt"
297
204
runcmd "uptime" "/tmp/uptime.$$.txt"
298
205
runcmd "date" "/tmp/date.$$.txt"
299
 
runcmd "ps auwwx" "/tmp/ps-auwwx.$$.txt"
300
 
runcmd "ulimit -a" "/tmp/ulimit-a.$$.txt"
301
206
runcmd "umask" "/tmp/umask.$$.txt"
302
207
 
 
208
 
 
209
# stageLinux(): gather information for troubleshooting Linux guests.
 
210
stageLinux()
 
211
{
 
212
   # Try to collect bootloader config.
 
213
   if [ -e /etc/lilo.conf ]; then
 
214
      addfiles /etc/lilo.conf
 
215
   fi
 
216
 
 
217
   # And for grub we are not sure about the exact default location so collect them
 
218
   # all.
 
219
   if [ -e /boot/grub/grub.conf ]; then
 
220
      addfile /boot/grub/grub.conf
 
221
   fi
 
222
   if [ -e /boot/grub/menu.lst ]; then
 
223
      addfile /boot/grub/menu.lst
 
224
   fi
 
225
   if [ -e /etc/grub.conf ]; then
 
226
      addfile /etc/grub.conf
 
227
   fi
 
228
 
 
229
   addfile /etc/cron.daily
 
230
   addfile /etc/cron.hourly
 
231
   addfile /etc/cron.monthly
 
232
   addfile /etc/cron.weekly
 
233
   addfile /etc/crontab
 
234
   addfile /etc/modules.conf
 
235
   addfile /etc/ntp.conf
 
236
   addfile /etc/security
 
237
   addfile /etc/services
 
238
 
 
239
   # Commands to run ($1) and redirect to logs ($2) for inclusion.
 
240
   runcmd "lspci -H1 -M" "/tmp/lspci1.$$.txt"
 
241
   runcmd "lspci -H1 -M -vn" "/tmp/lspci2.$$.txt"
 
242
   runcmd "/sbin/lsmod" "/tmp/modules.$$.txt"
 
243
   runcmd "uname -a" "/tmp/uname.$$.txt"
 
244
   runcmd "cat /etc/issue" "/tmp/issue.$$.txt"
 
245
   runcmd "rpm -qa" "/tmp/rpm-qa.$$.txt"
 
246
   runcmd "netstat -lan" "/tmp/netstat-lan.$$.txt"
 
247
   runcmd "route" "/tmp/route.$$.txt"
 
248
   runcmd "free" "/tmp/free.$$.txt"
 
249
}
 
250
 
 
251
 
 
252
# stageFreeBSD(): gather information for troubleshooting FreeBSD guests.
 
253
stageFreeBSD()
 
254
{
 
255
   runcmd "ps auwwx" "/tmp/ps-auwwx.$$.txt"
 
256
}
 
257
 
 
258
# stageSolaris(): gather information for troubleshooting Solaris guests.
 
259
stageSolaris()
 
260
{
 
261
   runcmd "ps eaf" "/tmp/ps-eaf.$$.txt"
 
262
}
 
263
 
 
264
case `uname` in
 
265
Linux)
 
266
   stageLinux
 
267
   #    tar options: 'S' for sparse core files.
 
268
   TAR_OPTS=-cSf
 
269
   ;;
 
270
FreeBSD)
 
271
   stageFreeBSD
 
272
   TAR_OPTS=-cf
 
273
   ;;
 
274
SunOS)
 
275
   stageSolaris
 
276
   TAR_OPTS=-cf
 
277
   ;;
 
278
esac
 
279
 
303
280
UpdateState $VMSUPPORT_RUNNING
304
281
 
305
 
 
306
 
#       Perform the tar ('S' for sparse core files)
307
 
 
308
 
tar -czSvf $TARFILE $OUTPUT_DIR
 
282
banner "Creating tar archive..."
 
283
tar $TAR_OPTS $TARFILE $OUTPUT_DIR
309
284
 
310
285
if [ $? != 0 ]; then
311
 
        banner "The tar did not successfully complete!" \
312
 
"If tar reports that a file changed while reading, please attempt to rerun this script."
 
286
        banner "The tar process did not successfully complete!" \
 
287
               "If tar reports that a file changed while reading, please attempt " \
 
288
               "to rerun this script."
313
289
fi
314
290
 
315
 
vmware-xferlogs enc $TARFILE &>/dev/null
 
291
gzip $TARFILE
 
292
TARFILE=${TARFILE}.gz
 
293
 
 
294
banner "Uploading archive to host..."
 
295
vmware-xferlogs enc $TARFILE 2>/dev/null
316
296
 
317
297
if [ $? != 0 ]; then
318
 
        banner "could not transmit logs successfully, either the xmitLogs"\
319
 
        "binary is not in the path, or you are not in a virtual machine"
 
298
   banner "Could not transmit logs successfully: either the vmware-xferlogs " \
 
299
          "binary is not in the path, or you are not in a virtual machine."
320
300
fi
321
301
 
322
302
#       Clean up temporary files
327
307
fi
328
308
 
329
309
UpdateState $VMSUPPORT_ENDING
 
310
banner "Done, support data available in '$TARFILE'."
330
311
 
331
 
#       End