-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
60 lines (51 loc) · 1.71 KB
/
install.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
#!/bin/bash
set -o errexit
set -o errtrace
set -o nounset
SCRIPTDIR="$(dirname "$(realpath "${0}")")"
SCRIPTNAME="$(basename "${0}")"
function find_repos {
local repo=
if [ "${#}" -eq 0 ]; then
echo "EXIT"
echo "ALL"
fi
find . -maxdepth 2 -type d -name .git | while read -r repo; do
rp="$(realpath "${repo}")"; dn="$(dirname "${rp}")"
printf "%s\n" "$(basename "${dn}")"
done
}
function install_hooks {
local project="${1}"
mv "${project}/.git/hooks" "${project}/.git/hooks.examples"
ln -sf "${SCRIPTDIR}" "${project}/.git/hooks"
if ! test -f "${project}/.git/hooks/${SCRIPTNAME}"; then
printf "Unable to find '%s' in '%s', exiting\n" "${SCRIPTNAME}" "${project}/.git/hooks"
return 1
fi
if [[ ! -L "${project}/.git/hooks/pre-commit" ]] || \
[[ "$(realpath "${project}/.git/hooks/pre-commit")" != "$(realpath "${project}/.git/hooks/pre-commit.bash")" ]]; then
ln -sf "$(realpath "${project}/.git/hooks/pre-commit.bash")" "${project}/.git/hooks/pre-commit"
else
printf "\tskipping symlink for '%s', already present\n" "${project}"
fi
printf "Successfully installed hooks in '%s'\n" "${project}"
return 0
}
if [ ! -d .git ]; then
select item in $(find_repos); do
case "${item}" in
ALL) find_repos nomenu | while read -r repo; do
install_hooks "${repo}";
done;
exit 0
;;
EXIT) echo "Exiting program as requested"; exit 0
;;
*) printf "Installing hooks into %s\n" "${item}";
install_hooks "${item}"
esac
done
else
install_hooks .
fi