Refactor MySQL installation logic in tools.func

Refactor MySQL installation script for clarity and efficiency. Update package handling and repository setup for Debian 13+.
This commit is contained in:
CanbiZ 2025-10-22 15:42:41 +02:00 committed by GitHub
parent 2e34f534eb
commit 0f69e8cc69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2451,14 +2451,8 @@ function setup_mysql() {
NEED_INSTALL=true NEED_INSTALL=true
else else
if apt list --upgradable 2>/dev/null | grep -q '^mysql-server/'; then if apt list --upgradable 2>/dev/null | grep -q '^mysql-server/'; then
$STD apt update || { $STD apt update || { msg_error "Failed to update package list"; return 1; }
msg_error "Failed to update package list" $STD apt install --only-upgrade -y mysql-server || { msg_error "Failed to upgrade MySQL"; return 1; }
return 1
}
$STD apt install --only-upgrade -y mysql-server || {
msg_error "Failed to upgrade MySQL"
return 1
}
fi fi
return return
fi fi
@ -2469,81 +2463,46 @@ function setup_mysql() {
if [[ "$NEED_INSTALL" == true ]]; then if [[ "$NEED_INSTALL" == true ]]; then
msg_info "Setup MySQL $MYSQL_VERSION" msg_info "Setup MySQL $MYSQL_VERSION"
# Cleanup old repository files
cleanup_old_repo_files "mysql" cleanup_old_repo_files "mysql"
# Determine suite - use bookworm for Debian testing/unstable
local SUITE local SUITE
if [[ "$DISTRO_ID" == "debian" ]]; then if [[ "$DISTRO_ID" == "debian" ]]; then
case "$DISTRO_CODENAME" in case "$DISTRO_CODENAME" in
bookworm | bullseye) bookworm|bullseye) SUITE="$DISTRO_CODENAME" ;;
SUITE="$DISTRO_CODENAME" trixie|forky|sid) SUITE="bookworm" ;;
;; *) SUITE="bookworm" ;;
trixie | forky | sid)
SUITE="bookworm"
;;
*)
SUITE="bookworm" # Fallback to bookworm for unknown Debian versions
;;
esac esac
else else
# For Ubuntu - use fallback detection
SUITE=$(get_fallback_suite "$DISTRO_ID" "$DISTRO_CODENAME" "https://repo.mysql.com/apt/${DISTRO_ID}") SUITE=$(get_fallback_suite "$DISTRO_ID" "$DISTRO_CODENAME" "https://repo.mysql.com/apt/${DISTRO_ID}")
fi fi
# Stop existing MySQL if running
$STD systemctl stop mysql 2>/dev/null || true $STD systemctl stop mysql 2>/dev/null || true
# Only purge if MySQL is actually installed
if dpkg -l 2>/dev/null | grep -q "^ii.*mysql-server"; then if dpkg -l 2>/dev/null | grep -q "^ii.*mysql-server"; then
$STD apt purge -y mysql-server* mysql-client* mysql-common 2>/dev/null || true $STD apt purge -y mysql-server* mysql-client* mysql-common mysql-community-* 2>/dev/null || true
fi fi
# Handle libaio dependency for Debian Trixie+ (time64 transition) # --- Debian 13+ Fix: MySQL 8.0 incompatible with libaio1t64 ---
if [[ "$DISTRO_ID" == "debian" ]] && [[ "$DISTRO_CODENAME" =~ ^(trixie|forky|sid)$ ]]; then if [[ "$DISTRO_ID" == "debian" && "$DISTRO_CODENAME" =~ ^(trixie|forky|sid)$ ]]; then
# Install libaio1t64 if not present msg_info "Debian ${DISTRO_CODENAME} detected → using MySQL 8.4 LTS (libaio1t64)"
if ! dpkg -l libaio1t64 2>/dev/null | grep -q "^ii"; then curl -fsSL https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 | gpg --dearmor -o /etc/apt/keyrings/mysql.gpg
$STD apt update || { cat >/etc/apt/sources.list.d/mysql.sources <<'EOF'
msg_error "Failed to update package list" Types: deb
return 1 URIs: https://repo.mysql.com/apt/debian/
} Suites: bookworm
$STD apt install -y libaio1t64 || { Components: mysql-8.4-lts
msg_error "Failed to install libaio1t64" Architectures: amd64 arm64
return 1 Signed-By: /etc/apt/keyrings/mysql.gpg
}
fi
# Create dummy libaio1 package for dependency satisfaction
local TEMP_DIR="/tmp/libaio1-compat-$$"
mkdir -p "$TEMP_DIR"
cd "$TEMP_DIR"
# Create control file
mkdir -p DEBIAN
cat >DEBIAN/control <<EOF
Package: libaio1
Version: 0.3.113-99~compat
Architecture: amd64
Maintainer: Local Build
Depends: libaio1t64
Provides: libaio1
Description: Compatibility package for libaio1 -> libaio1t64 transition
This is a transitional dummy package to satisfy dependencies on libaio1
while actually using libaio1t64 (time64 transition).
EOF EOF
$STD apt update
# Build the dummy package if ! $STD apt install -y mysql-community-server mysql-community-client; then
cd /tmp msg_error "MySQL 8.4 LTS installation failed falling back to MariaDB"
dpkg-deb -b "$TEMP_DIR" libaio1-compat.deb >/dev/null 2>&1 $STD apt install -y mariadb-server mariadb-client
fi
# Install it msg_ok "Setup Database Engine (MySQL 8.4 LTS / MariaDB)"
$STD dpkg -i libaio1-compat.deb return
# Cleanup
rm -rf "$TEMP_DIR" libaio1-compat.deb
fi fi
# -------------------------------------------------------------
# Use standardized repo setup
setup_deb822_repo \ setup_deb822_repo \
"mysql" \ "mysql" \
"https://repo.mysql.com/RPM-GPG-KEY-mysql-2023" \ "https://repo.mysql.com/RPM-GPG-KEY-mysql-2023" \
@ -2553,37 +2512,26 @@ EOF
"amd64 arm64" "amd64 arm64"
export DEBIAN_FRONTEND=noninteractive export DEBIAN_FRONTEND=noninteractive
# Update apt
if ! $STD apt update; then if ! $STD apt update; then
msg_error "APT update failed for MySQL repository" msg_error "APT update failed for MySQL repository"
return 1 return 1
fi fi
# Try multiple MySQL package patterns
local mysql_install_success=false local mysql_install_success=false
# First try: mysql-server (most common)
if apt-cache search "^mysql-server$" 2>/dev/null | grep -q . && $STD apt install -y mysql-server mysql-client 2>/dev/null; then if apt-cache search "^mysql-server$" 2>/dev/null | grep -q . && $STD apt install -y mysql-server mysql-client 2>/dev/null; then
mysql_install_success=true mysql_install_success=true
fi fi
# Second try: mysql-community-server (when official repo)
if [[ "$mysql_install_success" == false ]] && apt-cache search "^mysql-community-server$" 2>/dev/null | grep -q . && $STD apt install -y mysql-community-server mysql-community-client 2>/dev/null; then if [[ "$mysql_install_success" == false ]] && apt-cache search "^mysql-community-server$" 2>/dev/null | grep -q . && $STD apt install -y mysql-community-server mysql-community-client 2>/dev/null; then
mysql_install_success=true mysql_install_success=true
fi fi
# Third try: just mysql meta package
if [[ "$mysql_install_success" == false ]] && apt-cache search "^mysql$" 2>/dev/null | grep -q . && $STD apt install -y mysql 2>/dev/null; then if [[ "$mysql_install_success" == false ]] && apt-cache search "^mysql$" 2>/dev/null | grep -q . && $STD apt install -y mysql 2>/dev/null; then
mysql_install_success=true mysql_install_success=true
fi fi
if [[ "$mysql_install_success" == false ]]; then if [[ "$mysql_install_success" == false ]]; then
msg_error "MySQL ${MYSQL_VERSION} package not available for suite ${SUITE}" msg_error "MySQL ${MYSQL_VERSION} package not available for suite ${SUITE}"
return 1 return 1
fi fi
# Verify installation
if ! command -v mysql >/dev/null 2>&1; then if ! command -v mysql >/dev/null 2>&1; then
hash -r hash -r
if ! command -v mysql >/dev/null 2>&1; then if ! command -v mysql >/dev/null 2>&1; then