This repository was archived by the owner on Dec 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyncAccountBuckets.sh
More file actions
executable file
·109 lines (87 loc) · 3.29 KB
/
syncAccountBuckets.sh
File metadata and controls
executable file
·109 lines (87 loc) · 3.29 KB
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
#!/bin/bash
function usage() {
echo -e "\nSynchronise the contents of the code and credentials buckets to the local values"
echo -e "\nUsage: $(basename $0) -a OAID -d DOMAIN -y"
echo -e "\nwhere\n"
echo -e "(m) -a OAID is the organisation account id e.g. \"env01\""
echo -e "(o) -d DOMAIN is the domain of the buckets to be synchronised"
echo -e " -h shows this text"
echo -e "(o) -y for a dryrun - show what will happen without actually transferring any files"
echo -e "\nDEFAULTS:\n"
echo -e "DOMAIN = {OAID}.gosource.com.au"
echo -e "\nNOTES:\n"
echo -e "1) The OAID is only used to ensure we are in the correct directory tree"
echo -e ""
exit 1
}
DRYRUN=
# Parse options
while getopts ":a:d:hy" opt; do
case $opt in
a)
OAID=$OPTARG
;;
d)
DOMAIN=$OPTARG
;;
h)
usage
;;
y)
DRYRUN="--dryrun"
;;
\?)
echo -e "\nInvalid option: -$OPTARG"
usage
;;
:)
echo -e "\nOption -$OPTARG requires an argument"
usage
;;
esac
done
# Ensure mandatory arguments have been provided
if [[ "${OAID}" == "" ]]; then
echo -e "\nInsufficient arguments"
usage
fi
BIN="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT="$(basename $(cd $BIN/../..;pwd))"
ROOT_DIR="$(cd $BIN/../..;pwd)"
AWS_DIR="${ROOT_DIR}/infrastructure/aws"
STARTUP_DIR="${AWS_DIR}/startup"
CREDS_DIR="${ROOT_DIR}/infrastructure/credentials"
SOLUTIONS_DIR="${ROOT_DIR}/config/solutions"
if [[ "${OAID}" != "${ROOT}" ]]; then
echo -e "\nThe provided OAID (${OAID}) doesn't match the root directory (${ROOT}). Nothing to do."
usage
fi
# Set the profile if on PC to pick up the IAM credentials to use to access the credentials bucket.
# For other platforms, assume the server has a service role providing access.
uname | grep -iE "MINGW64|Darwin|FreeBSD" > /dev/null 2>&1
if [[ "$?" -eq 0 ]]; then
PROFILE="--profile ${OAID}"
fi
pushd ${SOLUTIONS_DIR} > /dev/null 2>&1
REGION=$(grep '"Region"' account.json | cut -d '"' -f 4)
if [[ "${REGION}" == "" ]]; then
echo -e "\nThe region must be defined in the account configuration file. Are we in the correct directory? Nothing to do."
usage
fi
if [[ "${DOMAIN}" == "" ]]; then DOMAIN=${OAID}.gosource.com.au; fi
# Confirm access to the code bucket
aws ${PROFILE} --region ${REGION} s3 ls s3://code.${DOMAIN}/ > /dev/null 2>&1
if [[ "$?" -ne 0 ]]; then
echo -e "\nCan't access the code bucket. Does the service role for the server include access to the \"${OAID}\" configuration bucket? If windows, is a profile matching the account been set up? Nothing to do."
usage
fi
pushd ${STARTUP_DIR} > /dev/null 2>&1
aws ${PROFILE} --region ${REGION} s3 sync ${DRYRUN} --delete bootstrap/ s3://code.${DOMAIN}/bootstrap/
# Confirm access to the credentials bucket
aws ${PROFILE} --region ${REGION} s3 ls s3://credentials.${DOMAIN}/ > /dev/null 2>&1
if [[ "$?" -ne 0 ]]; then
echo -e "\nCan't access the credentials bucket. Does the service role for the server include access to the \"${OAID}\" configuration bucket? If windows, is a profile matching the account been set up? Nothing to do."
usage
fi
pushd ${CREDS_DIR}/${OAID}/alm/docker > /dev/null 2>&1
aws ${PROFILE} --region ${REGION} s3 sync ${DRYRUN} --delete . s3://credentials.${DOMAIN}/${OAID}/alm/docker/