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:
parent
2e34f534eb
commit
0f69e8cc69
102
misc/tools.func
102
misc/tools.func
@ -2451,14 +2451,8 @@ function setup_mysql() {
|
||||
NEED_INSTALL=true
|
||||
else
|
||||
if apt list --upgradable 2>/dev/null | grep -q '^mysql-server/'; then
|
||||
$STD apt update || {
|
||||
msg_error "Failed to update package list"
|
||||
return 1
|
||||
}
|
||||
$STD apt install --only-upgrade -y mysql-server || {
|
||||
msg_error "Failed to upgrade MySQL"
|
||||
return 1
|
||||
}
|
||||
$STD apt update || { msg_error "Failed to update package list"; return 1; }
|
||||
$STD apt install --only-upgrade -y mysql-server || { msg_error "Failed to upgrade MySQL"; return 1; }
|
||||
fi
|
||||
return
|
||||
fi
|
||||
@ -2469,81 +2463,46 @@ function setup_mysql() {
|
||||
if [[ "$NEED_INSTALL" == true ]]; then
|
||||
msg_info "Setup MySQL $MYSQL_VERSION"
|
||||
|
||||
# Cleanup old repository files
|
||||
cleanup_old_repo_files "mysql"
|
||||
|
||||
# Determine suite - use bookworm for Debian testing/unstable
|
||||
local SUITE
|
||||
if [[ "$DISTRO_ID" == "debian" ]]; then
|
||||
case "$DISTRO_CODENAME" in
|
||||
bookworm | bullseye)
|
||||
SUITE="$DISTRO_CODENAME"
|
||||
;;
|
||||
trixie | forky | sid)
|
||||
SUITE="bookworm"
|
||||
;;
|
||||
*)
|
||||
SUITE="bookworm" # Fallback to bookworm for unknown Debian versions
|
||||
;;
|
||||
bookworm|bullseye) SUITE="$DISTRO_CODENAME" ;;
|
||||
trixie|forky|sid) SUITE="bookworm" ;;
|
||||
*) SUITE="bookworm" ;;
|
||||
esac
|
||||
else
|
||||
# For Ubuntu - use fallback detection
|
||||
SUITE=$(get_fallback_suite "$DISTRO_ID" "$DISTRO_CODENAME" "https://repo.mysql.com/apt/${DISTRO_ID}")
|
||||
fi
|
||||
|
||||
# Stop existing MySQL if running
|
||||
$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
|
||||
$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
|
||||
|
||||
# Handle libaio dependency for Debian Trixie+ (time64 transition)
|
||||
if [[ "$DISTRO_ID" == "debian" ]] && [[ "$DISTRO_CODENAME" =~ ^(trixie|forky|sid)$ ]]; then
|
||||
# Install libaio1t64 if not present
|
||||
if ! dpkg -l libaio1t64 2>/dev/null | grep -q "^ii"; then
|
||||
$STD apt update || {
|
||||
msg_error "Failed to update package list"
|
||||
return 1
|
||||
}
|
||||
$STD apt install -y libaio1t64 || {
|
||||
msg_error "Failed to install libaio1t64"
|
||||
return 1
|
||||
}
|
||||
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).
|
||||
# --- Debian 13+ Fix: MySQL 8.0 incompatible with libaio1t64 ---
|
||||
if [[ "$DISTRO_ID" == "debian" && "$DISTRO_CODENAME" =~ ^(trixie|forky|sid)$ ]]; then
|
||||
msg_info "Debian ${DISTRO_CODENAME} detected → using MySQL 8.4 LTS (libaio1t64)"
|
||||
curl -fsSL https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 | gpg --dearmor -o /etc/apt/keyrings/mysql.gpg
|
||||
cat >/etc/apt/sources.list.d/mysql.sources <<'EOF'
|
||||
Types: deb
|
||||
URIs: https://repo.mysql.com/apt/debian/
|
||||
Suites: bookworm
|
||||
Components: mysql-8.4-lts
|
||||
Architectures: amd64 arm64
|
||||
Signed-By: /etc/apt/keyrings/mysql.gpg
|
||||
EOF
|
||||
|
||||
# Build the dummy package
|
||||
cd /tmp
|
||||
dpkg-deb -b "$TEMP_DIR" libaio1-compat.deb >/dev/null 2>&1
|
||||
|
||||
# Install it
|
||||
$STD dpkg -i libaio1-compat.deb
|
||||
|
||||
# Cleanup
|
||||
rm -rf "$TEMP_DIR" libaio1-compat.deb
|
||||
$STD apt update
|
||||
if ! $STD apt install -y mysql-community-server mysql-community-client; then
|
||||
msg_error "MySQL 8.4 LTS installation failed – falling back to MariaDB"
|
||||
$STD apt install -y mariadb-server mariadb-client
|
||||
fi
|
||||
msg_ok "Setup Database Engine (MySQL 8.4 LTS / MariaDB)"
|
||||
return
|
||||
fi
|
||||
# -------------------------------------------------------------
|
||||
|
||||
# Use standardized repo setup
|
||||
setup_deb822_repo \
|
||||
"mysql" \
|
||||
"https://repo.mysql.com/RPM-GPG-KEY-mysql-2023" \
|
||||
@ -2553,37 +2512,26 @@ EOF
|
||||
"amd64 arm64"
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Update apt
|
||||
if ! $STD apt update; then
|
||||
msg_error "APT update failed for MySQL repository"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Try multiple MySQL package patterns
|
||||
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
|
||||
mysql_install_success=true
|
||||
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
|
||||
mysql_install_success=true
|
||||
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
|
||||
mysql_install_success=true
|
||||
fi
|
||||
|
||||
if [[ "$mysql_install_success" == false ]]; then
|
||||
msg_error "MySQL ${MYSQL_VERSION} package not available for suite ${SUITE}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Verify installation
|
||||
if ! command -v mysql >/dev/null 2>&1; then
|
||||
hash -r
|
||||
if ! command -v mysql >/dev/null 2>&1; then
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user