From 7cfe5d018d7b25bc6e86996334a8a6932530b0aa Mon Sep 17 00:00:00 2001 From: hhf Date: Fri, 6 Dec 2024 18:09:06 +0530 Subject: [PATCH] Update install-mailcow-ubuntu.sh --- install-mailcow-ubuntu.sh | 48 +++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/install-mailcow-ubuntu.sh b/install-mailcow-ubuntu.sh index 1243d7e..387bad3 100644 --- a/install-mailcow-ubuntu.sh +++ b/install-mailcow-ubuntu.sh @@ -135,27 +135,67 @@ if ! is_step_completed "mailcow_installed"; then mkdir -p "$MAILCOW_DIR" chown dockeruser:dockeruser "$MAILCOW_DIR" - # Clone repository + # Clone repository and set permissions su - dockeruser -c "cd /opt && git clone https://github.com/mailcow/mailcow-dockerized" + chown -R dockeruser:dockeruser "$MAILCOW_DIR" fi # Generate config if not already generated if [ ! -f "$MAILCOW_DIR/mailcow.conf" ]; then cd "$MAILCOW_DIR" - echo "$MAILCOW_HOSTNAME" | ./generate_config.sh + # Make sure generate_config.sh is executable + chmod +x generate_config.sh + log_message "Made generate_config.sh executable" + + # Debug: Show current directory and files + log_message "Current directory: $(pwd)" + log_message "Directory contents: $(ls -la)" + + # Generate config as dockeruser + log_message "Generating configuration with hostname: $MAILCOW_HOSTNAME" + su - dockeruser -c "cd $MAILCOW_DIR && echo \"$MAILCOW_HOSTNAME\" | ./generate_config.sh" + + # Verify config generation + if [ ! -f "$MAILCOW_DIR/mailcow.conf" ]; then + log_message "Error: mailcow.conf was not generated!" + log_message "Attempting alternative generation method..." + + # Alternative: Copy example config + if [ -f "$MAILCOW_DIR/mailcow.conf.example" ]; then + cp "$MAILCOW_DIR/mailcow.conf.example" "$MAILCOW_DIR/mailcow.conf" + sed -i "s/MAILCOW_HOSTNAME=.*/MAILCOW_HOSTNAME=$MAILCOW_HOSTNAME/" "$MAILCOW_DIR/mailcow.conf" + chown dockeruser:dockeruser "$MAILCOW_DIR/mailcow.conf" + log_message "Created mailcow.conf from example template" + else + log_message "Critical: Could not find mailcow.conf.example" + exit 1 + fi + fi + + # Ask for manual configuration echo "Would you like to edit the mailcow configuration? (y/N)" read -n1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then - nano mailcow.conf + EDITOR=${EDITOR:-nano} + $EDITOR "$MAILCOW_DIR/mailcow.conf" fi fi - # Start Mailcow services + # Start Mailcow services with proper ownership log_message "Starting Mailcow services..." + chown -R dockeruser:dockeruser "$MAILCOW_DIR" su - dockeruser -c "cd $MAILCOW_DIR && docker compose pull && docker compose up -d" + # Verify services are running + sleep 10 + if ! docker compose --project-directory "$MAILCOW_DIR" ps | grep -q "Up"; then + log_message "Warning: Some containers may not be running properly" + else + log_message "Mailcow services started successfully" + fi + save_checkpoint "mailcow_installed" fi