Skip to content

Commit c24f067

Browse files
authored
Merge pull request #1696 from master3395/v2.5.5-dev
fix: use mariadb CLI instead of deprecated mysql (version check, GRAN…
2 parents 0d77d07 + 41c708e commit c24f067

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

cyberpanel.sh

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ MARIADB_VER=""
1515
DEBUG_MODE=false
1616
AUTO_INSTALL=false
1717
INSTALLATION_TYPE=""
18+
# Prefer mariadb CLI (mysql is deprecated)
19+
MDB_CLI="mariadb"; command -v mariadb >/dev/null 2>&1 || MDB_CLI="mysql"
1820

1921
# Logging function
2022
log_message() {
@@ -221,7 +223,7 @@ fix_post_install_issues() {
221223
# Wait for MariaDB to be ready
222224
local retry_count=0
223225
while [ $retry_count -lt 10 ]; do
224-
if mysql -e "SELECT 1;" >/dev/null 2>&1; then
226+
if $MDB_CLI -e "SELECT 1;" >/dev/null 2>&1; then
225227
break
226228
fi
227229
echo " Waiting for MariaDB to be ready... ($((retry_count + 1))/10)"
@@ -231,34 +233,34 @@ fix_post_install_issues() {
231233

232234
# Create database user with proper permissions
233235
echo " Dropping existing cyberpanel user..."
234-
mysql -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
235-
mysql -e "DROP USER IF EXISTS 'cyberpanel'@'%';" 2>/dev/null || true
236+
$MDB_CLI -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
237+
$MDB_CLI -e "DROP USER IF EXISTS 'cyberpanel'@'%';" 2>/dev/null || true
236238

237239
echo " Creating cyberpanel user with correct password..."
238-
mysql -e "CREATE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
239-
mysql -e "CREATE USER 'cyberpanel'@'%' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
240+
$MDB_CLI -e "CREATE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
241+
$MDB_CLI -e "CREATE USER 'cyberpanel'@'%' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
240242

241243
echo " Granting privileges..."
242-
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
243-
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'%' WITH GRANT OPTION;" 2>/dev/null || true
244-
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
244+
$MDB_CLI -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
245+
$MDB_CLI -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'%' WITH GRANT OPTION;" 2>/dev/null || true
246+
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
245247

246248
# Verify the user was created correctly
247249
echo " Verifying database user..."
248-
if mysql -u cyberpanel -pcyberpanel -e "SELECT 1;" >/dev/null 2>&1; then
250+
if $MDB_CLI -u cyberpanel -pcyberpanel -e "SELECT 1;" >/dev/null 2>&1; then
249251
echo " ✅ Database user verification successful"
250252
else
251253
echo " ⚠️ Database user verification failed, trying alternative approach..."
252254
# Alternative: use root to create the user
253-
mysql -e "CREATE OR REPLACE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
254-
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
255-
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
255+
$MDB_CLI -e "CREATE OR REPLACE USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
256+
$MDB_CLI -e "GRANT ALL PRIVILEGES ON *.* TO 'cyberpanel'@'localhost' WITH GRANT OPTION;" 2>/dev/null || true
257+
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
256258
fi
257259

258260
# Create CyberPanel database if it doesn't exist
259-
mysql -e "CREATE DATABASE IF NOT EXISTS cyberpanel;" 2>/dev/null || true
260-
mysql -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost';" 2>/dev/null || true
261-
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
261+
$MDB_CLI -e "CREATE DATABASE IF NOT EXISTS cyberpanel;" 2>/dev/null || true
262+
$MDB_CLI -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost';" 2>/dev/null || true
263+
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
262264

263265
# Get or set unified password for both CyberPanel and OpenLiteSpeed
264266
local unified_password=""
@@ -278,8 +280,8 @@ fix_post_install_issues() {
278280
echo " Password: $unified_password"
279281

280282
# First, ensure the cyberpanel user exists and has correct password
281-
mysql -e "ALTER USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
282-
mysql -e "FLUSH PRIVILEGES;" 2>/dev/null || true
283+
$MDB_CLI -e "ALTER USER 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel';" 2>/dev/null || true
284+
$MDB_CLI -e "FLUSH PRIVILEGES;" 2>/dev/null || true
283285

284286
# Wait a moment for the database to be ready
285287
sleep 2
@@ -289,7 +291,7 @@ fix_post_install_issues() {
289291
/usr/local/CyberCP/bin/python3 /usr/local/CyberCP/plogical/adminPass.py 2>/dev/null || {
290292
echo " Admin password reset failed, trying alternative method..."
291293
# Alternative method: directly update the database
292-
mysql -u cyberpanel -pcyberpanel cyberpanel -e "UPDATE Administrator SET password = '$unified_password' WHERE id = 1;" 2>/dev/null || true
294+
$MDB_CLI -u cyberpanel -pcyberpanel cyberpanel -e "UPDATE Administrator SET password = '$unified_password' WHERE id = 1;" 2>/dev/null || true
293295
}
294296

295297
# Set OpenLiteSpeed admin password
@@ -441,7 +443,7 @@ verify_installation() {
441443
fi
442444

443445
# Check database connection
444-
if mysql -e "SELECT 1;" >/dev/null 2>&1; then
446+
if $MDB_CLI -e "SELECT 1;" >/dev/null 2>&1; then
445447
echo " ✅ Database connection is working"
446448
else
447449
echo " ❌ Database connection failed"
@@ -582,8 +584,8 @@ cleanup_existing_cyberpanel() {
582584
rm -f /etc/systemd/system/lsws.service 2>/dev/null || true
583585

584586
# Clean up databases
585-
mysql -e "DROP DATABASE IF EXISTS cyberpanel;" 2>/dev/null || true
586-
mysql -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
587+
$MDB_CLI -e "DROP DATABASE IF EXISTS cyberpanel;" 2>/dev/null || true
588+
$MDB_CLI -e "DROP USER IF EXISTS 'cyberpanel'@'localhost';" 2>/dev/null || true
587589

588590
echo " ✅ Cleanup completed"
589591
}

cyberpanel_upgrade.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ Git_User=""
7474
Git_Content_URL=""
7575
Git_Clone_URL=""
7676

77-
MySQL_Version=$(mysql -V | grep -P '\d+.\d+.\d+' -o)
77+
# Prefer mariadb CLI (mysql is deprecated and prints a warning)
78+
MySQL_Version=$(mariadb -V 2>/dev/null | grep -P '\d+.\d+.\d+' -o || mysql -V 2>/dev/null | grep -P '\d+.\d+.\d+' -o)
7879
MySQL_Password=$(cat /etc/cyberpanel/mysqlPassword)
7980

8081

@@ -418,14 +419,16 @@ if [[ "$MySQL_Version" = "10.1" ]]; then
418419
rm -rf /etc/my.cnf.d/
419420
mv /etc/cnfbackup/my.cnf.d /etc/
420421

421-
systemctl enable mysql
422-
systemctl start mysql
422+
# Prefer mariadb service name (mysql is deprecated)
423+
systemctl enable mariadb 2>/dev/null || systemctl enable mysql
424+
systemctl start mariadb 2>/dev/null || systemctl start mysql
423425

424-
mysql_upgrade -uroot -p"$MySQL_Password"
426+
mariadb-upgrade -uroot -p"$MySQL_Password" 2>/dev/null || mysql_upgrade -uroot -p"$MySQL_Password"
425427

426428
fi
427429

428-
mysql -uroot -p"$MySQL_Password" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$MySQL_Password';flush privileges"
430+
# Prefer mariadb CLI to avoid "mysql: Deprecated program name" warning
431+
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"
429432
}
430433

431434
Pre_Upgrade_Setup_Repository() {

plogical/upgrade.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def recover_database_credentials():
263263
except Exception as e:
264264
print("Failed to reset cyberpanel database user: %s" % str(e))
265265
print("Manual intervention required. Please run:")
266-
print(" mysql -u root -p")
266+
print(" mariadb -u root -p")
267267
print(" CREATE DATABASE IF NOT EXISTS cyberpanel;")
268268
print(" GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost' IDENTIFIED BY 'your_password';")
269269
print(" FLUSH PRIVILEGES;")
@@ -4803,16 +4803,17 @@ def fixDatabaseConnectivity():
48034803
pass
48044804
time.sleep(2)
48054805

4806-
# Ensure cyberpanel database exists
4806+
# Ensure cyberpanel database exists (prefer mariadb CLI; mysql is deprecated)
48074807
try:
4808-
result = subprocess.run(['mysql', '-e', 'USE cyberpanel;'], capture_output=True)
4808+
_mdb = shutil.which('mariadb') or 'mysql'
4809+
result = subprocess.run([_mdb, '-e', 'USE cyberpanel;'], capture_output=True)
48094810
if result.returncode != 0:
48104811
Upgrade.stdOut("Creating cyberpanel database...", 1)
48114812
commands = [
4812-
'mysql -e "CREATE DATABASE IF NOT EXISTS cyberpanel;"',
4813-
'mysql -e "CREATE USER IF NOT EXISTS \'cyberpanel\'@\'localhost\' IDENTIFIED BY \'cyberpanel\';"',
4814-
'mysql -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO \'cyberpanel\'@\'localhost\';"',
4815-
'mysql -e "FLUSH PRIVILEGES;"'
4813+
_mdb + ' -e "CREATE DATABASE IF NOT EXISTS cyberpanel;"',
4814+
_mdb + ' -e "CREATE USER IF NOT EXISTS \'cyberpanel\'@\'localhost\' IDENTIFIED BY \'cyberpanel\';"',
4815+
_mdb + ' -e "GRANT ALL PRIVILEGES ON cyberpanel.* TO \'cyberpanel\'@\'localhost\';"',
4816+
_mdb + ' -e "FLUSH PRIVILEGES;"'
48164817
]
48174818
for cmd in commands:
48184819
Upgrade.executioner(cmd, 'Setup cyberpanel database', 0)

0 commit comments

Comments
 (0)