-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrepo-cfn-bootstrap
executable file
·116 lines (100 loc) · 3.21 KB
/
repo-cfn-bootstrap
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
#!/usr/bin/env bash
set -euo pipefail
YP_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)"
source ${YP_DIR}/sh/common.inc.sh
#- repo-cfn-bootstrap 1.0
## Usage: repo-cfn-boostrap [OPTION] -- CFN_DIR
## Bootstrap a git repo with a cfn configuration.
##
## -s, --stack-stem A stack stem e.g. infra, ci, env-web, env-api, etc.
## If env-* is given, then STACK_NAME will be set to $(ENV_NAME)-*
## in the <stack-stem>.inc.mk file
##
## CFN_DIR The folder to cfn-bootstrap. Defaults to "cfn" in the root of the repo
##
## -h, --help Display this help and exit
## -v, --version Output version information and exit
STACK_STEM=
if { getopt --test >/dev/null 2>&1 && false; } || [[ "$?" = "4" ]] || false; then
ARGS=$(getopt -o hv -l help,version,stack-stem: -n $(basename ${BASH_SOURCE[0]}) -- "$@") || sh_script_usage
eval set -- "${ARGS}"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
-s|--stack-stem)
STACK_STEM=$2
shift 2
;;
-h|--help)
sh_script_usage
;;
-v|--version)
sh_script_version
;;
--)
shift
break
;;
-*)
sh_script_usage
;;
*)
break
;;
esac
done
# [[ $# -eq 0 ]] || sh_script_usage
(
cd ${YP_DIR}/..
git rev-parse --show-toplevel >/dev/null || {
echo_err "yplatform is not in a git repo"
exit 1
}
)
CFN_DIR=${1:-$(git rev-parse --show-toplevel)/cfn}
YP_DIR_REL="$(${YP_DIR}/bin/relpath "${YP_DIR}" "$(pwd)")"
ARTIFACTS=
mkdir -p ${CFN_DIR}
# NOTE duplicate code on purpose
ARTIFACT=${CFN_DIR}/.gitignore
[[ -e ${ARTIFACT} ]] || {
cp ${YP_DIR_REL}/aws-cfn.mk/tpl.gitignore ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
ARTIFACT=${CFN_DIR}/Makefile
[[ -e ${ARTIFACT} ]] || {
cp ${YP_DIR_REL}/aws-cfn.mk/tpl.Makefile ${ARTIFACT}
sed -i "s|<YP_DIR_REL>|${YP_DIR_REL}|g" ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
[[ -n ${STACK_STEM} ]] || {
echo_info "No stack stem given. Stopping here."
echo -e "${ARTIFACTS}" | sort -u
exit 0
}
ARTIFACT=${CFN_DIR}/${STACK_STEM}/index.js
[[ -e ${ARTIFACT} ]] || {
mkdir -p $(dirname ${ARTIFACT})
cp ${YP_DIR_REL}/aws-cfn.mk/tpl.stack-stem/index.js ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
ARTIFACT=${CFN_DIR}/${STACK_STEM}.inc.mk
[[ -e ${ARTIFACT} ]] || {
cp ${YP_DIR_REL}/aws-cfn.mk/tpl.stack-stem.inc.mk ${ARTIFACT}
sed -i "s|<STACK_STEM>|${STACK_STEM}|g" ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=${CFN_DIR}/${STACK_STEM}
[[ -e ${ARTIFACT} ]] || {
mkdir ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT} folder."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
echo -e "${ARTIFACTS}" | sort -u