diff --git a/create_database.sh b/create_database.sh index 5043c3e..479a872 100755 --- a/create_database.sh +++ b/create_database.sh @@ -299,7 +299,7 @@ fi if ! $NON_INTERACTIVE_MODE ; then - declare -i i=0 + declare -i index_arr=0 # - Get MySQL Version # - @@ -313,8 +313,11 @@ if ! $NON_INTERACTIVE_MODE ; then echo "" declare -a _tmp_arr=() - for _val in ${mysql_credential_args_arr[@]} ; do - IFS=':' read -a _val_arr <<< "${_val}" + #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]}" @@ -324,10 +327,10 @@ if ! $NON_INTERACTIVE_MODE ; then else mysql_dist="MySQL/Percona $mysql_version" fi - echo " [$i] $mysql_dist" - _temp_arr[${i}]="$mysql_credential_args" + echo " [$index_arr] $mysql_dist" + _temp_arr[${index_arr}]="$mysql_credential_args" #_temp_arr+=("$mysql_credential_args") - (( i++ )) + (( index_arr++ )) done _OK=false diff --git a/drop_database.sh b/drop_database.sh index f5ae73d..cbac2dd 100755 --- a/drop_database.sh +++ b/drop_database.sh @@ -153,6 +153,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 @@ -241,6 +251,7 @@ if [[ -n "$DATABASE_NAME" ]] ; then fi fi + if $NON_INTERACTIVE_MODE ; then if [[ -z "$DATABASE_USER" ]]; then fatal "Database user not given. Maybe missing or wrong file '${working_dir}/databases/$DATABASE_NAME'." @@ -252,6 +263,10 @@ if $NON_INTERACTIVE_MODE ; then fi +# - Clear Screen +# - +clear + # ------------- # - Load Settings from configuration file mysql_credetials.conf @@ -274,13 +289,69 @@ else warn "No Configuration File found. Loading defaults.." fi -[[ -n "$MYSQL_CREDENTIAL_ARGS" ]] || MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS" -#[[ -n "$ACTION" ]] || ACTION="$DEFAULT_ACTION" - +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 - 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 dropping database?" + 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 echo "" echo -e "\033[32m--\033[m" @@ -330,6 +401,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 "" @@ -337,6 +446,10 @@ if ! $QUIET_MODE ; then echo "Drop 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" if $DO_NOT_DELTE_USER ; then echo -e " Database user................: \033[33mNone\033[m"