@@ -15,6 +15,8 @@ MARIADB_VER=""
1515DEBUG_MODE=false
1616AUTO_INSTALL=false
1717INSTALLATION_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
2022log_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}
0 commit comments