-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup
executable file
·55 lines (47 loc) · 1.75 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
#!/usr/bin/env bash
do-setup() {
if [[ -d .git ]]; then
# check for dirty
if git status --porcelain | grep -qe '^[^?!]'; then
echo "Please commit or stash your changes before running setup"
exit 65 # EX_DATAERR
fi
else
echo "(Not using git? Be sure to exclude .devkit and .deps from revision control)"
fi
# Create dotfiles
for dot in .envrc .dkrc; do
create-or-inform $dot sample$dot
done
# Create script/bootstrap, et al
mkdir -p script
create-or-inform script/bootstrap script/bootstrap
create-or-inform script/README.md script/README.md no-inform
chmod +x script/bootstrap
for cmd in build cibuild clean console server setup test update; do
if [[ -f script/$cmd && ! -L script/$cmd ]]; then
echo "script/$cmd is not a symlink; please remove it"
elif [[ ! -L script/$cmd ]]; then
ln -s bootstrap script/$cmd
fi
done
# Update .gitignore and add to revision control
if [[ -d .git ]]; then
for ignore in .deps .devkit; do
if [[ ! -f .gitignore ]] || ! grep -q ^\\$ignore'\(\s\|$\)' .gitignore; then
echo $ignore >>.gitignore
fi
done
git add .gitignore .envrc .dkrc script/
fi
echo "devkit setup is complete; you can now commit the changes"
}
create-or-inform() {
if ! [[ -f $1 ]]; then
cat "${BASH_SOURCE%/*}/$2" >"$1"
[[ $1 == .envrc && "$(command -v direnv)" ]] && direnv allow
elif [[ ! "${3-}" ]] && ! diff -q "$1" "${BASH_SOURCE%/*}/$2" >/dev/null; then
echo "$1 already exists with different contents; please check against ${BASH_SOURCE%/*}/$2"
fi
}
[[ $0 == $BASH_SOURCE ]] && do-setup "$@"