forked from paketo-buildpacks/github-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·90 lines (69 loc) · 1.86 KB
/
bootstrap.sh
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
#!/usr/bin/env bash
set -eu
set -o pipefail
readonly ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${ROOT_DIR}/scripts/.util/print.sh"
# shellcheck source=SCRIPTDIR/sanity.sh
source "${ROOT_DIR}/scripts/sanity.sh"
function main() {
local target repo_type
while [[ "${#}" != 0 ]]; do
case "${1}" in
--target)
target="${2}"
shift 2
;;
--repo-type)
repo_type="${2}"
shift 2
;;
--help|-h)
shift 1
usage
exit 0
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
if [[ -z "${target:-}" ]]; then
usage
echo
util::print::error "--target is a required flag"
fi
if [[ -z "${repo_type:-}" ]]; then
usage
echo
util::print::error "--repo-type is a required flag"
fi
sanity::check "${ROOT_DIR}"
bootstrap "${target}" "${repo_type}"
}
function usage() {
cat <<-USAGE
bootstrap.sh --target <target> --repo-type <repo-type> [OPTIONS]
Bootstraps a repository with github configuration and scripts.
OPTIONS
--repo-type <repo-type> type of repo (implementation|language-family|builder)
--help -h prints the command usage
--target <target> path to a buildpack repository
USAGE
}
function bootstrap() {
local target repo_type
target="${1}"
repo_type="${2}"
if [[ ! -d "${target}" ]]; then
util::print::error "cannot bootstrap: \"${target}\" does not exist"
fi
if [[ "${repo_type}" != "implementation" && "${repo_type}" != "language-family" && "${repo_type}" != "builder" ]]; then
util::print::error "cannot bootstrap: \"${repo_type}\" is not a valid repo type"
fi
cp -pR "${ROOT_DIR}/${repo_type}/." "${target}"
}
main "${@:-}"