-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql-cli
134 lines (110 loc) · 2.89 KB
/
mysql-cli
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
#!/bin/bash
# creator by shencangsheng
set -e
Error() {
echo -e "\033[31m[Error] $1 \033[0m" >&2
}
Usage() {
echo -e "\033[33m[Usage] $1 \033[0m" >&2
}
Info() {
echo -e "[Info] $1" >&2
}
Todo() {
echo -e "\033[36m[Todo] $1 \033[0m" >&2
}
Notice() {
echo -e "\033[33m[Important] $1 \033[0m" >&2
}
GLOAB_ARGS=("$@")
MYSQL_FILE_NAME="mysql-server-5.7"
function contains_args() {
local key="$1"
for arg in "${GLOAB_ARGS[@]}"; do
case $arg in
"${key}")
return 0
;;
esac
done
return 1
}
function get_args_value() {
local key="--$1"
local def_value=$2
local value=$def_value
for arg in "${GLOAB_ARGS[@]}"; do
case $arg in
"${key}="*)
value="${arg#*=}"
break
;;
esac
done
if [ -z "$value" ]; then
Error "「${key}」Variable is empty"
kill -9 $$
fi
if [ "$def_value" == "--Blank" ]; then
value=''
fi
echo $value
}
function check_directory() {
if [ ! -d "$1" ]; then
Error "「$1」 No such directory / Must be a directory"
exit 1
fi
}
function check_file() {
if [ ! -f "$1" ]; then
Error "「$1」 No such file / Must be a file"
exit 1
fi
}
function cp_keyword() {
local alias=$(get_args_value "cp")
if ! contains_args "--ignore"; then
wget --tries=5 --no-check-certificate -P /tmp/ https://codeload.github.com/mysql/mysql-server/zip/refs/heads/5.7
unzip /tmp/5.7 -d /tmp/
fi
local mysql_path=$(get_args_value "mysql-path" "/tmp")
mysql_path=${mysql_path%/}
local mysql_dir="${mysql_path}/${MYSQL_FILE_NAME}"
check_directory $mysql_dir
local mysql_lex_file="${mysql_dir}/sql/lex.h"
check_file $mysql_lex_file
for kv in ${alias[@]}; do
local key=${kv%%=*}
local value=${kv#*=}
local len=$(grep -n -s "{.*\(\"${key}\",.*\)}," $mysql_lex_file)
local len_line=$(echo $len | awk -F ': ' '{print $1}')
local len_keyword=$(echo $len | awk -F ': ' '{print $2}')
local sed_instruction="s/\""${key}"\"/\""${value}"\"/g"
local alias_keyword=$(echo ${len_keyword} | sed ${sed_instruction})
sed -i "${len_line}a ${alias_keyword}" ${mysql_lex_file}
done
}
function build() {
local mysql_path=$(get_args_value "mysql-path" "/tmp")
mysql_path=${mysql_path%/}
local mysql_dir="${mysql_path}/${MYSQL_FILE_NAME}"
check_directory $mysql_dir
cd $mysql_dir
cmake . -DINSTALL_MYSQLTESTDIR= -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DWITH_BOOST=/usr/local/boost_1_59_0 -DSYSCONFDIR=/etc -DEXTRA_CHARSETS=all
make -j $(get_args_value "job" 1)
make install
}
action=$(get_args_value 'action')
case $action in
"cp")
cp_keyword
;;
"build")
build
;;
*)
Error "Unknown option ${action}"
exit 1
;;
esac