-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcf-runwrapper.sh
executable file
·178 lines (162 loc) · 3.13 KB
/
cf-runwrapper.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
#!/bin/sh
##############################################################################
#
# cf-runwrapper.sh
#
# Copyright (C) cfengineers.net
#
# Written and maintained by Jon Henrik Bjornstad <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
##############################################################################
# CONTROLWORD is the first bundle in the bundlesequence. It should be on the following format
# [PROMISES|UPDATE|FAILSAFE]_[QUIET|VERBOSE|INFORM]_[DRYRUN|NODRYRUN]_[NOLOCK|LOCK]
# eg.
# PROMISES_VERBOSE_NODRYRUN_NOLOCK
PROGNAME=`basename $0`
CONTROLWORD=""
OPTIONS=""
BUNDLES=""
COMMAND=""
TYPE="PROMISES"
OUTPUT="QUIET"
DRYRUN="NODRYRUN"
LOCK="LOCK"
WORKDIR=""
UID=0
if [ -x "/var/cfengine/bin/cf-agent" ]; then
COMMAND="/var/cfengine/bin/cf-agent"
elif [ -x "/usr/local/sbin/cf-agent" ]; then
COMMAND="/usr/local/sbin/cf-agent"
elif [ -x "/usr/local/bin/cf-agent" ]; then
COMMAND="/usr/local/bin/cf-agent"
else
exit 1
fi
if [ $UID -eq 0 ]; then
WORKDIR="/var/cfengine"
else
WORKDIR="$HOME/.cfagent"
fi
# getopts string I-: is for the script to accept --inform and -I that might get
# automatically added by cf-serverd/cf-runagent
while getopts b:D:I-: arg; do
case $arg in
b)
BUNDLES_PASSED=$OPTARG
;;
D)
CLASSES_PASSED=$OPTARG
;;
\?)
#echo "ERROR - invalid arg"
#exit 1
;;
esac
done
OLDIFS=$IFS
IFS=","
ITER=0
for i in $BUNDLES_PASSED; do
if [ $ITER -gt 0 ]; then
if [ "x${BUNDLES}" = "x" ]; then
BUNDLES=$i
else
BUNDLES="$BUNDLES,$i"
fi
else
CONTROLWORD=$i
fi
ITER=`expr $ITER + 1`
done
IFS=$OLDIFS
if [ "x${BUNDLES}" != "x" ]; then
OPTIONS="$OPTIONS --bundlesequence $BUNDLES"
fi
if [ "x${CLASSES_PASSED}" != "x" ]; then
OPTIONS="$OPTIONS --define $CLASSES_PASSED"
fi
OLDIFS=$IFS
IFS="_"
ITER=0
for i in $CONTROLWORD; do
if [ $ITER -eq 0 ]; then
TYPE=$i
elif [ $ITER -eq 1 ]; then
OUTPUT=$i
elif [ $ITER -eq 2 ]; then
DRYRUN=$i
elif [ $ITER -eq 3 ]; then
LOCK=$i
fi
ITER=`expr $ITER + 1`
done
IFS=$OLDIFS
case $TYPE in
UPDATE)
if [ -f "$WORKDIR/inputs/update.cf" ]; then
OPTIONS="$OPTIONS --file update.cf"
else
exit 1
fi
;;
FAILSAFE)
if [ -f "$WORKDIR/inputs/failsafe.cf" ]; then
OPTIONS="$OPTIONS --file failsafe.cf"
else
exit 1
fi
;;
PROMISES)
if [ -f "$WORKDIR/inputs/promises.cf" ]; then
OPTIONS="$OPTIONS"
else
exit 1
fi
;;
*)
exit 1
;;
esac
case $OUTPUT in
VERBOSE)
OPTIONS="$OPTIONS --verbose"
;;
INFORM)
OPTIONS="$OPTIONS --inform"
;;
QUIET)
;;
*)
exit 1
;;
esac
case $DRYRUN in
DRYRUN)
OPTIONS="$OPTIONS --dry-run"
;;
NODRYRUN)
;;
*)
exit 1
;;
esac
case $LOCK in
NOLOCK)
OPTIONS="$OPTIONS --no-lock"
;;
LOCK)
;;
*)
exit 1
;;
esac
$COMMAND $OPTIONS