-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·76 lines (62 loc) · 1.93 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
69
70
71
72
73
74
75
#!/usr/bin/env bash
# Installs proenv creating ${REPO}/.proenv structures
# Invoked by hooks/post-checkout
# After .githooks created, before hooks (registered) link setup
mkdir -p "${REPO}/.proenv"
cp -f "${REPO}/.git/proenv.head" "${REPO}/.proenv/HEAD"
[[ 0 == $? ]] && rm -rf "${REPO}/.git/proenv.head"
# move cloned template assets from .git to .proenv
cp -rf "${REPO}/.git/etc" "${REPO}/.proenv/etc"
[[ 0 == $? ]] && rm -rf "${REPO}/.git/etc"
cp -rf "${REPO}/.git/modules" "${REPO}/.proenv/modules"
[[ 0 == $? ]] && rm -rf "${REPO}/.git/modules"
cp -rf "${REPO}/.git/bin" "${REPO}/.proenv/bin"
[[ 0 == $? ]] && rm -rf "${REPO}/.git/bin"
# create .envrc
cat <<EOF > "${REPO}/.envrc"
REPO="${REPO}"
export REPO
PATH="\${REPO}/.proenv/bin:\$PATH"
export PATH
if [[ -f "\${REPO}/.proenv/etc/direnv" ]]; then
source "\${REPO}/.proenv/etc/direnv"
fi
EOF
if [[ -f ${REPO}/.gitignore ]]; then
if [[ -z $(grep '.envrc' "${REPO}/.gitignore") ]]; then
echo '.envrc' >> "${REPO}/.gitignore"
GITIGNORE_CHANGED=1
fi
if [[ -z $(grep '.proenv' "${REPO}/.gitignore") ]]; then
echo '.proenv' >> "${REPO}/.gitignore"
GITIGNORE_CHANGED=1
fi
else
echo '.envrc' >> "${REPO}/.gitignore"
echo '.proenv' >> "${REPO}/.gitignore"
GITIGNORE_CHANGED=1
fi
if [[ 1 == $GITIGNORE_CHANGED ]]; then
git add "${REPO}/.gitignore"
git commit -m 'proenv install adding .envrc and .proenv to .gitignore' \
"${REPO}/.gitignore"
git push
fi
# execute dependencies and direnv register repository's .envrc
FAIL_FAST=1
REPO="${REPO}" $(dirname $0)/dependencies
if [[ 0 != $? ]]; then
echo "proenv::install dependencies ${pc} failed"
if [[ 1 == $FAIL_FAST ]]; then
echo "FAIL_FAST is enabled, exiting"
exit 1
else
echo "FAIL_FAST is disabled"
fi
fi
direnv allow "${REPO}"
# cleanup .git directory from template assets
rm -f "${REPO}/.git/Readme.md"
rm -f "${REPO}/.git/dependencies"
rm -f "${REPO}/.git/install"
rm -rf "${REPO}/.git/share"