Fixed some errors on multiple MySQL installations.

This commit is contained in:
Christoph 2020-09-01 14:36:00 +02:00
parent 792579070c
commit 2d761934d4
5 changed files with 188 additions and 180 deletions

View File

@ -348,43 +348,8 @@ fi
if [[ -n "$mysql_credential_args" ]]; then
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
MYSQL_CREDENTIALS_GIVEN=true
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
MYSQL_CREDENTIALS_GIVEN=false
fi
if ! $NON_INTERACTIVE_MODE ; then
@ -411,6 +376,7 @@ if ! $NON_INTERACTIVE_MODE ; then
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
@ -438,6 +404,8 @@ if ! $NON_INTERACTIVE_MODE ; then
echononl "Eingabe: "
fi
done
MYSQL_CREDENTIALS_GIVEN=true
fi
@ -566,6 +534,40 @@ if $MYSQL_CREDENTIALS_GIVEN ; then
echo -e "\033[32m--\033[m"
echo ""
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
fi

View File

@ -347,41 +347,6 @@ fi
if [[ -n "$mysql_credential_args" ]]; then
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
MYSQL_CREDENTIALS_GIVEN=true
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
MYSQL_CREDENTIALS_GIVEN=false
fi
@ -438,6 +403,8 @@ if ! $NON_INTERACTIVE_MODE ; then
fi
done
MYSQL_CREDENTIALS_GIVEN=true
fi
@ -445,7 +412,7 @@ if ! $NON_INTERACTIVE_MODE ; then
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo "Insert Database name which should be created.."
echo "Insert Database name which should be deleted.."
echo ""
echo ""
echononl "Database name: "
@ -529,6 +496,40 @@ if $MYSQL_CREDENTIALS_GIVEN ; then
echo -e "\033[32m--\033[m"
echo ""
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
fi

View File

@ -270,41 +270,6 @@ fi
if [[ -n "$mysql_credential_args" ]]; then
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
MYSQL_CREDENTIALS_GIVEN=true
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
MYSQL_CREDENTIALS_GIVEN=false
fi
@ -319,7 +284,7 @@ if ! $NON_INTERACTIVE_MODE ; then
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo "Which Installation should be used for database creation?"
echo "Which Installation should be used?"
echo ""
echo ""
@ -361,6 +326,8 @@ if ! $NON_INTERACTIVE_MODE ; then
fi
done
MYSQL_CREDENTIALS_GIVEN=true
fi
@ -420,6 +387,40 @@ if $MYSQL_CREDENTIALS_GIVEN ; then
echo -e "\033[32m--\033[m"
echo ""
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
fi

View File

@ -348,41 +348,6 @@ fi
if [[ -n "$mysql_credential_args" ]]; then
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
MYSQL_CREDENTIALS_GIVEN=true
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
MYSQL_CREDENTIALS_GIVEN=false
fi
@ -439,6 +404,8 @@ if ! $NON_INTERACTIVE_MODE ; then
fi
done
MYSQL_CREDENTIALS_GIVEN=true
fi
@ -446,7 +413,7 @@ if ! $NON_INTERACTIVE_MODE ; then
echo ""
echo -e "\033[32m--\033[m"
echo ""
echo "Insert Database name which should be created.."
echo "Insert Database for which access should be granted.."
echo ""
echo ""
echononl "Database name: "
@ -566,6 +533,41 @@ if $MYSQL_CREDENTIALS_GIVEN ; then
echo -e "\033[32m--\033[m"
echo ""
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if $(mysql --login-path=local -e ";" > /dev/null 2>&1) ; then
MYSQL_CREDENTIAL_ARGS="--login-path=local"
elif [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
fi
@ -574,7 +576,7 @@ if ! $QUIET_MODE ; then
echo ""
echo ""
echo -e "\033[32m\033[1m====================\033[m"
echo "Create MySQL Database settings"
echo "Grant MySQL Database access settings"
echo -e "\033[32m\033[1m====================\033[m"
echo ""
echo " MySQL Distribution...........: $MYSQL_CUR_DISTRIBUTION"
@ -595,7 +597,7 @@ if ! $QUIET_MODE ; then
fi
if ! $NON_INTERACTIVE_MODE ; then
echo -e -n "\033[1mContinue creating user with above settings? [y/n]:\033[m "
echo -e -n "\033[1mContinue with above settings? [y/n]:\033[m "
read OK
while [[ "X${OK}X" = "XX" ]] ; do
echo ""
@ -630,7 +632,7 @@ fi
# - Check if User already exists
# -
echononl " Check if user '$DATABASE_USER' already exists for localhost .."
if [[ "$(mysql -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '${DATABASE_USER}')")" = "1" ]]; then
if [[ "$(mysql $MYSQL_CREDENTIAL_ARGS -se "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = '${DATABASE_USER}')")" = "1" ]]; then
user_exists=true
else
user_exists=false

View File

@ -256,39 +256,6 @@ declare -i index_arr=0
if [[ -n "$mysql_credential_args" ]]; then
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
MYSQL_CREDENTIALS_GIVEN=true
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
MYSQL_CREDENTIALS_GIVEN=false
fi
@ -339,6 +306,8 @@ if [[ ${#mysql_credential_args_arr[@]} -gt 0 ]] ; then
fi
done
MYSQL_CREDENTIALS_GIVEN=true
fi
if $DATABASE_NAME_NEEDED ; then
@ -396,6 +365,39 @@ if $MYSQL_CREDENTIALS_GIVEN ; then
echo -e "\033[32m--\033[m"
echo ""
else
detect_mysql_version
MAJOR_VERSION="$MYSQL_MAJOR_VERSION"
MINOR_VERSION="$MYSQL_MINOR_VERSION"
PATCH_LEVEL="$MYSQL_PATCH_LEVEL"
if [[ "$MYSQL_CUR_DISTRIBUTION" = "MariaDB" ]] && ([[ $MAJOR_VERSION -gt 10 ]] \
|| ( [[ $MAJOR_VERSION -eq 10 ]] && [[ $MINOR_VERSION -gt 3 ]] )) ; then
if [[ -S "/tmp/mysql.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /tmp/mysql.sock"
elif [[ -S "/var/run/mysqld/mysqld.sock" ]]; then
MYSQL_CREDENTIAL_ARGS="-u root -S /var/run/mysqld/mysqld.sock"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
else
if [[ -f "/usr/local/mysql/sys-maint.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
elif [[ -f "/etc/mysql/debian.cnf" ]] ; then
MYSQL_CREDENTIAL_ARGS="--defaults-file=/etc/mysql/debian.cnf"
else
fatal "Parameter 'MYSQL_CREDENTIAL_ARGS' cannot be determined automated.
Use configuration file "$conf_file" to set
parameter manually."
fi
fi
fi