gitea-app/start.sh

43 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
set -eu -o pipefail
readonly fqdn=$(hostname -f)
setup_ldap_source() {
# Wait for gogs to finish db setup, before we insert ldap source in db
while ! curl --fail http://localhost:3000/healthcheck; do
echo "Waiting for gogs to come up"
sleep 1
done
# id, type, name, is_actived, cfg, allow_auto_register, created, updated
mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \
-e "REPLACE INTO login_source VALUES (1,2,'cloudron',1,'{\"Name\":\"cloudron\",\"Host\":\"${LDAP_SERVER}\",\"Port\":${LDAP_PORT},\"UseSSL\":false,\"UserBase\":\"${LDAP_USERS_BASE_DN}\",\"AttributeUsername\":\"uid\",\"AttributeName\":\"\",\"AttributeSurname\":\"\",\"AttributeMail\":\"mail\",\"Filter\":\"(\\\\u0026(objectClass=user)(uid=%s))\",\"AdminFilter\":\"(memberof=cn=admins,${LDAP_GROUPS_BASE_DN})\",\"Enabled\":true}',1,'2015-06-24 17:14:12','2015-06-24 17:25:03');"
}
sed -e "s/^Port .*/Port ${SSH_PORT}/" \
-e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \
/etc/ssh/sshd_config > /run/gogs/sshd_config
sed -e "s/##HOSTNAME/${fqdn}/g" \
-e "s/##SSH_PORT/${SSH_PORT}/g" \
-e "s/##MYSQL_HOST/${MYSQL_HOST}/g" \
-e "s/##MYSQL_PORT/${MYSQL_PORT}/g" \
-e "s/##MYSQL_USERNAME/${MYSQL_USERNAME}/g" \
-e "s/##MYSQL_PASSWORD/${MYSQL_PASSWORD}/g" \
-e "s/##MYSQL_DATABASE/${MYSQL_DATABASE}/g" \
-e "s/##MAIL_SERVER/${MAIL_SMTP_SERVER}/g" \
-e "s/##MAIL_PORT/${MAIL_SMTP_PORT}/g" \
-e "s/##MAIL_FROM/${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}/g" \
-e "s/##SECRET_KEY/$(pwgen -1 -s)/g" \
/home/cloudron/app.ini.template > "/run/gogs/app.ini"
mkdir -p /app/data/repository /app/data/ssh
chown -R cloudron.cloudron /app/data /run/gogs
( setup_ldap_source ) &
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs