-
Notifications
You must be signed in to change notification settings - Fork 7
/
repo-generic-bootstrap
executable file
·205 lines (180 loc) · 5.95 KB
/
repo-generic-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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/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-generic-bootstrap 1.0
## Usage: repo-generic-boostrap [OPTION]
## Bootstrap a repo as a generic repo.
##
## --diff Bootstrap a temporary folder for comparing
## current status with current bootstrap template
##
## -h, --help Display this help and exit
## -v, --version Output version information and exit
DIFF=false
if { getopt --test >/dev/null 2>&1 && false; } || [[ "$?" = "4" ]] || false; then
ARGS=$(getopt -o hv -l help,version,diff -n $(basename ${BASH_SOURCE[0]}) -- "$@") || sh_script_usage
eval set -- "${ARGS}"
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--diff)
DIFF=true
shift
;;
-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 repository"
exit 1
}
[[ "$(cd $(git rev-parse --show-toplevel) >/dev/null && pwd -P)" = "$(pwd -P)" ]] || {
echo_err "yplatform is not in the root of a git repository"
exit 1
}
YP_DIR_REL="$(${YP_DIR}/bin/relpath "${YP_DIR}" "$(pwd)")"
ARTIFACTS=
if ${DIFF}; then
echo_info "Creating a temporary vanilla bootstrapped folder for comparison"
TMP_VANILLA_DIR=$(mktemp -d -t yplatform.XXXXXXXXXX)
echo_info "${TMP_VANILLA_DIR}"
echo_info "e.g. opendiff . ${TMP_VANILLA_DIR}"
echo_info "e.g. ksdiff . ${TMP_VANILLA_DIR}"
echo
ln -s ${YP_DIR} ${TMP_VANILLA_DIR}/yplatform
cd ${TMP_VANILLA_DIR}
fi
# NOTE duplicate code on purpose
ARTIFACT=.editorconfig
[[ -e ${ARTIFACT} ]] || {
ln -s ${YP_DIR_REL}/repo/dot.editorconfig ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Symlinked ${ARTIFACT}."
}
ARTIFACT=.ci.sh
[[ -e ${ARTIFACT} ]] || {
cp ${YP_DIR_REL}/repo/dot.ci.sh ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
ARTIFACT=.gitignore
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/dot.gitignore ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
[[ -e .github ]] || {
mkdir -p .github
# for ARTIFACT in "${YP_DIR_REL}/repo/dot.github"/* "${YP_DIR_REL}/repo/dot.github"/.*; do
for ARTIFACT in "${YP_DIR_REL}/repo/dot.github"/*; do
ARTIFACT=.github/$(basename ${ARTIFACT})
[[ "${ARTIFACT}" != ".github/settings.base.yml" ]] || continue
[[ -e ${ARTIFACT} ]] || {
cp -Rp -r ${YP_DIR_REL}/repo/dot${ARTIFACT} ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
done
}
[[ -e .git-hooks ]] || {
mkdir -p .git-hooks
for ARTIFACT in "${YP_DIR_REL}/repo/dot.git-hooks"/*; do
ARTIFACT=.git-hooks/$(basename ${ARTIFACT})
[[ -e ${ARTIFACT} ]] || {
cp -Rp -r ${YP_DIR_REL}/repo/dot${ARTIFACT} ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
done
}
ARTIFACT=.shellcheckrc
[[ -e ${ARTIFACT} ]] || {
ln -s ${YP_DIR_REL}/repo/dot.shellcheckrc ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Symlinked ${ARTIFACT}."
}
[[ -e .vscode ]] || {
mkdir -p .vscode
for ARTIFACT in "${YP_DIR_REL}/repo/dot.vscode"/* "${YP_DIR_REL}/repo/dot.vscode"/.*; do
ARTIFACT=.vscode/$(basename ${ARTIFACT})
[[ -e ${ARTIFACT} ]] || {
ln -s ../${YP_DIR_REL}/repo/dot${ARTIFACT} ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Symlinked ${ARTIFACT}."
}
done
}
ARTIFACT=LICENSE
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/LICENSE ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
}
ARTIFACT=NOTICE
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/NOTICE ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=AUTHORS
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/AUTHORS ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=Brewfile.inc.sh
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/Brewfile.inc.sh ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=Brewfile.lock
[[ -e ${ARTIFACT} ]] || {
ln -s ${YP_DIR_REL}/Brewfile.lock ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Symlinked ${ARTIFACT}."
}
ARTIFACT=Makefile
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/Makefile.generic ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=README.md
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/README.md ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
ARTIFACT=package.json
[[ -e ${ARTIFACT} ]] || {
cp -Rp ${YP_DIR_REL}/repo/package.json ${ARTIFACT}
ARTIFACTS="${ARTIFACTS}\\n${ARTIFACT}"
echo_info "Created ${ARTIFACT}."
echo_info "Make sure to edit ${ARTIFACT} in order to supply the required info."
}
echo -e "${ARTIFACTS}" | sort -u