This commit is contained in:
Christoph 2019-11-05 18:02:46 +01:00
commit ffd923f3e4

View File

@ -138,6 +138,16 @@ echo_skipped() {
fi 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 trap clean_up SIGHUP SIGINT SIGTERM
@ -202,12 +212,69 @@ else
warn "No Configuration File found. Loading defaults.." warn "No Configuration File found. Loading defaults.."
fi fi
[[ -n "$mysql_credential_args" ]] || MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS" if [[ -n "$mysql_credential_args" ]]; then
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
else
MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
fi
if ! $NON_INTERACTIVE_MODE ; then if ! $NON_INTERACTIVE_MODE ; then
clear declare -i index_arr=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
while [[ $index_arr -lt ${#mysql_credential_args_arr[@]} ]] ; do
#IFS=':' read -a _val_arr <<< "${_val}"
IFS=':' read -a _val_arr <<< "${mysql_credential_args_arr[$index_arr]}"
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 " [$index_arr] $mysql_dist"
_temp_arr[${index_arr}]="$mysql_credential_args"
#_temp_arr+=("$mysql_credential_args")
(( index_arr++ ))
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 if $DATABASE_NAME_NEEDED ; then
echo "" echo ""
echo -e "\033[32m--\033[m" echo -e "\033[32m--\033[m"
@ -225,12 +292,55 @@ if ! $NON_INTERACTIVE_MODE ; then
fi fi
fi 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 if ! $QUIET_MODE ; then
echo "" echo ""
echo "" echo ""
echo -e "\033[32m\033[1m====================\033[m" echo -e "\033[32m\033[1m====================\033[m"
echo "Settings: Drop all MySQL tables" echo "Settings: Drop all MySQL tables from dadabase '$DATABASE_NAME'"
echo -e "\033[32m\033[1m====================\033[m" 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 ""
echo " Database name................: $DATABASE_NAME" echo " Database name................: $DATABASE_NAME"
echo "" echo ""