#!/bin/bash
# Entrypoint for SendPortal

echo "
APP_NAME=\"${APP_NAME:-SendPortal}\"
APP_ENV=${APP_ENV:-local}
APP_KEY=${APP_KEY}
APP_DEBUG=${APP_DEBUG:-false}
APP_URL=${APP_URL:-http://localhost:3000}

LOG_CHANNEL=${LOG_CHANNEL:-stack}

DB_CONNECTION=${DB_CONNECTION:-pgsql}
DB_HOST=${DB_HOST:-127.0.0.1}
DB_PORT=${DB_PORT:-5432}
DB_DATABASE=${DB_DATABASE:-sendportal}
DB_USERNAME=${DB_USERNAME:-sendportal}
DB_PASSWORD=${DB_PASSWORD}

BROADCAST_DRIVER=${BROADCAST_DRIVER:-log}
CACHE_DRIVER=${CACHE_DRIVER:-file}
QUEUE_CONNECTION=${QUEUE_CONNECTION:-sync}
SESSION_DRIVER=${SESSION_DRIVER:-file}
SESSION_LIFETIME=${SESSION_LIFETIME:-120}

REDIS_HOST=${REDIS_HOST:-127.0.0.1}
REDIS_PASSWORD=${REDIS_PASSWORD:-null}
REDIS_PORT=${REDIS_PORT:-6379}

MAIL_MAILER=${MAIL_MAILER:-smtp}
MAIL_HOST=${MAIL_HOST:-smtp.mailtrap.io}
MAIL_PORT=${MAIL_PORT:-25}
MAIL_USERNAME=${MAIL_USERNAME:-null}
MAIL_PASSWORD=${MAIL_PASSWORD:-null}
MAIL_ENCRYPTION=${MAIL_ENCRYPTION:-null}
MAIL_FROM_ADDRESS=${MAIL_FROM_ADDRESS:-null}
MAIL_FROM_NAME=\"${MAIL_FROM_NAME}\"

MAILGUN_DOMAIN=${MAILGUN_DOMAIN}
MAILGUN_SECRET=${MAILGUN_SECRET}
MAILGUN_ENDPOINT=${MAILGUN_ENDPOINT}

AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-east-1}
AWS_BUCKET=${AWS_BUCKET:-}

PUSHER_APP_ID=${PUSHER_APP_ID}
PUSHER_APP_KEY=${PUSHER_APP_KEY}
PUSHER_APP_SECRET=${PUSHER_APP_SECRET}
PUSHER_APP_CLUSTER=${PUSHER_APP_CLUSTER:-mt1}

MIX_PUSHER_APP_KEY=${PUSHER_APP_KEY}
MIX_PUSHER_APP_CLUSTER=${PUSHER_APP_CLUSTER}

SENDPORTAL_THROTTLE_MIDDLEWARE=${SENDPORTAL_THROTTLE_MIDDLEWARE:-60,1}
SENDPORTAL_REGISTER=${SENDPORTAL_REGISTER:-false}
SENDPORTAL_PASSWORD_RESET=${SENDPORTAL_PASSWORD_RESET:-true}
" > /var/www/html/sendportal/.env

cd /var/www/html/sendportal
php artisan vendor:publish --provider=Sendportal\\Base\\SendportalBaseServiceProvider
php artisan migrate

exec "$@"
