mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-10-30 01:36:30 +01:00
Enhance CyberPanel installation script with improved error handling and verification
- Added checks to ensure successful download and execution of the CyberPanel installer. - Implemented detailed error messages for various failure scenarios during installation. - Introduced debugging output for better visibility into the installer script's behavior. - Enhanced progress monitoring with minimum wait time and timeout handling during installation. - Improved overall structure and readability of the script for better maintainability.
This commit is contained in:
@@ -221,9 +221,42 @@ install_cyberpanel() {
|
||||
curl --silent -o cyberpanel_original.sh "https://cyberpanel.sh/?dl&$SERVER_OS" 2>/dev/null
|
||||
fi
|
||||
|
||||
# Check if download was successful
|
||||
if [ $? -ne 0 ]; then
|
||||
print_status "ERROR: Failed to download CyberPanel installer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
chmod +x cyberpanel_original.sh
|
||||
|
||||
echo " ✓ CyberPanel installer downloaded"
|
||||
# Verify the downloaded file
|
||||
if [ ! -f "cyberpanel_original.sh" ] || [ ! -x "cyberpanel_original.sh" ]; then
|
||||
print_status "ERROR: Failed to download or make executable the CyberPanel installer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if the file has content (not empty)
|
||||
if [ ! -s "cyberpanel_original.sh" ]; then
|
||||
print_status "ERROR: Downloaded CyberPanel installer is empty"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if the file is actually a shell script
|
||||
if ! head -1 cyberpanel_original.sh | grep -q "#!/bin/bash"; then
|
||||
print_status "ERROR: Downloaded file is not a valid shell script"
|
||||
echo "First line of downloaded file:"
|
||||
head -1 cyberpanel_original.sh
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Show first few lines of the downloaded file for debugging
|
||||
if [ "$DEBUG_MODE" = true ]; then
|
||||
echo "First 10 lines of downloaded installer:"
|
||||
head -10 cyberpanel_original.sh
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo " ✓ CyberPanel installer downloaded and verified"
|
||||
echo " 🔄 Starting CyberPanel installation..."
|
||||
echo ""
|
||||
echo "IMPORTANT: The installation is now running in the background."
|
||||
@@ -238,10 +271,31 @@ install_cyberpanel() {
|
||||
echo "This may take several minutes. Please be patient."
|
||||
echo ""
|
||||
|
||||
# Test the installer first
|
||||
echo "Testing CyberPanel installer..."
|
||||
if ! ./cyberpanel_original.sh --help > /dev/null 2>&1; then
|
||||
print_status "ERROR: CyberPanel installer is not working properly"
|
||||
echo "Trying to run installer directly:"
|
||||
./cyberpanel_original.sh --help 2>&1 || echo "Failed to run installer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Start the installer in background and monitor progress
|
||||
echo "Starting CyberPanel installer with PID tracking..."
|
||||
./cyberpanel_original.sh $([ "$DEBUG_MODE" = true ] && echo "--debug") > /tmp/cyberpanel_install_output.log 2>&1 &
|
||||
local install_pid=$!
|
||||
|
||||
# Give the process a moment to start
|
||||
sleep 2
|
||||
|
||||
# Check if the process is still running
|
||||
if ! kill -0 $install_pid 2>/dev/null; then
|
||||
print_status "ERROR: CyberPanel installer failed to start or exited immediately"
|
||||
echo "Installation log:"
|
||||
cat /tmp/cyberpanel_install_output.log 2>/dev/null || echo "No log file found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Active progress bar with real-time updates
|
||||
local progress=0
|
||||
local bar_length=50
|
||||
@@ -254,25 +308,40 @@ install_cyberpanel() {
|
||||
echo ""
|
||||
|
||||
# Monitor the installation process
|
||||
local min_wait_time=30 # Minimum 30 seconds before allowing completion
|
||||
local max_wait_time=1800 # Maximum 30 minutes timeout
|
||||
while true; do
|
||||
# Check if process is still running
|
||||
if ! kill -0 $install_pid 2>/dev/null; then
|
||||
# Process has finished, break the loop
|
||||
# Process has finished, but wait minimum time
|
||||
if [ $elapsed -ge $min_wait_time ]; then
|
||||
break
|
||||
else
|
||||
# Still within minimum wait time, continue monitoring
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
local current_time=$(date +%s)
|
||||
local elapsed=$((current_time - start_time))
|
||||
|
||||
# Calculate progress based on elapsed time (more realistic)
|
||||
# Check for timeout
|
||||
if [ $elapsed -gt $max_wait_time ]; then
|
||||
print_status "ERROR: Installation timeout after $((max_wait_time / 60)) minutes"
|
||||
kill $install_pid 2>/dev/null || true
|
||||
break
|
||||
fi
|
||||
|
||||
# Calculate progress based on elapsed time (conservative and realistic)
|
||||
if [ $elapsed -lt 30 ]; then
|
||||
progress=$((elapsed * 3)) # 0-90% in first 30 seconds
|
||||
progress=$((elapsed * 2)) # 0-60% in first 30 seconds
|
||||
elif [ $elapsed -lt 120 ]; then
|
||||
progress=$((90 + (elapsed - 30) * 1)) # 90-180% in next 90 seconds
|
||||
progress=$((60 + (elapsed - 30) * 1)) # 60-150% in next 90 seconds
|
||||
elif [ $elapsed -lt 300 ]; then
|
||||
progress=$((180 + (elapsed - 120) * 1)) # 180-360% in next 3 minutes
|
||||
progress=$((150 + (elapsed - 120) * 1)) # 150-330% in next 3 minutes
|
||||
else
|
||||
progress=$((360 + (elapsed - 300) * 1)) # 360%+ after 5 minutes
|
||||
progress=$((330 + (elapsed - 300) * 1)) # 330%+ after 5 minutes
|
||||
fi
|
||||
|
||||
# Cap progress at 95% until actually complete
|
||||
@@ -332,7 +401,13 @@ install_cyberpanel() {
|
||||
print_status "SUCCESS: CyberPanel installed successfully"
|
||||
return 0
|
||||
else
|
||||
print_status "ERROR: CyberPanel installation failed. Check /tmp/cyberpanel_install_output.log for details"
|
||||
print_status "ERROR: CyberPanel installation failed (exit code: $install_status)"
|
||||
print_status "Check /tmp/cyberpanel_install_output.log for details"
|
||||
echo ""
|
||||
echo "Last 20 lines of the installation log:"
|
||||
echo "==============================================================================================================="
|
||||
tail -20 /tmp/cyberpanel_install_output.log 2>/dev/null || echo "Log file not found or empty"
|
||||
echo "==============================================================================================================="
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user