-
Notifications
You must be signed in to change notification settings - Fork 133
/
init.sh
111 lines (90 loc) · 3.21 KB
/
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
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
#!/bin/bash
echo "============prepare work env start============"
if [[ $# == 1 && $1 == "-f" ]]; then
FORCE_DEPLOY="1"
else
FORCE_DEPLOY="0"
fi
WORK_DIR=$(readlink -f "$(dirname ${BASH_SOURCE[0]})")
if [ ${OBD_HOME} ]; then
OBD_HOME=${OBD_HOME}
else
OBD_HOME="${HOME}/.obd"
fi
if [ ${FORCE_DEPLOY} == "1" ]; then
rm -rf ${OBD_HOME}/config_parser
rm -rf ${OBD_HOME}/optimize
rm -rf ${OBD_HOME}/plugins
rm -rf ${OBD_HOME}/workflows
sudo rm -rf /etc/profile.d/obd.sh
fi
if [ ! -e /etc/profile.d/obd.sh ]; then
sudo ln -s ${WORK_DIR}/profile/obd.sh /etc/profile.d/obd.sh
fi
mkdir -p ${OBD_HOME} && cd ${OBD_HOME}
mkdir -p mirror/remote && cd mirror/remote
if [ ! -e "OceanBase.repo" ]; then
wget -q https://mirrors.aliyun.com/oceanbase/OceanBase.repo
fi
mkdir -p ${OBD_HOME}/{workflows,plugins,optimize,config_parser}
mkdir -p ${OBD_HOME}/plugins/obproxy-ce/{3.1.0,4.2.1}
for DIR in ${WORK_DIR}/plugins/obproxy-ce/*; do
version_dir=$(basename "${DIR}")
FILE_LIST=$(ls "${DIR}/")
for FILE in $FILE_LIST; do
if [ ! -e "${OBD_HOME}/plugins/obproxy-ce/${version_dir}/${FILE}" ]; then
ln -s ${DIR}/${FILE} ${OBD_HOME}/plugins/obproxy-ce/${version_dir}/${FILE}
fi
done
done
for DIR in ${WORK_DIR}/plugins/obproxy/*; do
if [ -d "${DIR}" ]; then
version_name=$(basename "${DIR}")
IFS='.' read -r major minor patch <<< ${version_name}
if [ "${patch}" -gt 0 ]; then
patch=$((patch-1))
else
patch=9
if [ "${minor}" -gt 0 ]; then
minor=$((minor-1))
else
minor=9
major=$((major-1))
fi
fi
new_version="${major}.${minor}.${patch}"
if [ ! -e "${WORK_DIR}/plugins/obproxy-ce/${new_version}" ]; then
ln -s ${DIR} ${OBD_HOME}/plugins/obproxy-ce/${new_version}
fi
fi
done
for DIR in workflows plugins optimize config_parser; do
FILE_LIST=$(ls ${WORK_DIR}/${DIR})
for FILE in $FILE_LIST; do
if [ ! -e "${OBD_HOME}/${DIR}/${FILE}" ]; then
ln -s ${WORK_DIR}/${DIR}/${FILE} ${OBD_HOME}/${DIR}/${FILE}
fi
done
done
if [ ! -e ${OBD_HOME}/optimize/obproxy-ce ]; then
ln -s ${OBD_HOME}/optimize/obproxy ${OBD_HOME}/optimize/obproxy-ce
fi
for DIR in workflows plugins config_parser; do
if [ ! -e ${OBD_HOME}/${DIR}/oceanbase-ce ]; then
ln -s ${OBD_HOME}/${DIR}/oceanbase ${OBD_HOME}/${DIR}/oceanbase-ce
fi
if [ ! -e ${OBD_HOME}/${DIR}/ocp-server-ce ]; then
ln -s ${OBD_HOME}/${DIR}/ocp-server ${OBD_HOME}/${DIR}/ocp-server-ce
fi
done
echo -n '<VERSION>' > ${OBD_HOME}/version
echo "============update .bashrc============"
ALIAS_OBD_EXIST=$(grep "alias obd=" ~/.bashrc | head -n 1)
if [[ "${ALIAS_OBD_EXIST}" != "" ]]; then
echo "need update obd alias"
fi
echo "export OBD_INSTALL_PATH=${WORK_DIR}" >> ~/.bashrc
echo "alias obd='python ${WORK_DIR}/_cmd.py'" >> ~/.bashrc
echo -e "if [ -d ${WORK_DIR} ]\nthen\n source ${WORK_DIR}/profile/obd.sh\nfi" >> ~/.bashrc
echo "Please enter ob-deploy dir and install python requirements by 'pip install -r requirements.txt' when your python version is '2.x' and replace requirements.txt with requirements3.txt when your python version is '3.x'"
echo "============prepare work env ok!============"