#!/bin/bash -e

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

rm $FORUMS_SOURCE/Settings.php
ln -sf /configuration/SMFSettings.php $FORUMS_SOURCE/Settings.php

rm -rf $WIKI_SOURCE/images
ln -sf /userdata/images $WIKI_SOURCE/images

rm -rf $FORUMS_SOURCE/downloads
ln -sf /userdata/downloads $FORUMS_SOURCE/downloads

rm -rf $FORUMS_SOURCE/attachments
ln -sf /userdata/attachments $FORUMS_SOURCE/attachments

rm -rf $FORUMS_SOURCE/profile_pictures
ln -sf /userdata/profile_pictures $FORUMS_SOURCE/profile_pictures

rm -rf $FORUMS_SOURCE/pm_attachments
ln -sf /userdata/pm_attachments $FORUMS_SOURCE/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 $WIKI_SOURCE/maintenance
php update.php

cd $FORUMS_SOURCE
rm install.php
exit 0;
