1
0
mirror of https://git.cloudron.io/cloudron/gitea-app synced 2026-06-15 01:15:51 +00:00
Files
gitea-app/start.sh
T

83 lines
3.3 KiB
Bash
Raw Normal View History

2015-04-26 12:45:32 -07:00
#!/bin/bash
set -eu -o pipefail
2015-10-13 15:27:09 -07:00
setup_ldap_source() {
2015-11-24 11:53:21 -08:00
set -eu
2015-10-13 15:27:09 -07: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-28 21:57:58 -07:00
2016-04-11 12:21:59 -07:00
now=$(date +%s)
2016-08-26 21:51:49 -07:00
# Get the existing LDAP source status. This allows the user to disable LDAP
ldap_status=$(mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" -N -B -e "select is_actived from login_source WHERE name='cloudron';")
[[ -z "${ldap_status}" ]] && ldap_status="1"
2015-11-24 11:53:21 -08:00
if mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \
2016-08-26 21:51:49 -07:00
-e "REPLACE INTO login_source (id, type, name, is_actived, cfg, created_unix, updated_unix) VALUES (1,2,'cloudron',${ldap_status},'{\"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})\"}','${now}','${now}');"; then
echo "LDAP Authentication was setup with status ${ldap_status}"
2015-11-24 11:53:21 -08:00
else
echo "Failed to setup LDAP authentication"
exit 1
fi
2015-10-13 15:27:09 -07:00
}
2016-04-11 10:44:43 -07:00
# SSH_PORT can be unset to disable SSH
disable_ssh="false"
2016-04-11 11:46:57 -07:00
if [[ -z "${SSH_PORT:-}" ]]; then
2016-04-11 10:44:43 -07:00
echo "SSH disabled"
SSH_PORT=29418 # arbitrary port to keep sshd happy
2016-04-11 11:59:21 -07:00
disable_ssh="true"
2016-04-11 10:44:43 -07:00
fi
2016-05-03 22:49:59 -07:00
if [[ ! -f "/app/data/sshd/ssh_host_ed25519_key" ]]; then
echo "Generating ssh host keys"
mkdir -p /app/data/sshd
ssh-keygen -qt rsa -N '' -f /app/data/sshd/ssh_host_rsa_key
ssh-keygen -qt dsa -N '' -f /app/data/sshd/ssh_host_dsa_key
ssh-keygen -qt ecdsa -N '' -f /app/data/sshd/ssh_host_ecdsa_key
ssh-keygen -qt ed25519 -N '' -f /app/data/sshd/ssh_host_ed25519_key
else
echo "Reusing existing host keys"
fi
chmod 0600 /app/data/sshd/*_key
chmod 0644 /app/data/sshd/*.pub
2015-04-28 21:57:58 -07:00
sed -e "s/^Port .*/Port ${SSH_PORT}/" \
-e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \
2016-05-03 22:49:59 -07:00
-e "s,^HostKey /etc/ssh/,HostKey /app/data/sshd/," \
2015-10-13 15:27:09 -07:00
/etc/ssh/sshd_config > /run/gogs/sshd_config
2015-06-24 11:36:12 -07:00
2015-11-24 12:16:34 -08:00
sed -e "s/##DOMAIN/${APP_DOMAIN}/g" \
2015-04-28 17:12:16 -07:00
-e "s/##SSH_PORT/${SSH_PORT}/g" \
2016-04-11 10:44:43 -07:00
-e "s/##DISABLE_SSH/${disable_ssh}/g" \
2015-04-28 17:12:16 -07: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-28 19:29:12 -07:00
-e "s/##MAIL_PORT/${MAIL_SMTP_PORT}/g" \
2016-05-05 23:07:17 -07:00
-e "s/##MAIL_FROM/${MAIL_FROM}/g" \
-e "s/##MAIL_SMTP_USERNAME/${MAIL_SMTP_USERNAME}/g" \
-e "s/##MAIL_SMTP_PASSWORD/${MAIL_SMTP_PASSWORD}/g" \
2015-04-28 21:57:58 -07:00
-e "s/##SECRET_KEY/$(pwgen -1 -s)/g" \
2016-02-21 18:52:08 -08:00
/home/git/app.ini.template > "/run/gogs/app.ini"
2015-04-28 17:12:16 -07:00
2016-08-26 21:45:11 -07:00
# merge any user config file
2016-08-26 22:06:35 -07:00
[[ -f /app/data/app.ini ]] && cat "/app/data/app.ini" >> "/run/gogs/app.ini"
2016-08-26 21:45:11 -07:00
2015-11-25 09:12:59 -08:00
mkdir -p /app/data/repository /app/data/ssh
2015-10-14 00:46:53 -07:00
2016-02-21 18:52:08 -08:00
chown -R git:git /app/data /run/gogs
2015-08-18 13:44:26 -07:00
2015-10-13 15:27:09 -07:00
( setup_ldap_source ) &
2015-06-24 11:01:16 -07:00
2015-10-13 15:27:09 -07:00
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gogs
2015-04-26 12:45:32 -07:00