Skip to content

Commit 2c5473f

Browse files
author
Nicolas Huray
committed
Prevent aws cli installation if already present
1 parent d7238d3 commit 2c5473f

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

run.sh

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ bold() { printf "${bold}%s${reset}\n" "$@"
4242
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@"
4343
}
4444

45+
46+
type_exists() {
47+
if [ $(type -P $1) ]; then
48+
return 0
49+
fi
50+
return 1
51+
}
52+
4553
jsonValue() {
4654
key=$1
4755
num=$2
@@ -78,16 +86,18 @@ fi
7886
# ----- Install AWS Cli -----
7987
# see documentation : http://docs.aws.amazon.com/cli/latest/userguide/installing.html
8088
# ---------------------------
81-
set -e
82-
h1 "Installing AWS CLI"
8389

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
89100

90-
set +e
91101
# ----- Configure -----
92102
# see documentation :
93103
# http://docs.aws.amazon.com/cli/latest/reference/configure/index.html
@@ -100,7 +110,7 @@ h2 "Configuring AWS Access Key ID"
100110
CONFIGURE_KEY_OUTPUT=$(aws configure set aws_access_key_id $WERCKER_AWS_CODE_DEPLOY_KEY 2>&1)
101111
success "Configuring AWS Access Key ID succeeded"
102112

103-
h2 "Configuring AWS Access Key ID"
113+
h2 "Configuring AWS Secret Access Key"
104114
CONFIGURE_SECRET_OUTPUT=$(aws configure set aws_secret_access_key $WERCKER_AWS_CODE_DEPLOY_SECRET 2>&1)
105115
success "Configuring AWS Secret Access Key succeeded"
106116

@@ -129,17 +139,16 @@ APPLICATION_EXISTS="aws deploy get-application --application-name $APPLICATION_N
129139
info "$APPLICATION_EXISTS"
130140
APPLICATION_EXISTS_OUTPUT=$($APPLICATION_EXISTS 2>&1)
131141

132-
if [[ $? -ne 0 ]];then
142+
if [ $? -ne 0 ]; then
133143
warn "$APPLICATION_EXISTS_OUTPUT"
134144
h2 "Creating application '$APPLICATION_NAME' :"
135145

136-
137146
# Create application
138147
APPLICATION_CREATE="aws deploy create-application --application-name $APPLICATION_NAME"
139148
info "$APPLICATION_CREATE"
140149
APPLICATION_CREATE_OUTPUT=$($APPLICATION_CREATE 2>&1)
141150

142-
if [[ $? -ne 0 ]];then
151+
if [ $? -ne 0 ]; then
143152
warn "$APPLICATION_CREATE_OUTPUT"
144153
error "Creating application '$APPLICATION_NAME' failed"
145154
exit 1
@@ -164,7 +173,7 @@ DEPLOYMENT_CONFIG_EXISTS="aws deploy get-deployment-config --deployment-config-n
164173
info "$DEPLOYMENT_CONFIG_EXISTS"
165174
DEPLOYMENT_CONFIG_EXISTS_OUTPUT=$($DEPLOYMENT_CONFIG_EXISTS 2>&1)
166175

167-
if [[ $? -ne 0 ]];then
176+
if [ $? -ne 0 ]; then
168177
warn "$DEPLOYMENT_CONFIG_EXISTS_OUTPUT"
169178
h2 "Creating deployment config '$DEPLOYMENT_CONFIG_NAME'"
170179

@@ -173,7 +182,7 @@ if [[ $? -ne 0 ]];then
173182
info "$DEPLOYMENT_CONFIG_CREATE"
174183
DEPLOYMENT_CONFIG_CREATE_OUTPUT=$($DEPLOYMENT_CONFIG_CREATE 2>&1)
175184

176-
if [[ $? -ne 0 ]];then
185+
if [ $? -ne 0 ]; then
177186
warn "$DEPLOYMENT_CONFIG_CREATE_OUTPUT"
178187
error "Creating deployment config '$DEPLOYMENT_CONFIG_NAME' failed"
179188
exit 1
@@ -201,7 +210,7 @@ DEPLOYMENT_GROUP_EXISTS="aws deploy get-deployment-group --application-name $APP
201210
info "$DEPLOYMENT_GROUP_EXISTS"
202211
DEPLOYMENT_GROUP_EXISTS_OUTPUT=$($DEPLOYMENT_GROUP_EXISTS 2>&1)
203212

204-
if [[ $? -ne 0 ]];then
213+
if [ $? -ne 0 ]; then
205214
warn "$DEPLOYMENT_GROUP_EXISTS_OUTPUT"
206215
h2 "Creating deployment group '$DEPLOYMENT_GROUP' for application '$APPLICATION_NAME'"
207216

@@ -220,7 +229,7 @@ if [[ $? -ne 0 ]];then
220229
info "$DEPLOYMENT_GROUP_CREATE"
221230
DEPLOYMENT_GROUP_CREATE_OUTPUT=$($DEPLOYMENT_GROUP_CREATE 2>&1)
222231

223-
if [[ $? -ne 0 ]];then
232+
if [ $? -ne 0 ]; then
224233
warn "$DEPLOYMENT_GROUP_CREATE_OUTPUT"
225234
error "Creating deployment group '$DEPLOYMENT_GROUP' for application '$APPLICATION_NAME' failed"
226235
exit 1
@@ -257,7 +266,7 @@ fi
257266
info "$PUSH_S3"
258267
PUSH_S3_OUTPUT=$($PUSH_S3 2>&1)
259268

260-
if [[ $? -ne 0 ]];then
269+
if [ $? -ne 0 ]; then
261270
warn "$PUSH_S3_OUTPUT"
262271
error "Pushing revision '$REVISION' to S3 failed"
263272
exit 1
@@ -289,7 +298,7 @@ fi
289298
info "$REGISTER_REVISION"
290299
REGISTER_REVISION_OUTPUT=$($REGISTER_REVISION 2>&1)
291300

292-
if [[ $? -ne 0 ]];then
301+
if [ $? -ne 0 ]; then
293302
warn "$REGISTER_REVISION_OUTPUT"
294303
error "Registering revision '$REVISION' failed"
295304
exit 1
@@ -312,7 +321,7 @@ fi
312321
info "$DEPLOYMENT"
313322
DEPLOYMENT_OUTPUT=$($DEPLOYMENT 2>&1)
314323

315-
if [[ $? -ne 0 ]];then
324+
if [ $? -ne 0 ]; then
316325
warn "$DEPLOYMENT_OUTPUT"
317326
error "Deployment of application '$APPLICATION_NAME' on deployment group '$DEPLOYMENT_GROUP' failed"
318327
exit 1
@@ -332,7 +341,7 @@ if [ 'true' = "$DEPLOYMENT_OVERVIEW" ]; then
332341
do
333342
sleep 5
334343
DEPLOYMENT_GET_OUTPUT=$($DEPLOYMENT_GET 2>&1 > /tmp/$DEPLOYMENT_ID)
335-
if [[ $? -ne 0 ]];then
344+
if [ $? -ne 0 ]; then
336345
warn "$DEPLOYMENT_OUTPUT"
337346
error "Deployment of application '$APPLICATION_NAME' on deployment group '$DEPLOYMENT_GROUP' failed"
338347
exit 1

0 commit comments

Comments
 (0)