@@ -42,6 +42,14 @@ bold() { printf "${bold}%s${reset}\n" "$@"
42
42
note () { printf " \n${underline}${bold}${blue} Note:${reset} ${blue} %s${reset} \n" " $@ "
43
43
}
44
44
45
+
46
+ type_exists () {
47
+ if [ $( type -P $1 ) ]; then
48
+ return 0
49
+ fi
50
+ return 1
51
+ }
52
+
45
53
jsonValue () {
46
54
key=$1
47
55
num=$2
78
86
# ----- Install AWS Cli -----
79
87
# see documentation : http://docs.aws.amazon.com/cli/latest/userguide/installing.html
80
88
# ---------------------------
81
- set -e
82
- h1 " Installing AWS CLI"
83
89
84
- INSTALL_AWSCLI=" sudo pip install awscli"
85
- info " $INSTALL_AWSCLI "
86
- INSTALL_AWSCLI_OUTPUT=$( $INSTALL_AWSCLI 2>&1 )
87
-
88
- success " Installing AWS CLI succeeded"
90
+ # Check AWS is installed
91
+ if ! type_exists ' aws' ; then
92
+ set -e
93
+ h1 " Installing AWS CLI"
94
+ INSTALL_AWSCLI=" sudo pip install awscli"
95
+ info " $INSTALL_AWSCLI "
96
+ INSTALL_AWSCLI_OUTPUT=$( $INSTALL_AWSCLI 2>&1 )
97
+ success " Installing AWS CLI succeeded"
98
+ set +e
99
+ fi
89
100
90
- set +e
91
101
# ----- Configure -----
92
102
# see documentation :
93
103
# http://docs.aws.amazon.com/cli/latest/reference/configure/index.html
@@ -100,7 +110,7 @@ h2 "Configuring AWS Access Key ID"
100
110
CONFIGURE_KEY_OUTPUT=$( aws configure set aws_access_key_id $WERCKER_AWS_CODE_DEPLOY_KEY 2>&1 )
101
111
success " Configuring AWS Access Key ID succeeded"
102
112
103
- h2 " Configuring AWS Access Key ID "
113
+ h2 " Configuring AWS Secret Access Key"
104
114
CONFIGURE_SECRET_OUTPUT=$( aws configure set aws_secret_access_key $WERCKER_AWS_CODE_DEPLOY_SECRET 2>&1 )
105
115
success " Configuring AWS Secret Access Key succeeded"
106
116
@@ -129,17 +139,16 @@ APPLICATION_EXISTS="aws deploy get-application --application-name $APPLICATION_N
129
139
info " $APPLICATION_EXISTS "
130
140
APPLICATION_EXISTS_OUTPUT=$( $APPLICATION_EXISTS 2>&1 )
131
141
132
- if [[ $? -ne 0 ]] ; then
142
+ if [ $? -ne 0 ]; then
133
143
warn " $APPLICATION_EXISTS_OUTPUT "
134
144
h2 " Creating application '$APPLICATION_NAME ' :"
135
145
136
-
137
146
# Create application
138
147
APPLICATION_CREATE=" aws deploy create-application --application-name $APPLICATION_NAME "
139
148
info " $APPLICATION_CREATE "
140
149
APPLICATION_CREATE_OUTPUT=$( $APPLICATION_CREATE 2>&1 )
141
150
142
- if [[ $? -ne 0 ]] ; then
151
+ if [ $? -ne 0 ]; then
143
152
warn " $APPLICATION_CREATE_OUTPUT "
144
153
error " Creating application '$APPLICATION_NAME ' failed"
145
154
exit 1
@@ -164,7 +173,7 @@ DEPLOYMENT_CONFIG_EXISTS="aws deploy get-deployment-config --deployment-config-n
164
173
info " $DEPLOYMENT_CONFIG_EXISTS "
165
174
DEPLOYMENT_CONFIG_EXISTS_OUTPUT=$( $DEPLOYMENT_CONFIG_EXISTS 2>&1 )
166
175
167
- if [[ $? -ne 0 ]] ; then
176
+ if [ $? -ne 0 ]; then
168
177
warn " $DEPLOYMENT_CONFIG_EXISTS_OUTPUT "
169
178
h2 " Creating deployment config '$DEPLOYMENT_CONFIG_NAME '"
170
179
@@ -173,7 +182,7 @@ if [[ $? -ne 0 ]];then
173
182
info " $DEPLOYMENT_CONFIG_CREATE "
174
183
DEPLOYMENT_CONFIG_CREATE_OUTPUT=$( $DEPLOYMENT_CONFIG_CREATE 2>&1 )
175
184
176
- if [[ $? -ne 0 ]] ; then
185
+ if [ $? -ne 0 ]; then
177
186
warn " $DEPLOYMENT_CONFIG_CREATE_OUTPUT "
178
187
error " Creating deployment config '$DEPLOYMENT_CONFIG_NAME ' failed"
179
188
exit 1
@@ -201,7 +210,7 @@ DEPLOYMENT_GROUP_EXISTS="aws deploy get-deployment-group --application-name $APP
201
210
info " $DEPLOYMENT_GROUP_EXISTS "
202
211
DEPLOYMENT_GROUP_EXISTS_OUTPUT=$( $DEPLOYMENT_GROUP_EXISTS 2>&1 )
203
212
204
- if [[ $? -ne 0 ]] ; then
213
+ if [ $? -ne 0 ]; then
205
214
warn " $DEPLOYMENT_GROUP_EXISTS_OUTPUT "
206
215
h2 " Creating deployment group '$DEPLOYMENT_GROUP ' for application '$APPLICATION_NAME '"
207
216
@@ -220,7 +229,7 @@ if [[ $? -ne 0 ]];then
220
229
info " $DEPLOYMENT_GROUP_CREATE "
221
230
DEPLOYMENT_GROUP_CREATE_OUTPUT=$( $DEPLOYMENT_GROUP_CREATE 2>&1 )
222
231
223
- if [[ $? -ne 0 ]] ; then
232
+ if [ $? -ne 0 ]; then
224
233
warn " $DEPLOYMENT_GROUP_CREATE_OUTPUT "
225
234
error " Creating deployment group '$DEPLOYMENT_GROUP ' for application '$APPLICATION_NAME ' failed"
226
235
exit 1
257
266
info " $PUSH_S3 "
258
267
PUSH_S3_OUTPUT=$( $PUSH_S3 2>&1 )
259
268
260
- if [[ $? -ne 0 ]] ; then
269
+ if [ $? -ne 0 ]; then
261
270
warn " $PUSH_S3_OUTPUT "
262
271
error " Pushing revision '$REVISION ' to S3 failed"
263
272
exit 1
289
298
info " $REGISTER_REVISION "
290
299
REGISTER_REVISION_OUTPUT=$( $REGISTER_REVISION 2>&1 )
291
300
292
- if [[ $? -ne 0 ]] ; then
301
+ if [ $? -ne 0 ]; then
293
302
warn " $REGISTER_REVISION_OUTPUT "
294
303
error " Registering revision '$REVISION ' failed"
295
304
exit 1
312
321
info " $DEPLOYMENT "
313
322
DEPLOYMENT_OUTPUT=$( $DEPLOYMENT 2>&1 )
314
323
315
- if [[ $? -ne 0 ]] ; then
324
+ if [ $? -ne 0 ]; then
316
325
warn " $DEPLOYMENT_OUTPUT "
317
326
error " Deployment of application '$APPLICATION_NAME ' on deployment group '$DEPLOYMENT_GROUP ' failed"
318
327
exit 1
@@ -332,7 +341,7 @@ if [ 'true' = "$DEPLOYMENT_OVERVIEW" ]; then
332
341
do
333
342
sleep 5
334
343
DEPLOYMENT_GET_OUTPUT=$( $DEPLOYMENT_GET 2>&1 > /tmp/$DEPLOYMENT_ID )
335
- if [[ $? -ne 0 ]] ; then
344
+ if [ $? -ne 0 ]; then
336
345
warn " $DEPLOYMENT_OUTPUT "
337
346
error " Deployment of application '$APPLICATION_NAME ' on deployment group '$DEPLOYMENT_GROUP ' failed"
338
347
exit 1
0 commit comments