forked from oceanbase/obdiag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev_init.sh
executable file
·76 lines (61 loc) · 2.31 KB
/
dev_init.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
#!/usr/bin/env bash
PROJECT_PATH=$(cd "$(dirname "$0")"; pwd)
WORK_DIR=$(readlink -f "$(dirname ${BASH_SOURCE[0]})")
get_python_version() {
python3 -c "import sys; print(sys.version_info[0], sys.version_info[1])"
}
check_python_version() {
local version_output=$(python3 -c "import sys; print(sys.version_info.major, sys.version_info.minor)")
IFS=' ' read -ra version <<< "$version_output"
major=${version[0]}
minor=${version[1]}
if (( major < 3 || (major == 3 && minor < 8) )); then
echo "Your Python3 version is less than 3.8. Please updating Python3..."
exit 1
fi
}
install_requirements() {
REQ_FILE="${PROJECT_PATH}/requirements3.txt"
if [[ -f "$REQ_FILE" ]]; then
echo "Installing packages listed in $REQ_FILE..."
pip3 install -r "$REQ_FILE"
else
echo "No requirements3.txt file found at the expected location."
fi
}
copy_file(){
if [ ${OBDIAG_HOME} ]; then
OBDIAG_HOME=${OBDIAG_HOME}
else
OBDIAG_HOME="${HOME}/.obdiag"
fi
mkdir -p ${OBDIAG_HOME} && cd ${OBDIAG_HOME}
mkdir -p ${OBDIAG_HOME}/check
mkdir -p ${OBDIAG_HOME}/gather
mkdir -p ${OBDIAG_HOME}/display
if [ -d "${WORK_DIR}/handler/checker/tasks" ]; then
cp -rf ${WORK_DIR}/handler/checker/tasks ${OBDIAG_HOME}/check/
cp -rf ${WORK_DIR}/handler/checker/tasks/obproxy_check_package.yaml ${OBDIAG_HOME}/check/
cp -rf ${WORK_DIR}/handler/checker/tasks/observer_check_package.yaml ${OBDIAG_HOME}/check/
fi
if [ -d "${WORK_DIR}/handler/gather/tasks" ]; then
cp -rf ${WORK_DIR}/handler/gather/tasks ${OBDIAG_HOME}/gather/
fi
if [ -d "${WORK_DIR}/handler/display/tasks" ]; then
cp -rf ${WORK_DIR}/handler/display/tasks ${OBDIAG_HOME}/display/
fi
if [ -d "${WORK_DIR}/example" ]; then
cp -rf ${WORK_DIR}/example ${OBDIAG_HOME}/
fi
if [ -d "${WORK_DIR}/handler/rca/scene" ]; then
cp -rf ${WORK_DIR}/handler/rca/scene ${OBDIAG_HOME}/rca
fi
}
copy_file
echo "File initialization completed"
check_python_version
source ${WORK_DIR}/init_obdiag_cmd.sh
echo "Creating or updating alias 'obdiag' to run 'python3 ${PROJECT_PATH}/main.py'"
echo "alias obdiag='python3 ${PROJECT_PATH}/main.py'" >> ~/.bashrc
source ~/.bashrc
echo "Initialization completed successfully!"