Try to determin 'MYSQL_CREDENTIAL_ARGS' if not given.
This commit is contained in:
parent
c8a177e2c2
commit
ea8fc078c2
@ -11,7 +11,7 @@ tmp_log_file="$(mktemp)"
|
||||
# - Variable settings
|
||||
# -------------
|
||||
|
||||
DEFAULT_MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
MYSQL_CREDENTIALS_GIVEN=false
|
||||
|
||||
DATABASE_NAME=""
|
||||
DATABASE_USER=""
|
||||
@ -164,6 +164,28 @@ is_number() {
|
||||
#return $([[ ! -z "${1##*[!0-9]*}" ]])
|
||||
}
|
||||
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
elif [[ "$_MYSQLD_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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
|
||||
@ -292,8 +314,40 @@ fi
|
||||
|
||||
if [[ -n "$mysql_credential_args" ]]; then
|
||||
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
|
||||
MYSQL_CREDENTIALS_GIVEN=true
|
||||
else
|
||||
MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -439,41 +493,46 @@ 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
|
||||
if $MYSQL_CREDENTIALS_GIVEN ; then
|
||||
|
||||
# - 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
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
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%%-*}"
|
||||
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
|
||||
## - 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
|
||||
elif [[ "$_version" =~ MariaDB ]]; then
|
||||
MYSQL_CUR_DISTRIBUTION="MariaDB"
|
||||
else
|
||||
else
|
||||
MYSQL_CUR_DISTRIBUTION="MySQL"
|
||||
fi
|
||||
echo_ok
|
||||
echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
fi
|
||||
echo_ok
|
||||
echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
|
||||
|
||||
if ! $QUIET_MODE ; then
|
||||
|
112
drop_database.sh
112
drop_database.sh
@ -11,7 +11,7 @@ tmp_log_file="$(mktemp)"
|
||||
# - Variable settings
|
||||
# -------------
|
||||
|
||||
DEFAULT_MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
MYSQL_CREDENTIALS_GIVEN=false
|
||||
|
||||
DATABASE_NAME=""
|
||||
DATABASE_USER=""
|
||||
@ -163,6 +163,28 @@ is_number() {
|
||||
#return $([[ ! -z "${1##*[!0-9]*}" ]])
|
||||
}
|
||||
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
elif [[ "$_MYSQLD_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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
|
||||
@ -291,8 +313,40 @@ fi
|
||||
|
||||
if [[ -n "$mysql_credential_args" ]]; then
|
||||
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
|
||||
MYSQL_CREDENTIALS_GIVEN=true
|
||||
else
|
||||
MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -402,41 +456,45 @@ 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
|
||||
if $MYSQL_CREDENTIALS_GIVEN ; then
|
||||
|
||||
# - 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
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
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%%-*}"
|
||||
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
|
||||
## - 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
|
||||
elif [[ "$_version" =~ MariaDB ]]; then
|
||||
MYSQL_CUR_DISTRIBUTION="MariaDB"
|
||||
else
|
||||
else
|
||||
MYSQL_CUR_DISTRIBUTION="MySQL"
|
||||
fi
|
||||
echo_ok
|
||||
echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
fi
|
||||
echo_ok
|
||||
echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
|
||||
if ! $QUIET_MODE ; then
|
||||
|
112
drop_tables.sh
112
drop_tables.sh
@ -11,7 +11,7 @@ tmp_log_file="$(mktemp)"
|
||||
# - Variable settings
|
||||
# -------------
|
||||
|
||||
DEFAULT_MYSQL_CREDENTIAL_ARGS="--defaults-file=/usr/local/mysql/sys-maint.cnf"
|
||||
MYSQL_CREDENTIALS_GIVEN=false
|
||||
|
||||
DATABASE_NAME=""
|
||||
DATABASE_NAME_NEEDED=true
|
||||
@ -148,6 +148,28 @@ is_number() {
|
||||
#return $([[ ! -z "${1##*[!0-9]*}" ]])
|
||||
}
|
||||
|
||||
detect_mysql_version () {
|
||||
|
||||
_MYSQLD_VERSION="$(mysqld -V 2>/dev/null)"
|
||||
|
||||
if [[ -z "$_MYSQLD_VERSION" ]]; then
|
||||
fatal "No installed MySQL server or distribution found!"
|
||||
elif [[ "$_MYSQLD_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
|
||||
|
||||
MYSQL_VERSION="$(echo $_MYSQLD_VERSION | grep -o -E "[0-9]+\.[0-9]+\.[0-9]+(-[0-9]+)?" | head -n 1)"
|
||||
MYSQL_MAJOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1)"
|
||||
MYSQL_MINOR_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f2)"
|
||||
MYSQL_PATCH_LEVEL="$(echo $MYSQL_VERSION | cut -d '.' -f3)"
|
||||
MYSQL_MAIN_VERSION="$(echo $MYSQL_VERSION | cut -d '.' -f1,2)"
|
||||
|
||||
}
|
||||
|
||||
|
||||
trap clean_up SIGHUP SIGINT SIGTERM
|
||||
|
||||
@ -214,8 +236,40 @@ fi
|
||||
|
||||
if [[ -n "$mysql_credential_args" ]]; then
|
||||
MYSQL_CREDENTIAL_ARGS="$mysql_credential_args"
|
||||
MYSQL_CREDENTIALS_GIVEN=true
|
||||
else
|
||||
MYSQL_CREDENTIAL_ARGS="$DEFAULT_MYSQL_CREDENTIAL_ARGS"
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -293,41 +347,45 @@ 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
|
||||
if $MYSQL_CREDENTIALS_GIVEN ; then
|
||||
|
||||
# - 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
|
||||
else
|
||||
echo_ok
|
||||
fi
|
||||
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%%-*}"
|
||||
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
|
||||
## - 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
|
||||
elif [[ "$_version" =~ MariaDB ]]; then
|
||||
MYSQL_CUR_DISTRIBUTION="MariaDB"
|
||||
else
|
||||
else
|
||||
MYSQL_CUR_DISTRIBUTION="MySQL"
|
||||
fi
|
||||
echo_ok
|
||||
echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
fi
|
||||
echo_ok
|
||||
echo ""
|
||||
echo -e "\033[32m--\033[m"
|
||||
echo ""
|
||||
|
||||
|
||||
if ! $QUIET_MODE ; then
|
||||
|
Loading…
Reference in New Issue
Block a user