#!/bin/bash set -eu echo "==> Starting AnonAddy initialization" # Initialize /app/data if empty if [ ! -d "/app/data/storage" ]; then echo "==> Initializing /app/data from /tmp/data" cp -r /tmp/data/* /app/data/ chown -R cloudron:cloudron /app/data fi # Ensure proper permissions chown -R cloudron:cloudron /app/data chmod -R 755 /app/data/storage # Create .env file in /app/data echo "==> Configuring application environment" cat > /app/data/.env < Generating application key" cd /app/code sudo -u cloudron php artisan key:generate --force # Save the key to persistent storage grep "APP_KEY=" /app/data/.env | cut -d= -f2 > /app/data/app_key else echo "==> Using existing application key" APP_KEY=$(cat /app/data/app_key) sed -i "s|APP_KEY=.*|APP_KEY=${APP_KEY}|g" /app/data/.env fi # Generate ANONADDY_SECRET if it doesn't exist if [ ! -f "/app/data/anonaddy_secret" ]; then echo "==> Generating AnonAddy secret" ANONADDY_SECRET=$(openssl rand -hex 32) echo "$ANONADDY_SECRET" > /app/data/anonaddy_secret echo "ANONADDY_SECRET=${ANONADDY_SECRET}" >> /app/data/.env else echo "==> Using existing AnonAddy secret" ANONADDY_SECRET=$(cat /app/data/anonaddy_secret) echo "ANONADDY_SECRET=${ANONADDY_SECRET}" >> /app/data/.env fi # Run database migrations echo "==> Running database migrations" cd /app/code sudo -u cloudron php artisan migrate --force # Clear and cache configuration echo "==> Optimizing application" sudo -u cloudron php artisan config:clear sudo -u cloudron php artisan cache:clear sudo -u cloudron php artisan view:clear sudo -u cloudron php artisan config:cache sudo -u cloudron php artisan route:cache # Create default admin user if database is empty USER_COUNT=$(sudo -u cloudron php artisan tinker --execute="echo \App\Models\User::count();") if [ "$USER_COUNT" -eq "0" ]; then echo "==> Creating default admin user" sudo -u cloudron php artisan tinker <username = 'admin'; \$user->email = 'admin@example.com'; \$user->password = bcrypt('password'); \$user->save(); echo "Default admin user created: admin@example.com / password"; TINKER echo "==> IMPORTANT: Change the default password after first login!" fi # Configure Postfix echo "==> Configuring Postfix" cp /tmp/postfix-main.cf /etc/postfix/main.cf cp /tmp/postfix-master.cf /etc/postfix/master.cf # Update Postfix configuration with domain sed -i "s|CLOUDRON_APP_DOMAIN|${CLOUDRON_APP_DOMAIN}|g" /etc/postfix/main.cf sed -i "s|CLOUDRON_MAIL_DOMAIN|${CLOUDRON_MAIL_DOMAIN}|g" /etc/postfix/main.cf # Create Postfix directories mkdir -p /app/data/postfix/spool mkdir -p /var/spool/postfix chown -R postfix:postfix /var/spool/postfix chown -R cloudron:cloudron /app/data/postfix # Start services via supervisor echo "==> Starting services" exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf