Merge pull request #1696 from master3395/v2.5.5-dev

fix: use mariadb CLI instead of deprecated mysql (version check, GRAN…
This commit is contained in:
Master3395
2026-02-15 02:12:12 +01:00
committed by GitHub
3 changed files with 39 additions and 33 deletions

View File

@@ -15,6 +15,8 @@ MARIADB_VER=""
DEBUG_MODE=false
AUTO_INSTALL=false
INSTALLATION_TYPE=""
# Prefer mariadb CLI (mysql is deprecated)
MDB_CLI="mariadb"; command -v mariadb >/dev/null 2>&1 || MDB_CLI="mysql"
# Logging function
log_message() {
@@ -221,7 +223,7 @@ fix_post_install_issues() {
# Wait for MariaDB to be ready
local retry_count=0
while [ $retry_count -lt 10 ]; do
if mysql -e "SELECT 1;" >/dev/null 2>&1; then
if $MDB_CLI -e "SELECT 1;" >/dev/null 2>&1; then
break
fi
echo " Waiting for MariaDB to be ready... ($((retry_count + 1))/10)"
@@ -231,34 +233,34 @@ fix_post_install_issues() {
# Create database user with proper permissions
echo " Dropping existing cyberpanel user..."
mysql -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
mysql -e "DROP USER IF EXISTS 'cyberpanel'@'%';" 2>/dev/null || true
$MDB_CLI -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
$MDB_CLI -e "DROP USER IF EXISTS 'cyberpanel'@'%';" 2>/dev/null || true
echo " Creating cyberpanel user with correct password..."
mysql -e "CREATE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
mysql -e "CREATE USER 'cyberpanel'@'%' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
$MDB_CLI -e "CREATE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
$MDB_CLI -e "CREATE USER 'cyberpanel'@'%' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
echo " Granting privileges..."
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'%' WITH GRANT OPTION;" 2>/dev/null || true
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
$MDB_CLI -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
$MDB_CLI -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'%' WITH GRANT OPTION;" 2>/dev/null || true
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
# Verify the user was created correctly
echo " Verifying database user..."
if mysql -u cyberpanel -pcyberpanel -e "SELECT 1;" >/dev/null 2>&1; then
if $MDB_CLI -u cyberpanel -pcyberpanel -e "SELECT 1;" >/dev/null 2>&1; then
echo " ✅ Database user verification successful"
else
echo " ⚠️ Database user verification failed, trying alternative approach..."
# Alternative: use root to create the user
mysql -e "CREATE OR REPLACE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
$MDB_CLI -e "CREATE OR REPLACE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
$MDB_CLI -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
fi
# Create CyberPanel database if it doesn't exist
mysql -e "CREATE DATABASE IF NOT EXISTS cyberpanel;" 2>/dev/null || true
mysql -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost';" 2>/dev/null || true
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
$MDB_CLI -e "CREATE DATABASE IF NOT EXISTS cyberpanel;" 2>/dev/null || true
$MDB_CLI -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost';" 2>/dev/null || true
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
# Get or set unified password for both CyberPanel and OpenLiteSpeed
local unified_password=""
@@ -278,8 +280,8 @@ fix_post_install_issues() {
echo " Password: $unified_password"
# First, ensure the cyberpanel user exists and has correct password
mysql -e "ALTER USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
$MDB_CLI -e "ALTER USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
# Wait a moment for the database to be ready
sleep 2
@@ -289,7 +291,7 @@ fix_post_install_issues() {
/usr/local/CyberCP/bin/python3 /usr/local/CyberCP/plogical/adminPass.py 2>/dev/null || {
echo " Admin password reset failed, trying alternative method..."
# Alternative method: directly update the database
mysql -u cyberpanel -pcyberpanel cyberpanel -e "UPDATE Administrator SET password = '$unified_password' WHERE id = 1;" 2>/dev/null || true
$MDB_CLI -u cyberpanel -pcyberpanel cyberpanel -e "UPDATE Administrator SET password = '$unified_password' WHERE id = 1;" 2>/dev/null || true
}
# Set OpenLiteSpeed admin password
@@ -441,7 +443,7 @@ verify_installation() {
fi
# Check database connection
if mysql -e "SELECT 1;" >/dev/null 2>&1; then
if $MDB_CLI -e "SELECT 1;" >/dev/null 2>&1; then
echo " ✅ Database connection is working"
else
echo " ❌ Database connection failed"
@@ -582,8 +584,8 @@ cleanup_existing_cyberpanel() {
rm -f /etc/systemd/system/lsws.service 2>/dev/null || true
# Clean up databases
mysql -e "DROP DATABASE IF EXISTS cyberpanel;" 2>/dev/null || true
mysql -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
$MDB_CLI -e "DROP DATABASE IF EXISTS cyberpanel;" 2>/dev/null || true
$MDB_CLI -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
echo " ✅ Cleanup completed"
}

View File

@@ -74,7 +74,8 @@ Git_User=""
Git_Content_URL=""
Git_Clone_URL=""
MySQL_Version=$(mysql -V | grep -P '\d+.\d+.\d+' -o)
# Prefer mariadb CLI (mysql is deprecated and prints a warning)
MySQL_Version=$(mariadb -V 2>/dev/null | grep -P '\d+.\d+.\d+' -o || mysql -V 2>/dev/null | grep -P '\d+.\d+.\d+' -o)
MySQL_Password=$(cat /etc/cyberpanel/mysqlPassword)
@@ -418,14 +419,16 @@ if [[ "$MySQL_Version" = "10.1" ]]; then
rm -rf /etc/my.cnf.d/
mv /etc/cnfbackup/my.cnf.d /etc/
systemctl enable mysql
systemctl start mysql
# Prefer mariadb service name (mysql is deprecated)
systemctl enable mariadb 2>/dev/null || systemctl enable mysql
systemctl start mariadb 2>/dev/null || systemctl start mysql
mysql_upgrade -uroot -p"$MySQL_Password"
mariadb-upgrade -uroot -p"$MySQL_Password" 2>/dev/null || mysql_upgrade -uroot -p"$MySQL_Password"
fi
mysql -uroot -p"$MySQL_Password" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$MySQL_Password';flush privileges"
# Prefer mariadb CLI to avoid "mysql: Deprecated program name" warning
mariadb -uroot -p"$MySQL_Password" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$MySQL_Password';flush privileges" 2>/dev/null || mysql -uroot -p"$MySQL_Password" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$MySQL_Password';flush privileges"
}
Pre_Upgrade_Setup_Repository() {

View File

@@ -263,7 +263,7 @@ except ImportError:
except Exception as e:
print("Failed to reset cyberpanel database user: %s" % str(e))
print("Manual intervention required. Please run:")
print(" mysql -u root -p")
print(" mariadb -u root -p")
print(" CREATE DATABASE IF NOT EXISTS cyberpanel;")
print(" GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost' IDENTIFIED BY 'your_password';")
print(" FLUSH PRIVILEGES;")
@@ -4803,16 +4803,17 @@ echo $oConfig->Save() ? 'Done' : 'Error';
pass
time.sleep(2)
# Ensure cyberpanel database exists
# Ensure cyberpanel database exists (prefer mariadb CLI; mysql is deprecated)
try:
result = subprocess.run(['mysql', '-e', 'USE cyberpanel;'], capture_output=True)
_mdb = shutil.which('mariadb') or 'mysql'
result = subprocess.run([_mdb, '-e', 'USE cyberpanel;'], capture_output=True)
if result.returncode != 0:
Upgrade.stdOut("Creating cyberpanel database...", 1)
commands = [
'mysql -e "CREATE DATABASE IF NOT EXISTS cyberpanel;"',
'mysql -e "CREATE USER IF NOT EXISTS \'cyberpanel\'@\'localhost\' IDENTIFIED BY \'cyberpanel\';"',
'mysql -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO \'cyberpanel\'@\'localhost\';"',
'mysql -e "FLUSH PRIVILEGES;"'
_mdb + ' -e "CREATE DATABASE IF NOT EXISTS cyberpanel;"',
_mdb + ' -e "CREATE USER IF NOT EXISTS \'cyberpanel\'@\'localhost\' IDENTIFIED BY \'cyberpanel\';"',
_mdb + ' -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO \'cyberpanel\'@\'localhost\';"',
_mdb + ' -e "FLUSH PRIVILEGES;"'
]
for cmd in commands:
Upgrade.executioner(cmd, 'Setup cyberpanel database', 0)