mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-12-23 16:59:44 +01:00
Add force reinstall option and cleanup functions to CyberPanel installation script
- Introduced a new function to check if CyberPanel is already installed and clean up existing installations if necessary. - Added a force reinstall option in the main menu, allowing users to completely remove and reinstall CyberPanel. - Enhanced user prompts and feedback during the cleanup and reinstallation process to improve clarity and user experience.
This commit is contained in:
100
cyberpanel.sh
100
cyberpanel.sh
@@ -376,10 +376,49 @@ install_cyberpanel() {
|
|||||||
install_cyberpanel_direct
|
install_cyberpanel_direct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to check if CyberPanel is already installed
|
||||||
|
check_cyberpanel_installed() {
|
||||||
|
if [ -d "/usr/local/CyberPanel" ] || [ -d "/usr/local/CyberCP" ] || [ -f "/usr/local/lsws/bin/lswsctrl" ]; then
|
||||||
|
return 0 # CyberPanel is installed
|
||||||
|
else
|
||||||
|
return 1 # CyberPanel is not installed
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to clean up existing CyberPanel installation
|
||||||
|
cleanup_existing_cyberpanel() {
|
||||||
|
echo " 🧹 Cleaning up existing CyberPanel installation..."
|
||||||
|
|
||||||
|
# Stop services
|
||||||
|
systemctl stop lsws mariadb 2>/dev/null || true
|
||||||
|
|
||||||
|
# Remove CyberPanel directories
|
||||||
|
rm -rf /usr/local/CyberPanel 2>/dev/null || true
|
||||||
|
rm -rf /usr/local/CyberCP 2>/dev/null || true
|
||||||
|
rm -rf /usr/local/lsws 2>/dev/null || true
|
||||||
|
|
||||||
|
# Remove systemd services
|
||||||
|
systemctl disable lsws mariadb 2>/dev/null || true
|
||||||
|
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
|
||||||
|
|
||||||
|
echo " ✅ Cleanup completed"
|
||||||
|
}
|
||||||
|
|
||||||
# Function to install CyberPanel directly using the working method
|
# Function to install CyberPanel directly using the working method
|
||||||
install_cyberpanel_direct() {
|
install_cyberpanel_direct() {
|
||||||
echo " 🔄 Downloading CyberPanel installation files..."
|
echo " 🔄 Downloading CyberPanel installation files..."
|
||||||
|
|
||||||
|
# Check if CyberPanel is already installed
|
||||||
|
if check_cyberpanel_installed; then
|
||||||
|
echo " ⚠️ CyberPanel is already installed but may not be working properly"
|
||||||
|
echo " 🔧 Cleaning up existing installation and reinstalling..."
|
||||||
|
cleanup_existing_cyberpanel
|
||||||
|
fi
|
||||||
|
|
||||||
# Pre-installation system checks
|
# Pre-installation system checks
|
||||||
echo " 🔍 Running pre-installation checks..."
|
echo " 🔍 Running pre-installation checks..."
|
||||||
|
|
||||||
@@ -773,16 +812,17 @@ show_main_menu() {
|
|||||||
echo " 1. Fresh Installation (Recommended)"
|
echo " 1. Fresh Installation (Recommended)"
|
||||||
echo " 2. Update Existing Installation"
|
echo " 2. Update Existing Installation"
|
||||||
echo " 3. Reinstall CyberPanel"
|
echo " 3. Reinstall CyberPanel"
|
||||||
echo " 4. Pre-Upgrade (Download latest upgrade script)"
|
echo " 4. Force Reinstall (Clean & Install)"
|
||||||
echo " 5. Check System Status"
|
echo " 5. Pre-Upgrade (Download latest upgrade script)"
|
||||||
echo " 6. Advanced Options"
|
echo " 6. Check System Status"
|
||||||
echo " 7. Exit"
|
echo " 7. Advanced Options"
|
||||||
|
echo " 8. Exit"
|
||||||
echo ""
|
echo ""
|
||||||
echo "==============================================================================================================="
|
echo "==============================================================================================================="
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
echo -n "Enter your choice [1-7]: "
|
echo -n "Enter your choice [1-8]: "
|
||||||
read -r choice
|
read -r choice
|
||||||
|
|
||||||
case $choice in
|
case $choice in
|
||||||
@@ -802,19 +842,23 @@ show_main_menu() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
4)
|
4)
|
||||||
start_preupgrade
|
INSTALLATION_TYPE="force_reinstall"
|
||||||
|
start_force_reinstall
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
5)
|
5)
|
||||||
show_system_status
|
start_preupgrade
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
6)
|
6)
|
||||||
show_advanced_menu
|
show_system_status
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
7)
|
7)
|
||||||
echo ""
|
show_advanced_menu
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
8)
|
||||||
echo "Goodbye!"
|
echo "Goodbye!"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
@@ -1788,6 +1832,44 @@ start_upgrade() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to start force reinstall
|
||||||
|
start_force_reinstall() {
|
||||||
|
echo ""
|
||||||
|
echo "==============================================================================================================="
|
||||||
|
echo " FORCE REINSTALL CYBERPANEL"
|
||||||
|
echo "==============================================================================================================="
|
||||||
|
echo ""
|
||||||
|
echo "This will completely remove the existing CyberPanel installation and install a fresh copy."
|
||||||
|
echo "All data and configurations will be lost!"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
echo -n "Are you sure you want to proceed? (y/N): "
|
||||||
|
read -r confirm
|
||||||
|
case $confirm in
|
||||||
|
[Yy]*)
|
||||||
|
echo ""
|
||||||
|
echo "Starting force reinstall..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Clean up existing installation
|
||||||
|
cleanup_existing_cyberpanel
|
||||||
|
|
||||||
|
# Start fresh installation
|
||||||
|
start_installation
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
[Nn]*|"")
|
||||||
|
echo "Force reinstall cancelled."
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Please answer yes or no."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
# Function to start preupgrade
|
# Function to start preupgrade
|
||||||
start_preupgrade() {
|
start_preupgrade() {
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
Reference in New Issue
Block a user