-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall
executable file
·68 lines (58 loc) · 1.86 KB
/
install
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
#!/usr/bin/env bash
# CircleCI CLI Multi-File-Config installer script.
#
# WARNING: This is a very rough implementation, and is still work in progress.
# This script will modify files in the target repo, use at your own risk.
#
# This installer copies the relevant files from copythis.circleci to the
# target repo, and attempts to install the git pre-commit hook if there is
# no pre-commit hook already in the repo.
TARGET="$1"
set -euo pipefail
log() { echo "==> $1" 1>&2; }
die() { log "FATAL: $1"; exit 1; }
usage() {
echo "usage: $(basename "$0") <target dir>";
exit 1
}
SRC="$PWD"
export SRC
[ -d "$SRC/copythis.circleci" ] || die "./copythis.circleci dir not found."
SRC=$SRC/copythis.circleci
[ -n "$TARGET" ] || usage
[ -d "$TARGET" ] || die "TARGET not a directory ($TARGET)"
# Strip trailing / and /.circleci[/]
TARGET="${TARGET%/}"
TARGET="${TARGET%/.circleci}"
log "Installing to repo rooted at $TARGET"
(
cd "$TARGET"
mkdir -p .circleci/config
(
[ ! -f .circleci/config.yml ] || {
[ ! -f .circleci/config/@config.yml ] || {
log "Existing config detected: not modifying."
exit 0 # Exit from this subshell.
}
log "Moving $TARGET/.circleci/config.yml -> $TARGET/.circleci/config/@config.yml"
mv .circleci/config.yml .circleci/config/@config.yml
make -C .circleci ci-config
}
)
cd .circleci
log "Copying Makefile, .gitattributes, .gitignore and README.md"
cp "$SRC"/{Makefile,.gitattributes,.gitignore,README.md} ./
# Re-gen the config now in case it needs to change due to updated Makefile.
make ci-config
cd ..
[ ! -d .git ] || {
mkdir -p .git/hooks
cd .git/hooks
if [ -f pre-commit ]; then
log ".git/hooks/pre-commit already exists, please install hook manually"
else
log "Installing git pre-commit hook to $TARGET/.git/hooks/"
cp "$SRC/pre-commit" ./
fi
}
)