98 lines
3.2 KiB
Bash
98 lines
3.2 KiB
Bash
#!/bin/bash
|
|
|
|
set -eu
|
|
|
|
# Create necessary directories
|
|
mkdir -p /app/data/config /app/data/storage
|
|
|
|
# Create config template file on first run
|
|
if [[ ! -f /app/data/config/config.yaml ]]; then
|
|
echo "==> First run - creating configuration template"
|
|
|
|
# Replace variables in template for things we know
|
|
sed \
|
|
-e "s|%%POSTGRESQL_HOST%%|${CLOUDRON_POSTGRESQL_HOST}|g" \
|
|
-e "s|%%POSTGRESQL_PORT%%|${CLOUDRON_POSTGRESQL_PORT}|g" \
|
|
-e "s|%%POSTGRESQL_USERNAME%%|${CLOUDRON_POSTGRESQL_USERNAME}|g" \
|
|
-e "s|%%POSTGRESQL_PASSWORD%%|${CLOUDRON_POSTGRESQL_PASSWORD}|g" \
|
|
-e "s|%%POSTGRESQL_DATABASE%%|${CLOUDRON_POSTGRESQL_DATABASE}|g" \
|
|
-e "s|%%APP_ORIGIN%%|${CLOUDRON_APP_ORIGIN}|g" \
|
|
-e "s|%%MAIL_SMTP_SERVER%%|${CLOUDRON_MAIL_SMTP_SERVER}|g" \
|
|
-e "s|%%MAIL_SMTP_PORT%%|${CLOUDRON_MAIL_SMTP_PORT}|g" \
|
|
-e "s|%%MAIL_SMTP_USERNAME%%|${CLOUDRON_MAIL_SMTP_USERNAME}|g" \
|
|
-e "s|%%MAIL_SMTP_PASSWORD%%|${CLOUDRON_MAIL_SMTP_PASSWORD}|g" \
|
|
-e "s|%%MAIL_FROM%%|${CLOUDRON_MAIL_FROM}|g" \
|
|
-e "s|%%MAIL_FROM_DISPLAY_NAME%%|${CLOUDRON_MAIL_FROM_DISPLAY_NAME}|g" \
|
|
/app/pkg/config.template.yaml > /app/data/config/config.yaml
|
|
|
|
# Create an S3 configuration file template
|
|
cat > /app/data/config/s3.env.template <<EOT
|
|
# S3 Configuration for Ente
|
|
# Fill in your S3 credentials and rename this file to s3.env
|
|
|
|
# S3 endpoint (example: https://s3.amazonaws.com)
|
|
S3_ENDPOINT=
|
|
|
|
# S3 region (example: us-east-1)
|
|
S3_REGION=
|
|
|
|
# S3 bucket name
|
|
S3_BUCKET=
|
|
|
|
# S3 access key
|
|
S3_ACCESS_KEY=
|
|
|
|
# S3 secret key
|
|
S3_SECRET_KEY=
|
|
|
|
# Prefix for objects in the bucket (optional)
|
|
S3_PREFIX=ente/
|
|
EOT
|
|
|
|
echo "==> IMPORTANT: S3 storage configuration required"
|
|
echo " 1. Edit the file at /app/data/config/s3.env.template"
|
|
echo " 2. Fill in your S3 credentials"
|
|
echo " 3. Rename the file to s3.env"
|
|
echo " 4. Restart the app"
|
|
|
|
# Exit with a message if this is the first run
|
|
if [[ ! -f /app/data/config/s3.env ]]; then
|
|
echo "==> Exiting. Please configure S3 storage and restart the app."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Check if s3.env exists
|
|
if [[ ! -f /app/data/config/s3.env ]]; then
|
|
echo "==> ERROR: S3 configuration not found"
|
|
echo " Please configure S3 storage by editing /app/data/config/s3.env.template"
|
|
echo " and renaming it to s3.env, then restart the app."
|
|
exit 1
|
|
fi
|
|
|
|
# Load S3 environment variables
|
|
source /app/data/config/s3.env
|
|
|
|
# Update the config file with S3 credentials
|
|
sed -i \
|
|
-e "s|%%S3_ENDPOINT%%|${S3_ENDPOINT}|g" \
|
|
-e "s|%%S3_REGION%%|${S3_REGION}|g" \
|
|
-e "s|%%S3_BUCKET%%|${S3_BUCKET}|g" \
|
|
-e "s|%%S3_ACCESS_KEY%%|${S3_ACCESS_KEY}|g" \
|
|
-e "s|%%S3_SECRET_KEY%%|${S3_SECRET_KEY}|g" \
|
|
-e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \
|
|
/app/data/config/config.yaml
|
|
|
|
# Change to server directory
|
|
cd /app/code/server
|
|
|
|
# Run database migrations
|
|
echo "==> Running database migrations"
|
|
NODE_ENV=production yarn run db-migrate
|
|
|
|
# Change ownership to cloudron user
|
|
chown -R cloudron:cloudron /app/data
|
|
|
|
# Start the server
|
|
echo "==> Starting Ente server"
|
|
exec /usr/local/bin/gosu cloudron:cloudron NODE_ENV=production CONFIG_PATH=/app/data/config/config.yaml yarn run serve |