-
Notifications
You must be signed in to change notification settings - Fork 26
/
setup
executable file
·71 lines (58 loc) · 2.21 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
64
65
66
67
68
69
70
71
#!/bin/bash
# original authors: James Hunt <james@niftylogic.com>
# Dennis Bell <dennis.j.bell@gmail.com>
# created: 2016-03-10
# maintainer: Benjamin Gandon (Gstack)
src="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pipeline_types="$(cd ${src} && find . -name 'pipeline.yml' | sed -e "s|^\./||;s|/pipeline.yml$||")"
usage() {
local message=$1
local exit_status=$2
cat <<EOF
${message:-"Setup pipeline template for the desired type of pipeline."}
Usage: $(basename "${BASH_SOURCE[0]}") <type> [/repo/to/setup]
where <type> is one of:
$(sed -e "s/^/ - /" <<< "${pipeline_types}")
EOF
exit ${exit_status:-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="^($(tr "\n" "|" <<<"${pipeline_types}" | 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
rm -f ${target}/ci/README.md
cp ${src}/repipe ${target}/ci/
[ -f ${target}/ci/settings.yml ] || initial_settings_yml ${template} ${target}
exit 0