Skip to content

Commit be039cc

Browse files
authored
Merge pull request #6 from ZarTek-Creole/master
2 parents f4dd2d9 + b44af30 commit be039cc

File tree

1 file changed

+67
-14
lines changed

1 file changed

+67
-14
lines changed

install.sh

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,78 @@
1-
if [[ $# > 0 ]]; then
1+
# Determine the name of the MySQL/MariaDB configuration command
2+
get_mysql_config_cmd() {
23
version_info=$(mysql --version)
34
if [[ "$version_info" == *"Maria"* ]]; then
4-
include_dir=$(mariadb_config --include)
5+
echo "mariadb_config"
56
else
6-
include_dir=$(mysql_config --include)
7+
echo "mysql_config"
78
fi
9+
}
810

9-
sql_result=$(mysql --user=$1 --password=$2 -s -N -e "SHOW VARIABLES LIKE 'plugin_dir';")
10-
plugin_dir=$(cut -d" " -f2 <<< $sql_result)
11+
# Retrieve the directory containing MySQL/MariaDB header files
12+
get_include_dir() {
13+
local mysql_config_cmd
14+
mysql_config_cmd=$(get_mysql_config_cmd)
15+
$mysql_config_cmd --include
16+
}
17+
18+
# Retrieve the MySQL/MariaDB plugin directory
19+
get_plugin_dir() {
20+
local username=$1
21+
local password=$2
22+
local sql_result
23+
sql_result=$(mysql --user=$username --password=$password -s -N -e "SHOW VARIABLES LIKE 'plugin_dir';")
24+
cut -d" " -f2 <<< $sql_result
25+
}
26+
27+
# Execute a MySQL/MariaDB command
28+
execute_mysql_cmd() {
29+
local username=$1
30+
local password=$2
31+
local command=$3
32+
mysql --user=$username --password=$password -s -N -e "$command"
33+
}
34+
35+
# Compile and install the HTTP plugin
36+
install_http_plugin() {
37+
local username=$1
38+
local password=$2
39+
local include_dir
40+
include_dir=$(get_include_dir)
41+
local plugin_dir
42+
plugin_dir=$(get_plugin_dir $username $password)
1143

1244
export CGO_CFLAGS=$include_dir
13-
go build -buildmode=c-shared -o $plugin_dir"http.so" http.go
14-
rm $plugin_dir"http.h"
45+
go build -buildmode=c-shared -o "$plugin_dir/http.so" http.go
46+
rm "$plugin_dir/http.h"
47+
}
1548

16-
mysql --user=$1 --password=$2 -s -N -e "CREATE OR REPLACE FUNCTION http_help RETURNS STRING SONAME 'http.so';"
17-
mysql --user=$1 --password=$2 -s -N -e "CREATE OR REPLACE FUNCTION http_raw RETURNS STRING SONAME 'http.so';"
18-
mysql --user=$1 --password=$2 -s -N -e "CREATE OR REPLACE FUNCTION http_get RETURNS STRING SONAME 'http.so';"
19-
mysql --user=$1 --password=$2 -s -N -e "CREATE OR REPLACE FUNCTION http_post RETURNS STRING SONAME 'http.so';"
49+
# Create MySQL/MariaDB functions for the HTTP plugin
50+
create_http_functions() {
51+
local username=$1
52+
local password=$2
53+
execute_mysql_cmd $username $password "CREATE OR REPLACE FUNCTION http_help RETURNS STRING SONAME 'http.so';"
54+
execute_mysql_cmd $username $password "CREATE OR REPLACE FUNCTION http_raw RETURNS STRING SONAME 'http.so';"
55+
execute_mysql_cmd $username $password "CREATE OR REPLACE FUNCTION http_get RETURNS STRING SONAME 'http.so';"
56+
execute_mysql_cmd $username $password "CREATE OR REPLACE FUNCTION http_post RETURNS STRING SONAME 'http.so';"
57+
}
2058

21-
echo "Install Success"
22-
else
23-
echo "bash install.sh username password(optional)"
59+
# Check if the script was called with at least one argument (username)
60+
if [[ $# -lt 1 ]]; then
61+
echo "Error: you must specify the MySQL/MariaDB username as an argument."
62+
echo "Usage: bash install.sh username [password]"
63+
exit 1
2464
fi
2565

66+
# Retrieve
67+
# Retrieve the username and password (optional)
68+
username=$1
69+
password=
70+
if [[ $# -gt 1 ]]; then
71+
password=$2
72+
fi
73+
74+
# Install the HTTP plugin and create the MySQL/MariaDB functions
75+
install_http_plugin $username $password
76+
create_http_functions $username $password
77+
78+
echo "Installation successful"

0 commit comments

Comments
 (0)