#!/bin/bash # Wait for MySQL to warm-up while mysqladmin ping --host 172.22.1.250 --silent; do # Recreate view mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "DROP VIEW IF EXISTS sogo_view" mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} << EOF CREATE VIEW sogo_view (c_uid, domain, c_name, c_password, c_cn, mail, aliases, ad_aliases, home, kind, multiple_bookings) AS SELECT mailbox.username, mailbox.domain, mailbox.username, mailbox.password, mailbox.name, mailbox.username, IFNULL(ga.aliases, ''), IFNULL(gda.ad_alias, ''), CONCAT('/var/vmail/', maildir), mailbox.kind, mailbox.multiple_bookings FROM mailbox LEFT OUTER JOIN grouped_mail_aliases ga ON ga.username = mailbox.username LEFT OUTER JOIN grouped_domain_alias_address gda ON gda.username = mailbox.username WHERE mailbox.active = '1'; EOF mkdir -p /var/lib/sogo/GNUstep/Defaults/ # Generate plist header with timezone data cat < /var/lib/sogo/GNUstep/Defaults/sogod.plist OCSAclURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_acl OCSCacheFolderURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_cache_folder OCSEMailAlarmsFolderURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_alarms_folder OCSFolderInfoURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_folder_info OCSSessionsFolderURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_sessions_folder OCSStoreURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_store SOGoProfileURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_user_profile SOGoTimeZone ${TZ} domains EOF # Generate multi-domain setup while read line do echo " ${line} SOGoMailDomain ${line} SOGoUserSources MailFieldNames aliases ad_aliases KindFieldName kind DomainFieldName domain MultipleBookingsFieldName multiple_bookings canAuthenticate YES displayName GAL id ${line} isAddressBook YES type sql userPasswordAlgorithm ssha256 viewURL mysql://${DBUSER}:${DBPASS}@mysql:3306/${DBNAME}/sogo_view " >> /var/lib/sogo/GNUstep/Defaults/sogod.plist done < <(mysql --host mysql -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain;" -B -N) # Generate footer echo ' ' >> /var/lib/sogo/GNUstep/Defaults/sogod.plist # Fix permissions chown sogo:sogo -R /var/lib/sogo/ chmod 600 /var/lib/sogo/GNUstep/Defaults/sogod.plist supervisorctl restart sogo sleep 99999 done