-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.sh
executable file
·137 lines (117 loc) · 3.82 KB
/
configure.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
# ############################################################################
# Entrypoint
# ############################################################################
# Get
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#
LOGGER_PATH=$ROOT_DIR/tools/GitTools/Utils/logger.sh
#
GIT_HOOKS_PATH=$ROOT_DIR/tools/GitTools/Hooks
#
PYTHON_SETUP_SCRIPT_PATH=$ROOT_DIR/tools/BuildTools/scripts/setup.py
# Include/Import logger
source $LOGGER_PATH
# TODO(PO): remove this
set_log_level $LOG_LEVEL_TRACE
# Parse command line arguments
# TODO: add --install-missing or something like that
verbose=0 # Default verbosity level
install_hooks=true
while getopts ":vhn" opt; do
case $opt in
v)
((verbose++))
set_log_level LOG_LEVEL_TRACE
;;
h)
echo "Usage: $0 [-v (verbose)] [-h (help)] [-n (no-install-hooks)]"
exit 0
;;
n)
install_hooks=false
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
esac
done
# VERBOSE=0
# while getopts 'v' flag; do
# case "${flag}" in
# v)
# VERBOSE=1
# LOG_VERBOSITY=1
# set_log_level LOG_LEVEL_TRACE
# ;;
# ?)
# echo "script usage: $(basename \$0) [-v]" >&2
# exit 1
# ;;
# esac
# done
# ############################################################################
# Helper Functions
# - setup_git_hooks
# - run_python_setup
# ############################################################################
function setup_git_hooks() {
log_trace "setup_git_hooks"
if [ $install_hooks = true ]; then
read -p "Do you want to configure the git hooks? (yes/no): " UserInput
if [ "$UserInput" = "yes" ]; then
log_warn "Configuring Git Hooks ..."
if [ -d "$GIT_HOOKS_PATH" ]; then
log_warn "Installing hooks ..."
git config core.hooksPath "$GIT_HOOKS_PATH"
log_info "Installing hooks --- SUCCESS"
log_info "Configuring Git Hooks --- SUCCESS"
else
log_warn "Installing hooks --- FAILED"
log_warn "Configuring Git Hooks --- FAILED"
fi
else
log_info "Skipping git hooks configuration."
fi
fi
}
DEFAULT_PYTHON_VERSION="3.10.12"
function run_python_setup() {
log_warn "Testing if python is installed or in PATH ..."
if command -v python >/dev/null 2>&1; then
log_info "Testing if python is installed or in PATH --- SUCCESS"
log_warn "Checking python for version ${DEFAULT_PYTHON_VERSION} ..."
if python --version | grep -q "Python ${DEFAULT_PYTHON_VERSION}"; then
log_info "Checking python for version ${DEFAULT_PYTHON_VERSION} --- SUCCESS"
else
log_error "Checking python for version ${DEFAULT_PYTHON_VERSION} --- FAILED"
log_warn "This project was tested with Python ${DEFAULT_PYTHON_VERSION}. Other versions may not work as expected."
fi
else
log_fatal "Testing if python is installed or in PATH --- FAILED"
fi
log_warn "Detecting setup.py ..."
if [ -e "$PYTHON_SETUP_SCRIPT_PATH" ]; then
log_warn "Detecting setup.py --- SUCCESS"
log_warn "Running setup.py"
PYTHON_VERSION=$(python --version)
log_debug "PYTHON_VERSION: $PYTHON_VERSION"
python $PYTHON_SETUP_SCRIPT_PATH
else
log_fatal "Detecting setup.py --- FAILED"
fi
}
# ############################################################################
# Main Function
# ############################################################################
main() {
log_message " === Linux Configuration Batch File (version 0.1.0) ==="
setup_git_hooks
run_python_setup
}
main