-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup
executable file
·63 lines (51 loc) · 1.83 KB
/
setup
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
#!/bin/bash
src="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pipeline_types="$(cd $src && find . -name 'pipeline.yml' | sed -e "s|^\./||;s|/pipeline.yml$||")"
usage() {
cat << EOF
${1:-"Setup pipeline template for the desired type of pipeline."}
Usage: $0 <type> [/repo/to/setup]
where <type> is one of:
$(echo "$pipeline_types" | sed -e "s/^/ - /")
EOF
exit ${2:-0}
}
set -e
case "${1}" in
(-h|--help|help)
usage
;;
esac
export template=$1
export target=${2:-$(pwd)}
apply_shell_expansion() {
declare file="$1"
declare data=$(< "$file")
declare delimiter="__apply_shell_expansion_delimiter__"
declare command="cat <<$delimiter"$'\n'"$data"$'\n'"$delimiter"
eval "$command"
}
initial_settings_yml() {
local settings_yml=${target}/ci/settings.yml
if [[ -f ${src}/${template}/helpers/initial_settings.yml ]]; then
export team=${team:-main}
export name=$(basename $target)
export fly_target=${fly_target:-$(fly targets | head -n1 | tail -n1 | awk '{print $1}')}
export fly_target_url=$(bosh int ~/.flyrc --path /targets/${fly_target}/api)
apply_shell_expansion ${src}/${template}/helpers/initial_settings.yml > $settings_yml
${src}/${template}/helpers/credhub-examples.sh
else
echo "--- {}" > $settings_yml
fi
}
[ -n "${template}" ] || usage "ERROR: Missing pipeline template type" 1
[ -d "${target}" ] || usage "ERROR: ${target} path not found" 1
pattern="^($(echo "$pipeline_types" | tr "\n" "|" | sed -e "s/\|*$//"))$"
[[ "${template}"=~$pattern ]] || usage "ERROR: ${template} is not a valid pipeline template" 1
echo "Installing ${template} pipeline in ${target}..."
mkdir -p ${target}/ci
cp -R ${src}/${template}/* ${target}/ci/
rm -rf ${target}/ci/helpers
cp ${src}/repipe ${target}/ci/
[ -f ${target}/ci/settings.yml ] || initial_settings_yml ${template} ${target}
exit 0