Skip to content

Commit 32ed3df

Browse files
committed
Adding support to detect version number required for aws-cli 1.9.8
changes.
1 parent 0c01fbd commit 32ed3df

File tree

1 file changed

+56
-9
lines changed

1 file changed

+56
-9
lines changed

bin/aws-code-deploy.sh

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,50 @@ jsonValue() {
8686
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$key'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
8787
}
8888

89+
installAwsCli() {
90+
if ! typeExists "pip"; then
91+
h2 "Installing Python PIP"
92+
runCommand "sudo apt-get install -y python-pip"
93+
success "Installing PIP (`pip --version`) succeeded"
94+
fi
95+
96+
h2 "Installing AWS CLI"
97+
runCommand "sudo pip install awscli"
98+
}
99+
100+
vercomp() {
101+
if [[ $1 == $2 ]]
102+
then
103+
return 0
104+
fi
105+
local IFS=.
106+
local i ver1=($1) ver2=($2)
107+
108+
# fill empty fields in ver1 with zeros
109+
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
110+
do
111+
ver1[i]=0
112+
done
113+
114+
for ((i=0; i<${#ver1[@]}; i++))
115+
do
116+
if [[ -z ${ver2[i]} ]]
117+
then
118+
# fill empty fields in ver2 with zeros
119+
ver2[i]=0
120+
fi
121+
if ((10#${ver1[i]} > 10#${ver2[i]}))
122+
then
123+
return 1
124+
fi
125+
if ((10#${ver1[i]} < 10#${ver2[i]}))
126+
then
127+
return 2
128+
fi
129+
done
130+
return 0
131+
}
132+
89133
# Check variables
90134

91135
if [ -z "$AWS_CODE_DEPLOY_APPLICATION_NAME" ]; then
@@ -111,18 +155,21 @@ fi
111155

112156
# Check AWS is installed
113157
h1 "Step 1: Checking Dependencies"
158+
114159
if ! typeExists "aws"; then
115-
if ! typeExists "pip"; then
116-
h2 "Installing Python PIP"
117-
runCommand "sudo apt-get install -y python-pip"
118-
success "Installing PIP (`pip --version`) succeeded"
119-
fi
120-
121-
h2 "Installing AWS CLI"
122-
runCommand "sudo pip install awscli"
160+
installAwsCli
123161
success "Installing AWS CLI $(aws --version 2>&1) succeeded"
124162
else
125-
success "Dependencies met (aws: $(aws --version 2>&1))."
163+
# aws-cli 1.9.8 is required for proper SSE syntax
164+
AWS_FULL_VER=$(aws --version 2>&1)
165+
AWS_VER=$(echo $AWS_FULL_VER | sed -e 's/aws-cli\///' | sed -e 's/ Python.*//')
166+
vercomp $AWS_VER "1.9.8"
167+
if [[ $? == 2 ]]; then
168+
h2 "Installing updated AWS CLI version ($AWS_VER < 1.9.8)"
169+
installAwsCli
170+
fi
171+
172+
success "Dependencies met $(aws --version 2>&1)"
126173
fi
127174

128175

0 commit comments

Comments
 (0)