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 pathinitProjectConfiguration.sh
More file actions
executable file
·163 lines (138 loc) · 4.09 KB
/
initProjectConfiguration.sh
File metadata and controls
executable file
·163 lines (138 loc) · 4.09 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
function usage() {
echo -e "\nCreate the configuration directory structure for a project"
echo -e "\nUsage: $(basename $0) -a OAID -t TITLE -p PID -r REGION -s SOLUTION -l ALPHASOLUTION"
echo -e "\nwhere\n"
echo -e "(m) -a OAID is the organisation account id e.g. \"env01\""
echo -e " -h shows this text"
echo -e "(o) -l ALPHASOLUTION is the solution template used for prototyping"
echo -e "(m) -p PID is the project id for the project e.g. \"eticket\""
echo -e "(o) -r REGION is the AWS region identifier where project resources will be created"
echo -e "(o) -s SOLUTION is the target solution template for the project"
echo -e "(m) -t TITLE is the title for the project e.g. \"Parks E-Ticketing\""
echo -e "\nNOTES:\n"
echo -e "1) The project directory tree will be created and populated"
echo -e "2) If the project directory already exists, no action is performed"
echo -e "3) The OAID is only used to ensure we are in the correct directory tree"
echo -e "4) If a region is not provided, the organisation account region will be used"
echo -e "5) The ALPHASOLUTION template overrides the SOLUTION template in the alpha environment"
echo -e "6) If ALPHASOLUTION is not provided, a default alpha solution is provided, which"
echo -e " provides a basic VPC with a publically accessible subnet"
echo -e ""
exit 1
}
# Parse options
while getopts ":a:hl:p:r:s:t:" opt; do
case $opt in
a)
OAID=$OPTARG
;;
h)
usage
;;
l)
ALPHASOLUTION=$OPTARG
;;
p)
PID=$OPTARG
;;
r)
REGION=$OPTARG
;;
s)
SOLUTION=$OPTARG
;;
t)
PRJ=$OPTARG
;;
\?)
echo -e "\nInvalid option: -$OPTARG"
usage
;;
:)
echo -e "\nOption -$OPTARG requires an argument"
usage
;;
esac
done
# Ensure mandatory arguments have been provided
if [[ "${OAID}" == "" ||
"${PRJ}" == "" ||
"${PID}" == "" ]]; then
echo -e "\nInsufficient arguments"
usage
fi
BIN="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ROOT="$(basename $(cd $BIN/../..;pwd))"
ROOT_DIR="$(cd $BIN/../..;pwd)"
SOLUTIONS_DIR="${ROOT_DIR}/config/solutions"
PROJECT_DIR="${SOLUTIONS_DIR}/${PID}"
ALPHA_DIR="${PROJECT_DIR}/alpha"
if [[ "${OAID}" != "${ROOT}" ]]; then
echo -e "\nThe provided OAID (${OAID}) doesn't match the root directory (${ROOT}). Nothing to do."
usage
fi
if [[ -d ${PROJECT_DIR} ]]; then
echo -e "\nLooks like the project directory tree already exists. Nothing to do."
usage
fi
# Create the project
if [[ ! -e ${PROJECT_DIR} ]]; then
mkdir ${PROJECT_DIR}
fi
cp -rp ${BIN}/patterns/configuration/project/* ${PROJECT_DIR}
# Generate the project profile
TEMPLATE="project.ftl"
TEMPLATEDIR="${BIN}/templates"
OUTPUT="${PROJECT_DIR}/project.json"
ARGS="-v \"project=${PRJ}\""
ARGS="${ARGS} -v id=${PID}"
ARGS="${ARGS} -v name=${PID}"
CMD="${BIN}/gsgen.sh -t $TEMPLATE -d $TEMPLATEDIR -o $OUTPUT $ARGS"
eval $CMD
if [[ "${REGION}" != "" ]]; then
ARGS="-v region=${REGION}"
fi
# Generate the target solution template
SOLUTIONDIR="${BIN}/patterns/solutions/${SOLUTION}"
if [[ ("${SOLUTION}" != "") && (-d "${SOLUTIONDIR}") ]]; then
for f in ${SOLUTIONDIR}/*; do
NAME=$(basename $f)
case $NAME in
solution.ftl)
TEMPLATEDIR="${SOLUTIONDIR}/"
TEMPLATE="$NAME"
OUTPUT="${PROJECT_DIR}/solution.json"
CMD="${BIN}/gsgen.sh -t $TEMPLATE -d $TEMPLATEDIR -o $OUTPUT $ARGS"
eval $CMD
;;
*)
cp -p $f .
;;
esac
done
fi
# Generate the alpha solution template
SOLUTIONDIR="${BIN}/patterns/solutions/${ALPHASOLUTION}"
if [[ ("${ALPHASOLUTION}" == "") || (! -d "${SOLUTIONDIR}") ]]; then
SOLUTIONDIR="${BIN}/patterns/solutions/alpha"
fi
for f in ${SOLUTIONDIR}/*; do
NAME=$(basename $f)
case $NAME in
solution.ftl)
TEMPLATEDIR="${SOLUTIONDIR}/"
TEMPLATE="$NAME"
OUTPUT="${ALPHA_DIR}/solution.json"
CMD="${BIN}/gsgen.sh -t $TEMPLATE -d $TEMPLATEDIR -o $OUTPUT $ARGS"
eval $CMD
;;
*)
cp -p $f ${ALPHA_DIR}
;;
esac
done
# Commit the results
cd ${PROJECT_DIR}
git add *
git commit -m "Configure project ${PID} solution"