forked from aruba/pyaoscx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-hooks
executable file
·106 lines (85 loc) · 2.24 KB
/
bootstrap-hooks
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env sh
# (C) Copyright 2021 Hewlett Packard Enterprise Development LP.
# Apache License 2.0
# editing a script while it runs
# may cause problems because the shell reads it line by line
# when all commands are outside functions
# so here all the blocks are wrapped to avoid that
# should someone want to add something to their local hook
set_hooks_settings() {
git config hooks.verbose false
cat <<- EOF
by default, the hooks will NOT use verbose output
if you want hooks in this repository to use verbose output
you can run
git config hooks.verbose true
EOF
}
install_hooks() {
# use local for variable that won't be shared
local base_dir
base_dir=$(git rev-parse --show-toplevel)
for filename in ${base_dir}/.hooks/*; do
rm -f "$base_dir/.git/hooks/$(basename "$filename")"
ln -s "$filename" "${base_dir}/.git/hooks/"
git update-index --assume-unchanged "$filename"
done
cat <<- EOF
by default, these hooks will be ignored (but may still affected by git reset)
if you want to see when the hooks change, run
cd $(git rev-parse --show-toplevel)
git update-index --no-assume-unchanged .hooks/*
cd -
EOF
}
spin() {
while :; do
for c in / - \\ \|; do
printf '%s\b' "$c"
[ "$END_SPIN" = "true" ] && { break 2; }
sleep 1
done
done
printf '\n'
}
install_tools() {
[ -d "$HOME/.bintools" ] && return 0
cat <<- EOF
installing tools
EOF
# start a spinner while installing the tools
spin &
SPIN_PID=$!
# set a trap for the spinner to end when receiving any signal
# including this script ending
trap 'kill -9 "$SPIN_PID"' $(seq 0 15)
(
virtualenv -p python3.7 "$HOME/.bintools"
. "$HOME/.bintools/bin/activate"
python -m pip install flake8
python -m pip install black
deactivate
) > /dev/null 2>&1
END_SPIN="true"
[ -d "$HOME/.hookbin" ] && return 0
(
mkdir -p "$HOME/.hookbin"
cd "$HOME/.hookbin"
ln -s "$HOME/.bintools/bin/flake8" .
ln -s "$HOME/.bintools/bin/black" .
) > /dev/null 2>&1
}
set_new_path_section() {
grep -q hookbin "$HOME/.bashrc" && return 0
cat <<- EOF >> "$HOME/.bashrc"
# set by pyaoscx's bootstrap-hooks
[ -d \$HOME/.hookbin ] && export PATH="\$HOME/.hookbin:\$PATH"
EOF
}
main() {
set_hooks_settings
install_hooks
install_tools
set_new_path_section
}
main