mastodon-app/start.sh

73 lines
3.2 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2018-10-30 15:46:13 +00:00
set -eu
2018-10-30 15:46:13 +00:00
mkdir -p /tmp/mastodon /app/data/system /run/mastodon
2018-10-31 12:53:10 +00:00
if [[ ! -f /app/data/env.production ]]; then
echo "==> Copying env template on first run"
2020-01-06 19:21:25 +00:00
cp /app/pkg/env.template /app/data/env.production
2020-01-23 19:26:04 +00:00
# LOCAL_DOMAIN is the federation domain. We only set this once on a fresh install
# changing this will break federation
sed -e "s/LOCAL_DOMAIN=.*/LOCAL_DOMAIN=${CLOUDRON_APP_DOMAIN}/g" -i /app/data/env.production
fi
2018-10-31 12:53:10 +00:00
echo "==> Configuring mastodon"
sed -e "s/DB_HOST=.*/DB_HOST=${CLOUDRON_POSTGRESQL_HOST}/g" \
-e "s/DB_PORT=.*/DB_PORT=${CLOUDRON_POSTGRESQL_PORT}/g" \
-e "s/DB_NAME=.*/DB_NAME=${CLOUDRON_POSTGRESQL_DATABASE}/g" \
-e "s/DB_USER=.*/DB_USER=${CLOUDRON_POSTGRESQL_USERNAME}/g" \
-e "s/DB_PASS=.*/DB_PASS=${CLOUDRON_POSTGRESQL_PASSWORD}/g" \
-e "s/REDIS_HOST=.*/REDIS_HOST=${CLOUDRON_REDIS_HOST}/g" \
-e "s/REDIS_PORT=.*/REDIS_PORT=${CLOUDRON_REDIS_PORT}/g" \
-e "s/REDIS_PASSWORD=.*/REDIS_PASSWORD=${CLOUDRON_REDIS_PASSWORD}/g" \
-e "s/SMTP_SERVER=.*/SMTP_SERVER=${CLOUDRON_MAIL_SMTP_SERVER}/g" \
-e "s/SMTP_PORT=.*/SMTP_PORT=${CLOUDRON_MAIL_SMTP_PORT}/g" \
-e "s/SMTP_FROM_ADDRESS=.*/SMTP_FROM_ADDRESS=${CLOUDRON_MAIL_FROM}/g" \
-e "s/SMTP_LOGIN=.*/SMTP_LOGIN=${CLOUDRON_MAIL_SMTP_USERNAME}/g" \
-e "s/SMTP_PASSWORD=.*/SMTP_PASSWORD=${CLOUDRON_MAIL_SMTP_PASSWORD}/g" \
2020-01-06 19:27:26 +00:00
-e "s/WEB_DOMAIN=.*/WEB_DOMAIN=${CLOUDRON_APP_DOMAIN}/g" \
-i /app/data/env.production
2019-07-18 16:50:17 +00:00
if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then
sed -e "s/LDAP_ENABLED=.*/LDAP_ENABLED=true/g" \
-e "s/LDAP_HOST=.*/LDAP_HOST=${CLOUDRON_LDAP_SERVER}/g" \
-e "s/LDAP_PORT=.*/LDAP_PORT=${CLOUDRON_LDAP_PORT}/g" \
2019-07-18 18:23:01 +00:00
-e "s/LDAP_BASE=.*/LDAP_BASE=${CLOUDRON_LDAP_USERS_BASE_DN}/g" \
2019-07-18 16:50:17 +00:00
-e "s/LDAP_BIND_DN=.*/LDAP_BIND_DN=${CLOUDRON_LDAP_BIND_DN}/g" \
2019-07-18 18:23:01 +00:00
-e "s/LDAP_BIND_PASSWORD=.*/LDAP_BIND_PASSWORD=${CLOUDRON_LDAP_BIND_PASSWORD}/g" \
2019-07-18 16:50:17 +00:00
-i /app/data/env.production
else
sed -e "s/LDAP_ENABLED=.*/LDAP_ENABLED=false/g" -i /app/data/env.production
fi
if grep -q "^SECRET_KEY_BASE=$" /app/data/env.production; then
echo "==> Generating secrets"
export RANDFILE=/tmp/.rnd
sed -i -e "s/SECRET_KEY_BASE=.*/SECRET_KEY_BASE=$(openssl rand -hex 64)/" \
-e "s/OTP_SECRET=.*/OTP_SECRET=$(openssl rand -hex 64)/" \
/app/data/env.production
2018-10-30 15:46:13 +00:00
echo "==> Generating vapid keys"
HOME=/app/data bundle exec rake mastodon:webpush:generate_vapid_key >> /app/data/env.production
2018-10-30 15:46:13 +00:00
echo "==> Init database"
HOME=/app/data SAFETY_ASSURED=1 bundle exec rails db:schema:load db:seed
2019-07-18 18:34:51 +00:00
if [[ -n "${CLOUDRON_LDAP_SERVER:-}" ]]; then
echo "Disabling registration by default"
PGPASSWORD=${CLOUDRON_POSTGRESQL_PASSWORD} psql -h ${CLOUDRON_POSTGRESQL_HOST} -p ${CLOUDRON_POSTGRESQL_PORT} -U ${CLOUDRON_POSTGRESQL_USERNAME} -d ${CLOUDRON_POSTGRESQL_DATABASE} \
-c "INSERT INTO settings (var, value) VALUES ('registrations_mode', 'none')"
fi
2020-03-09 17:02:03 +00:00
else
echo "==> Migrating database"
HOME=/app/data SAFETY_ASSURED=1 bundle exec rails db:migrate
2018-10-31 12:53:10 +00:00
fi
2018-10-30 15:46:13 +00:00
chown -R cloudron:cloudron /app/data /tmp/mastodon /run/mastodon
2018-10-30 15:46:13 +00:00
echo "==> Starting mastodon"
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Mastodon
2018-10-30 15:46:13 +00:00