-
Notifications
You must be signed in to change notification settings - Fork 104
/
buildproperties.sh
executable file
·104 lines (98 loc) · 2.36 KB
/
buildproperties.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
#!/bin/bash
KEY_LOCATION=""
BUILDENV_LIST=""
usage()
{
cat << EOF
usage: $0 options
This script need to be executed with below option.
OPTIONS:
-e environment
-b Security file location GIT|AWS
-k key location
EOF
}
#log Function - Used to provide information of execution information with date and time
log()
{
echo "`date +'%D %T'` : $1"
}
track_error()
{
if [ $1 != "0" ]; then
log "$2 exited with error code $1"
log "completed execution IN ERROR at `date`"
exit $1
fi
}
download_buildenvfile()
{
if [ -z "$BUILDENV_LIST" ];
then
if [ -z "$KEY_LOCATION" ];
then
track_error $? "Please provide the file list using -b or file location -k or both -b and -k "
else
aws s3 sync s3://tc-buildproperties-${ENV_CONFIG}/$KEY_LOCATION .
track_error $? "Environment setting"
fi
else
Buffer_seclist=$(echo $BUILDENV_LIST | sed 's/,/ /g' )
for listname in $Buffer_seclist;
do
if [ -z "$KEY_LOCATION" ];
then
aws s3 cp s3://tc-buildproperties-${ENV_CONFIG}/$listname .
track_error $? "Environment setting"
else
aws s3 cp s3://tc-buildproperties-${ENV_CONFIG}/$KEY_LOCATION/$listname .
track_error $? "Environment setting"
fi
done
fi
}
configure_aws_cli() {
aws --version
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
aws configure set default.region $AWS_REGION
aws configure set default.output json
log "Configured AWS CLI."
}
while getopts .b:e:k:. OPTION
do
case $OPTION in
e)
ENV=$OPTARG
;;
b)
BUILDENV_LIST=$OPTARG
;;
k)
KEY_LOCATION=$OPTARG
;;
?)
log "additional param required"
usage
exit
;;
esac
done
#AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID")
#AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY")
#AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION")
if [ -z $AWS_REGION ];
then
AWS_REGION="us-east-1"
fi
if [ -z $AWS_ACCESS_KEY_ID ] || [ -z $AWS_SECRET_ACCESS_KEY ] ;
then
log "AWS Secret Parameters are not configured in circleci/environment"
usage
exit 1
else
#configure_aws_cli
log "AWS configured"
fi
ENV_CONFIG=`echo "$ENV" | tr '[:upper:]' '[:lower:]'`
download_buildenvfile