forgejo-app/start.sh

59 lines
2.3 KiB
Bash
Raw Normal View History

2015-04-26 19:45:32 +00:00
#!/bin/bash
set -eu -o pipefail
2015-10-13 22:27:09 +00:00
setup_ldap_source() {
2015-11-24 19:53:21 +00:00
set -eu
2015-10-13 22:27:09 +00:00
# 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
2015-04-29 04:57:58 +00:00
2016-04-11 19:21:59 +00:00
# id, type, name, is_actived, cfg, allow_auto_register, created_unix, updated_unix
now=$(date +%s)
2015-11-24 19:53:21 +00:00
if mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \
2016-04-11 19:21:59 +00:00
-e "REPLACE INTO login_source 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
2015-11-24 19:53:21 +00:00
echo "LDAP Authentication Setup"
else
echo "Failed to setup LDAP authentication"
exit 1
fi
2015-10-13 22:27:09 +00:00
}
2016-04-11 17:44:43 +00:00
# SSH_PORT can be unset to disable SSH
disable_ssh="false"
2016-04-11 18:46:57 +00:00
if [[ -z "${SSH_PORT:-}" ]]; then
2016-04-11 17:44:43 +00:00
echo "SSH disabled"
SSH_PORT=29418 # arbitrary port to keep sshd happy
2016-04-11 18:59:21 +00:00
disable_ssh="true"
2016-04-11 17:44:43 +00:00
fi
2015-04-29 04:57:58 +00:00
sed -e "s/^Port .*/Port ${SSH_PORT}/" \
-e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \
2015-10-13 22:27:09 +00:00
/etc/ssh/sshd_config > /run/gogs/sshd_config
2015-06-24 18:36:12 +00:00
2015-11-24 20:16:34 +00:00
sed -e "s/##DOMAIN/${APP_DOMAIN}/g" \
2015-04-29 00:12:16 +00:00
-e "s/##SSH_PORT/${SSH_PORT}/g" \
2016-04-11 17:44:43 +00:00
-e "s/##DISABLE_SSH/${disable_ssh}/g" \
2015-04-29 00:12:16 +00:00
-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" \
2015-04-29 02:29:12 +00:00
-e "s/##MAIL_PORT/${MAIL_SMTP_PORT}/g" \
2015-04-29 00:12:16 +00:00
-e "s/##MAIL_FROM/${MAIL_SMTP_USERNAME}@${MAIL_DOMAIN}/g" \
2015-04-29 04:57:58 +00:00
-e "s/##SECRET_KEY/$(pwgen -1 -s)/g" \
2016-02-22 02:52:08 +00:00
/home/git/app.ini.template > "/run/gogs/app.ini"
2015-04-29 00:12:16 +00:00
2015-11-25 17:12:59 +00:00
mkdir -p /app/data/repository /app/data/ssh
2015-10-14 07:46:53 +00:00
2016-02-22 02:52:08 +00:00
chown -R git:git /app/data /run/gogs
2015-10-13 22:27:09 +00:00
( setup_ldap_source ) &
2015-06-24 18:01:16 +00:00
2015-10-13 22:27:09 +00:00
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs
2015-04-26 19:45:32 +00:00