Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
192 - 1
#!/bin/sh
2
##########################################################
3
# Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
4
#
5
# This program is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU Lesser General Public License as published
7
# by the Free Software Foundation version 2.1 and no later version.
8
#
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11
# or FITNESS FOR A PARTICULAR PURPOSE.  See the Lesser GNU General Public
12
# License for more details.
13
#
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with this program; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
17
#
18
##########################################################
19
 
20
##########################################################################
21
# DO NOT modify this file directly as it will be overwritten the next
22
# time the VMware Tools are installed.
23
##########################################################################
24
 
25
#
26
# statechange.sh
27
#
28
# This script is a refactored version of the legacy power scripts (e.g.,
29
# poweron-vm-default).  It expects to be installed in their places --
30
# in other words, `basename "$0"` might be poweron-vm-default.
31
#
32
# Handy reference/shorthand used in this doc/scripts:
33
#    TOOLS_CONFDIR ::= Depends on platform and installation settings.  Likely
34
#                      "/etc/vmware-tools" or
35
#                      "/Library/Application Support/VMware Tools"
36
#    powerOp       ::= One of "poweron-vm", "poweroff-vm", "suspend-vm", and
37
#                      "resume-vm".
38
#    vmwScriptDir  ::= $TOOLS_CONFDIR/scripts/vmware
39
#    userScriptDir ::= $TOOLS_CONFDIR/scripts/${powerOp}-default.d
40
#
41
# End users may install scripts of their own under $userScriptDir.  They
42
# are executed in alphabetical order with "$powerOp" as the only argument.
43
#
44
# NB:  This directory layout remains to preserve backwards compatibility. End
45
# users are free to write a single script which uses its only parameter
46
# (${powerOp}) as a discriminator, and then install symlinks to it in each
47
# of the ${powerOp}-default.d directories.
48
#
49
# On power-on and resume, VMware's scripts execute before the end user's.  On
50
# suspend and power-off, the end user's execute before VMware's.  (This way,
51
# VMware stops services only after the user's scripts have finished their
52
# work, and conversely restores the same services before the user's scripts
53
# attempt to use them.)
54
#
55
# Should any script exit non-zero, only its value will be saved to exitCode.
56
# (Any further non-zero exits will have no effect on exitCode.)  This script
57
# exits with $exitCode.
58
#
59
# XXX Consider using the available/enabled pattern for VMware's scripts.
60
#
61
# XXX This should be staged as a single executable whereby the desired
62
# power operation is passed in as a parameter.  (I.e., one would run
63
# "/path/to/statechange.sh suspend-vm" rather than having to install
64
# statechange.sh as suspend-vm-default.)
65
#
66
 
67
echo `date` ": Executing '$0'"
68
 
69
# See above.
70
TOOLS_CONFDIR=`dirname "$0"`
71
export TOOLS_CONFDIR
72
 
73
# Pull in subroutines like Panic.
74
. "$TOOLS_CONFDIR"/statechange.subr
75
 
76
 
77
#
78
# RunScripts --
79
#
80
#    Executes scripts installed under $scriptDir.
81
#
82
# Side effects:
83
#    exitCode may be incremented.
84
#
85
 
86
RunScripts() {
87
   scriptDir="$1"
88
 
89
   if [ -d "$scriptDir" ]; then
90
      for scriptFile in "$scriptDir"/*; do
91
         if [ -x "$scriptFile" ]; then
92
            "$scriptFile" $powerOp
93
            exitCode=`expr $exitCode \| $?`
94
         fi
95
      done
96
   fi
97
}
98
 
99
 
100
#
101
# main --
102
#
103
#    Entry point.  See comments at top of file for details.
104
#
105
# Results:
106
#    Exits with $exitCode.
107
#
108
 
109
main() {
110
   # This is sanity checked in the case/esac bit below.
111
   powerOp=`basename "$0" | sed 's,-default,,'`
112
   exitCode=0
113
 
114
   vmwScriptDir="$TOOLS_CONFDIR/scripts/vmware"
115
   userScriptDir="$TOOLS_CONFDIR/scripts/${powerOp}-default.d"
116
 
117
   case "$powerOp" in
118
      poweron-vm|resume-vm)
119
         RunScripts "$vmwScriptDir"
120
         RunScripts "$userScriptDir"
121
         ;;
122
      poweroff-vm|suspend-vm)
123
         RunScripts "$userScriptDir"
124
         RunScripts "$vmwScriptDir"
125
         ;;
126
      *)
127
         Panic "Invalid argument: $powerOp"
128
         ;;
129
   esac
130
 
131
   return $exitCode
132
}
133
 
134
main