|
1 |
| -if [[ $# > 0 ]]; then |
| 1 | +# Determine the name of the MySQL/MariaDB configuration command |
| 2 | +get_mysql_config_cmd() { |
2 | 3 | version_info=$(mysql --version)
|
3 | 4 | if [[ "$version_info" == *"Maria"* ]]; then
|
4 |
| - include_dir=$(mariadb_config --include) |
| 5 | + echo "mariadb_config" |
5 | 6 | else
|
6 |
| - include_dir=$(mysql_config --include) |
| 7 | + echo "mysql_config" |
7 | 8 | fi
|
| 9 | +} |
8 | 10 |
|
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) |
11 | 43 |
|
12 | 44 | 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 | +} |
15 | 48 |
|
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 | +} |
20 | 58 |
|
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 |
24 | 64 | fi
|
25 | 65 |
|
| 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