create_database.sh: add support of multiple MySQL installations.

This commit is contained in:
Christoph 2019-01-30 14:58:24 +01:00
parent cd625ae265
commit b61cc133f0
2 changed files with 108 additions and 34 deletions

View File

@ -53,4 +53,4 @@
# - the forst value (before the colon ':') is only user for logging output and has no
# - further relevance .
# -
#msql_credential_args_arr=""
#mysql_credential_args_arr=""

View File

@ -155,6 +155,16 @@ echo_skipped() {
fi
}
is_number() {
return $(test ! -z "${1##*[!0-9]*}" > /dev/null 2>&1);
# - also possible
# -
#[[ ! -z "${1##*[!0-9]*}" ]] && return 0 || return 1
#return $([[ ! -z "${1##*[!0-9]*}" ]])
}
trap clean_up SIGHUP SIGINT SIGTERM
@ -255,6 +265,10 @@ if $NON_INTERACTIVE_MODE ; then
fi
# - Clear Screen
# -
clear
# -------------
# - Load Settings from configuration file create_drop_database.conf
@ -286,7 +300,57 @@ fi
if ! $NON_INTERACTIVE_MODE ; then
clear
declare -i i=0
# - Get MySQL Version
# -
if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo "Which Installation should be used for database creation?"
echo ""
echo ""
declare -a _tmp_arr=()
for _val in ${mysql_credential_args_arr[@]} ; do
IFS=':' read -a _val_arr <<< "${_val}"
mysql_version="${_val_arr[0]}"
mysql_credential_args="${_val_arr[1]}"
mysql_dist_string="$(mysql $mysql_credential_args -N -s -e "SELECT VERSION()" 2> /dev/null)"
if [[ "$mysql_dist_string" =~ MariaDB ]]; then
mysql_dist="MariaDB $mysql_version"
else
mysql_dist="MySQL/Percona $mysql_version"
fi
echo " [$i] $mysql_dist"
_temp_arr[${i}]="$mysql_credential_args"
#_temp_arr+=("$mysql_credential_args")
(( i++ ))
done
_OK=false
echo ""
echononl "Eingabe: "
while ! $_OK ; do
read _IN
if is_number "$_IN" && [[ -n ${_temp_arr[$_IN]} ]]; then
MYSQL_CREDENTIAL_ARGS="${_temp_arr[$_IN]}"
_OK=true
else
echo ""
echo -e "\tFalsche Eingabe !"
echo ""
echononl "Eingabe: "
fi
done
fi
if $DATABASE_NAME_NEEDED ; then
echo ""
echo -e "\033[32m--\033[m"
@ -372,6 +436,44 @@ if ! $NON_INTERACTIVE_MODE ; then
fi
# - Get MySQL Version
# -
echo ""
echo -e "\033[32m--\033[m"
echo ""
echononl " Get MySQL Version"
_version="$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT VERSION()" 2> $tmp_log_file)"
if [[ $? -ne 0 ]] ; then
echo_failed
fatal "$(cat $tmp_log_file)"
else
echo_ok
fi
IFS='.' read -r -a version_arr <<< "$_version"
declare -i MAJOR_VERSION="${version_arr[0]}"
declare -i MINOR_VERSION="${version_arr[1]}"
_path_level="${version_arr[2]}"
declare -i PATCH_LEVEL="${_path_level%%-*}"
## - Get current MySQL Distribution
## -
echononl " Get current MySQL distribution .."
if [[ -z "$_version" ]]; then
echo_failed
fatal "No installed MySQL server or distribution found!"
elif [[ "$_version" =~ MariaDB ]]; then
MYSQL_CUR_DISTRIBUTION="MariaDB"
else
MYSQL_CUR_DISTRIBUTION="MySQL"
fi
echo_ok
echo ""
echo -e "\033[32m--\033[m"
echo ""
if ! $QUIET_MODE ; then
echo ""
echo ""
@ -379,6 +481,10 @@ if ! $QUIET_MODE ; then
echo "Create MySQL Database settings"
echo -e "\033[32m\033[1m====================\033[m"
echo ""
echo " MySQL Distribution...........: $MYSQL_CUR_DISTRIBUTION"
echo " MySQL Version................: ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_LEVEL}"
echo " MySQL Credentials............: $MYSQL_CREDENTIAL_ARGS"
echo ""
echo " Database name................: $DATABASE_NAME"
echo " Database user................: $DATABASE_USER"
echo " Database password............: $DATABASE_PASSWD"
@ -416,38 +522,6 @@ if ! $QUIET_MODE ; then
echo ""
fi
# - Get MySQL Version
# -
echononl " Get MySQL Version"
_version="$(mysql $MYSQL_CREDENTIAL_ARGS -N -s -e "SELECT VERSION()" 2> $tmp_log_file)"
if [[ $? -ne 0 ]] ; then
echo_failed
fatal "$(cat $tmp_log_file)"
else
echo_ok
fi
IFS='.' read -r -a version_arr <<< "$_version"
declare -i MAJOR_VERSION="${version_arr[0]}"
declare -i MINOR_VERSION="${version_arr[1]}"
_path_level="${version_arr[2]}"
declare -i PATCH_LEVEL="${_path_level%%-*}"
## - Get current MySQL Distribution
## -
echononl " Get current MySQL distribution .."
if [[ -z "$_version" ]]; then
echo_failed
fatal "No installed MySQL server or distribution found!"
elif [[ "$_version" =~ MariaDB ]]; then
MYSQL_CUR_DISTRIBUTION="MariaDB"
elif [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ percona- ]]; then
MYSQL_CUR_DISTRIBUTION="Percona"
elif [[ "$(basename "$(realpath "/usr/local/mysql")")" =~ mysql- ]]; then
MYSQL_CUR_DISTRIBUTION="MySQL"
fi
echo_ok
# - Test if Database already exists