-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsetup.sh
executable file
·78 lines (64 loc) · 1.89 KB
/
setup.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -efu -o pipefail
source $(dirname $0)/scripts/utils.inc
readonly SRC_DIR=scripts/git_hooks/
readonly TARGET_DIR=.git/hooks/
preExistCheck() {
local FILE=$(basename ${1} .py)
local TARGET=${TARGET_DIR}${FILE}
local FILE_BAK=${FILE}.bak
local TARGET_BAK=${TARGET}.bak
echo ${TARGET}
if [[ -e ${TARGET} || -L ${TARGET} ]]; then
printf "$(focus ${FILE}) already exists! Backing up to $(focus ${FILE_BAK})..."
mv ${TARGET} ${TARGET_BAK}
if [[ -e ${TARGET_BAK} || -L ${TARGET_BAK} ]]; then
echo_success
else
echo_failure "An error occurred while trying to backup $(focus ${FILE})."
fi
fi
}
linkHooks() {
local SRC_FILE=${1}
local SRC=${SRC_DIR}${SRC_FILE}
local TARGET_FILE=$(basename ${SRC_FILE} .py)
local TARGET=${TARGET_DIR}${TARGET_FILE}
printf "Setting up $(focus ${TARGET_FILE}) git hook..."
echo "#!/bin/sh" >> ${TARGET}
echo "exec < /dev/tty" >> ${TARGET}
echo "${SRC} \$1" >> ${TARGET}
# ln -s -f ../../${SRC_DIR}${SRC_FILE} ${TARGET}
if [[ ! -e ${TARGET} ]]; then
echo_failure "An error occurred while trying to link $(focus ${TARGET_FILE})."
fi
echo_success
}
makeExec() {
local SRC_FILE=${1}
local SRC=${SRC_DIR}${SRC_FILE}
local TARGET_FILE=$(basename ${SRC_FILE} .py)
local TARGET=${TARGET_DIR}${TARGET_FILE}
printf "Making $(focus ${SRC_FILE}) executable..."
chmod 755 ${SRC}
echo_success
printf "Making $(focus ${TARGET_FILE}) executable..."
chmod 755 ${TARGET}
echo_success
}
installDeps() {
printf "Confirming %s is installed..." $(focus "Node")
if ! hash npm 2>/dev/null; then
echo_failure "$(focus "Node") must be installed"
fi
echo_success
printf "Installing %s dependencies...\n" $(focus "NPM")
npm install
}
for file in $(ls ${SRC_DIR}); do
preExistCheck ${file}
linkHooks ${file}
makeExec ${file}
installDeps ${file}
done
printf "${GREEN}Setup Successful!${NORMAL}"