#!/bin/bash -e

# Create symlinks between application, userdata, and configuration
rm /application/w/LocalSettings.php
ln -sf /configuration/MWSettings.php /application/w/LocalSettings.php

rm /application/forums/Settings.php
ln -sf /configuration/SMFSettings.php /application/forums/Settings.php

rm -rf /application/w/images
ln -sf /userdata/images /application/w/images

rm -rf /application/forums/downloads
ln -sf /userdata/downloads /application/forums/downloads

rm -rf /application/forums/attachments
ln -sf /userdata/attachments /application/forums/attachments

rm -rf /application/forums/profile_pictures
ln -sf /userdata/profile_pictures /application/forums/profile_pictures

rm -rf /application/forums/pm_attachments
ln -sf /userdata/pm_attachments /application/forums/pm_attachments

# Configure email
cp /configuration/msmtprc /etc/msmtprc
sed -i "s/@GCL_SMTP_HOST@/$GCL_SMTP_HOST/g" /etc/msmtprc

SMTP_PORT=${GCL_SMTP_PORT:-587}
sed -i "s/@GCL_SMTP_PORT@/$SMTP_PORT/g" /etc/msmtprc

SMTP_FROM=${GCL_SMTP_FROM:-no-reply@glitchcity.info}
sed -i "s/@GCL_SMTP_FROM@/$SMTP_FROM/g" /etc/msmtprc
sed -i "s/@GCL_SMTP_USER@/$GCL_SMTP_USER/g" /etc/msmtprc
sed -i "s/@GCL_SMTP_PASSWORD@/$GCL_SMTP_PASSWORD/g" /etc/msmtprc

# Run maintenance scripts
cd /application/w/maintenance
php update.php
