mirror of
https://git.cloudron.io/cloudron/gitea-app.git
synced 2024-11-22 08:01:01 +00:00
57 lines
2.3 KiB
Bash
Executable file
57 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -eu -o pipefail
|
|
|
|
setup_ldap_source() {
|
|
set -eu
|
|
|
|
# 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
|
|
|
|
now=$(date +%s)
|
|
if mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \
|
|
-e "REPLACE INTO login_source (id, type, name, is_actived, cfg, created_unix, updated_unix) VALUES (1,2,'cloudron',1,'{\"Name\":\"cloudron\",\"Host\":\"${LDAP_SERVER}\",\"Port\":${LDAP_PORT},\"UseSSL\":false,\"SkipVerify\":true,\"BindDN\":\"${LDAP_BIND_DN}\",\"BindPassword\":\"${LDAP_BIND_PASSWORD}\",\"UserBase\":\"${LDAP_USERS_BASE_DN}\",\"AttributeUsername\":\"username\",\"AttributeName\":\"displayname\",\"AttributeSurname\":\"\",\"AttributeMail\":\"mail\",\"Filter\":\"(\\\\u007C(mail=%[1]s)(username=%[1]s))\",\"AdminFilter\":\"(memberof=cn=admins,${LDAP_GROUPS_BASE_DN})\",\"Enabled\":true}','${now}','${now}');"; then
|
|
echo "LDAP Authentication Setup"
|
|
else
|
|
echo "Failed to setup LDAP authentication"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# SSH_PORT can be unset to disable SSH
|
|
disable_ssh="false"
|
|
if [[ -z "${SSH_PORT:-}" ]]; then
|
|
echo "SSH disabled"
|
|
SSH_PORT=29418 # arbitrary port to keep sshd happy
|
|
disable_ssh="true"
|
|
fi
|
|
|
|
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/##DOMAIN/${APP_DOMAIN}/g" \
|
|
-e "s/##SSH_PORT/${SSH_PORT}/g" \
|
|
-e "s/##DISABLE_SSH/${disable_ssh}/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/git/app.ini.template > "/run/gogs/app.ini"
|
|
|
|
mkdir -p /app/data/repository /app/data/ssh
|
|
|
|
chown -R git:git /app/data /run/gogs
|
|
|
|
( setup_ldap_source ) &
|
|
|
|
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs
|
|
|