#!/bin/sh
mkdir -p /data/pleroma/uploads
mkdir -p /data/pleroma/static
chown -R pleroma:pleroma /data/pleroma
mkdir -p /data/pleroma/ssh_keys
if [ ! -f /data/pleroma/ssh_keys/ssh_host_rsa_key ]; then
ssh-keygen -m PEM -N "" -b 2048 -t rsa -f /data/pleroma/ssh_keys/ssh_host_rsa_key
fi
export PATH="$PATH:/opt/pleroma/bin"
FLAGFILE="/opt/pleroma/instance/.soapbox_${SOAPBOX_FE_VERSION=latest}_ready"
if [ ! -f $FLAGFILE ]; then
unzip -q -o /opt/pleroma/dist/soapbox-fe.zip -d /opt/pleroma/instance
sed -i 's/<\/head>/<style>a[href="\/timeline\/local"] { display: none !important; }<\/style><\/head>/' /data/pleroma/static/index.html
touch "$FLAGFILE"
chown -R pleroma:pleroma /opt/pleroma/instance
fi
if [ ! -d /data/postgres ]; then
cp -rp /var/lib/postgresql/14/main /data/postgres
(
while ! pg_isready; do
sleep 1
done
runuser -u postgres -- psql -c "CREATE ROLE pleroma LOGIN"
runuser -u postgres -- psql -c "CREATE DATABASE pleroma WITH OWNER pleroma"
while [ ! -f /tmp/.pleroma-ever-started ]; do
sleep 1
done
runuser -u pleroma -- /opt/pleroma/bin/pleroma_ctl config migrate_to_db
echo "config :pleroma, configurable_from_database: true" >> /data/pleroma/config.exs
) &
fi
cd /opt/pleroma
exec supervisord -n