mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-09 16:56:03 +02:00
Fix syntax error (missing fi) and add disk space checking
- Fix missing 'fi' closing the TEMP_DIR check block - Add check_disk_space() function to verify minimum 10GB available - Display disk space requirements and available space - Warn if insufficient space but allow continuation
This commit is contained in:
103
install.sh
103
install.sh
@@ -63,40 +63,41 @@ if [[ "$SCRIPT_DIR" == /dev/fd/* ]] || [[ ! -d "$SCRIPT_DIR/modules" ]]; then
|
||||
|
||||
# Only attempt git clone if we have a temp directory
|
||||
if [ -n "$TEMP_DIR" ]; then
|
||||
|
||||
early_log "📦 Cloning CyberPanel repository (branch: $BRANCH_NAME)..."
|
||||
early_log "This may take a minute depending on your connection speed..."
|
||||
|
||||
# Try git clone with timeout and better error handling
|
||||
GIT_CLONE_SUCCESS=false
|
||||
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
if timeout 180 git clone --depth 1 --branch "$BRANCH_NAME" https://github.com/master3395/cyberpanel.git "$TEMP_DIR/cyberpanel" >/tmp/git-clone.log 2>&1; then
|
||||
GIT_CLONE_SUCCESS=true
|
||||
early_log "📦 Cloning CyberPanel repository (branch: $BRANCH_NAME)..."
|
||||
early_log "This may take a minute depending on your connection speed..."
|
||||
|
||||
# Try git clone with timeout and better error handling
|
||||
GIT_CLONE_SUCCESS=false
|
||||
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
if timeout 180 git clone --depth 1 --branch "$BRANCH_NAME" https://github.com/master3395/cyberpanel.git "$TEMP_DIR/cyberpanel" >/tmp/git-clone.log 2>&1; then
|
||||
GIT_CLONE_SUCCESS=true
|
||||
fi
|
||||
else
|
||||
# No timeout command, try without timeout
|
||||
if git clone --depth 1 --branch "$BRANCH_NAME" https://github.com/master3395/cyberpanel.git "$TEMP_DIR/cyberpanel" >/tmp/git-clone.log 2>&1; then
|
||||
GIT_CLONE_SUCCESS=true
|
||||
fi
|
||||
fi
|
||||
else
|
||||
# No timeout command, try without timeout
|
||||
if git clone --depth 1 --branch "$BRANCH_NAME" https://github.com/master3395/cyberpanel.git "$TEMP_DIR/cyberpanel" >/tmp/git-clone.log 2>&1; then
|
||||
GIT_CLONE_SUCCESS=true
|
||||
|
||||
# Verify clone was successful and structure is valid
|
||||
if [ "$GIT_CLONE_SUCCESS" = true ] && [ -d "$TEMP_DIR/cyberpanel" ] && [ -f "$TEMP_DIR/cyberpanel/install.sh" ] && [ -d "$TEMP_DIR/cyberpanel/modules" ]; then
|
||||
SCRIPT_DIR="$TEMP_DIR/cyberpanel"
|
||||
cd "$SCRIPT_DIR"
|
||||
early_log "✅ Repository cloned successfully"
|
||||
else
|
||||
# Git clone failed or structure invalid, use fallback
|
||||
GIT_ERROR=$(tail -3 /tmp/git-clone.log 2>/dev/null | tr '\n' ' ')
|
||||
early_log "⚠️ Git clone failed or incomplete"
|
||||
if [ -n "$GIT_ERROR" ]; then
|
||||
early_log "Last error: $GIT_ERROR"
|
||||
fi
|
||||
early_log "Falling back to legacy installer..."
|
||||
rm -rf "$TEMP_DIR/cyberpanel" 2>/dev/null || true
|
||||
TEMP_DIR="" # Clear TEMP_DIR to trigger fallback
|
||||
fi
|
||||
fi
|
||||
|
||||
# Verify clone was successful and structure is valid
|
||||
if [ "$GIT_CLONE_SUCCESS" = true ] && [ -d "$TEMP_DIR/cyberpanel" ] && [ -f "$TEMP_DIR/cyberpanel/install.sh" ] && [ -d "$TEMP_DIR/cyberpanel/modules" ]; then
|
||||
SCRIPT_DIR="$TEMP_DIR/cyberpanel"
|
||||
cd "$SCRIPT_DIR"
|
||||
early_log "✅ Repository cloned successfully"
|
||||
else
|
||||
# Git clone failed or structure invalid, use fallback
|
||||
GIT_ERROR=$(tail -3 /tmp/git-clone.log 2>/dev/null | tr '\n' ' ')
|
||||
early_log "⚠️ Git clone failed or incomplete"
|
||||
if [ -n "$GIT_ERROR" ]; then
|
||||
early_log "Last error: $GIT_ERROR"
|
||||
fi
|
||||
early_log "Falling back to legacy installer..."
|
||||
rm -rf "$TEMP_DIR/cyberpanel" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# If git clone failed or we couldn't create temp dir, use fallback
|
||||
if [ -z "$TEMP_DIR" ] || [ ! -d "$TEMP_DIR/cyberpanel" ] || [ ! -f "$TEMP_DIR/cyberpanel/install.sh" ]; then
|
||||
# Fallback: try to download install.sh from the old method
|
||||
@@ -136,7 +137,8 @@ if [[ "$SCRIPT_DIR" == /dev/fd/* ]] || [[ ! -d "$SCRIPT_DIR/modules" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi # Close the if [ -n "$TEMP_DIR" ] block
|
||||
fi # Close the if [[ "$SCRIPT_DIR" == /dev/fd/* ]] block
|
||||
|
||||
MODULES_DIR="$SCRIPT_DIR/modules"
|
||||
|
||||
@@ -380,6 +382,42 @@ parse_arguments() {
|
||||
done
|
||||
}
|
||||
|
||||
# Function to check disk space
|
||||
check_disk_space() {
|
||||
local required_gb=10 # Minimum 10GB required
|
||||
local root_available_gb=0
|
||||
|
||||
# Get available space on root filesystem
|
||||
if command -v df >/dev/null 2>&1; then
|
||||
root_available_gb=$(df -BG / | awk 'NR==2 {print $4}' | sed 's/G//' | cut -d. -f1)
|
||||
if [ -z "$root_available_gb" ] || [ "$root_available_gb" = "" ]; then
|
||||
# Try alternative method
|
||||
root_available_gb=$(df -BG / | tail -1 | awk '{print $4}' | sed 's/G//' | cut -d. -f1)
|
||||
fi
|
||||
fi
|
||||
|
||||
# If we couldn't get the value, try without -BG flag
|
||||
if [ -z "$root_available_gb" ] || ! [[ "$root_available_gb" =~ ^[0-9]+$ ]]; then
|
||||
root_available_gb=$(df / | awk 'NR==2 {print $4}' | awk '{printf "%.0f", $1/1024/1024}')
|
||||
fi
|
||||
|
||||
print_status "$BLUE" "💾 Checking disk space..."
|
||||
print_status "$BLUE" " Required: ${required_gb}GB minimum"
|
||||
|
||||
if [[ "$root_available_gb" =~ ^[0-9]+$ ]] && [ "$root_available_gb" -ge "$required_gb" ]; then
|
||||
print_status "$GREEN" " Available: ${root_available_gb}GB (✅ Sufficient)"
|
||||
return 0
|
||||
elif [[ "$root_available_gb" =~ ^[0-9]+$ ]]; then
|
||||
print_status "$YELLOW" " Available: ${root_available_gb}GB (⚠️ Less than ${required_gb}GB recommended)"
|
||||
print_status "$YELLOW" " Installation may fail if disk space runs out"
|
||||
return 1
|
||||
else
|
||||
print_status "$YELLOW" " Could not determine available disk space"
|
||||
print_status "$YELLOW" " Please ensure at least ${required_gb}GB is available"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main installation function
|
||||
main() {
|
||||
# Initialize log file
|
||||
@@ -389,6 +427,9 @@ main() {
|
||||
print_status "$BLUE" "🚀 Enhanced CyberPanel Installer Starting..."
|
||||
print_status "$BLUE" "Log file: /var/log/cyberpanel_install.log"
|
||||
|
||||
# Check disk space before proceeding
|
||||
check_disk_space
|
||||
|
||||
# Parse command line arguments
|
||||
parse_arguments "$@"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user