gitea-app/start.sh

105 lines
4.6 KiB
Bash
Raw Normal View History

2015-04-26 19:45:32 +00:00
#!/bin/bash
set -eu -o pipefail
2017-06-02 08:32:24 +00:00
mkdir -p /run/gitea/tmp/uploads
2015-10-13 22:27:09 +00:00
setup_ldap_source() {
2015-11-24 19:53:21 +00:00
set -eu
2017-06-02 08:32:24 +00:00
# Wait for gitea to finish db setup, before we insert ldap source in db
2015-10-13 22:27:09 +00:00
while ! curl --fail http://localhost:3000/healthcheck; do
2017-06-02 08:32:24 +00:00
echo "Waiting for gitea to come up"
2015-10-13 22:27:09 +00:00
sleep 1
done
2015-04-29 04:57:58 +00:00
2016-04-11 19:21:59 +00:00
now=$(date +%s)
2016-08-27 04:51:49 +00: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 19:53:21 +00:00
if mysql -u"${MYSQL_USERNAME}" -p"${MYSQL_PASSWORD}" -h mysql --database="${MYSQL_DATABASE}" \
2016-08-27 04:51:49 +00: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 19:53:21 +00:00
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
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-29 04:57:58 +00:00
sed -e "s/^Port .*/Port ${SSH_PORT}/" \
-e "s/^#ListenAddress .*/ListenAddress 0.0.0.0/" \
-e "s,^HostKey /etc/ssh/,HostKey /app/data/sshd/," \
2017-06-02 08:32:24 +00:00
/etc/ssh/sshd_config > /run/gitea/sshd_config
2015-06-24 18:36:12 +00:00
cp /home/git/app.ini.template "/run/gitea/app.ini"
# create default user config file
if ! [ -f /app/data/app.ini ]; then
cp /home/git/app.ini.template /app/data/app.ini
fi
# merge user config file
crudini --merge "/run/gitea/app.ini" < "/app/data/app.ini"
# override important values
crudini --set "/run/gitea/app.ini" database DB_TYPE mysql
crudini --set "/run/gitea/app.ini" database HOST "${MYSQL_HOST}:${MYSQL_PORT}"
crudini --set "/run/gitea/app.ini" database NAME "${MYSQL_DATABASE}"
crudini --set "/run/gitea/app.ini" database USER "${MYSQL_USERNAME}"
crudini --set "/run/gitea/app.ini" database PASSWD "${MYSQL_PASSWORD}"
crudini --set "/run/gitea/app.ini" database SSL_MODE "disable"
crudini --set "/run/gitea/app.ini" server PROTOCOL "http"
crudini --set "/run/gitea/app.ini" server DOMAIN "${APP_DOMAIN}"
crudini --set "/run/gitea/app.ini" server ROOT_URL "https://%(DOMAIN)s/"
crudini --set "/run/gitea/app.ini" server HTTP_ADDR ""
crudini --set "/run/gitea/app.ini" server HTTP_PORT "3000"
crudini --set "/run/gitea/app.ini" server DISABLE_SSH "${disable_ssh}"
crudini --set "/run/gitea/app.ini" server SSH_PORT "${SSH_PORT}"
crudini --set "/run/gitea/app.ini" server APP_DATA_PATH "/app/data/appdata"
crudini --set "/run/gitea/app.ini" repository ROOT "/app/data/repository"
crudini --set "/run/gitea/app.ini" repository.upload TEMP_PATH "/run/gitea/tmp/uploads"
crudini --set "/run/gitea/app.ini" mailer HOST "${MAIL_SMTP_SERVER}:${MAIL_SMTP_PORT}"
crudini --set "/run/gitea/app.ini" mailer USER "${MAIL_SMTP_USERNAME}"
crudini --set "/run/gitea/app.ini" mailer PASSWD "${MAIL_SMTP_PASSWORD}"
crudini --set "/run/gitea/app.ini" mailer FROM "${MAIL_FROM}"
crudini --set "/run/gitea/app.ini" mailer SKIP_VERIFY "true"
crudini --set "/run/gitea/app.ini" security SECRET_KEY $(pwgen -1 -s)
crudini --set "/run/gitea/app.ini" security INSTALL_LOCK "true"
crudini --set "/run/gitea/app.ini" log MODE "console"
crudini --set "/run/gitea/app.ini" log ROOT_PATH "/run/gitea"
crudini --set "/run/gitea/app.ini" indexer ISSUE_INDEXER_PATH "/app/data/appdata/indexers/issues.bleve"
2016-08-27 04:45:11 +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
2017-06-02 08:32:24 +00:00
chown -R git:git /app/data /run/gitea
2015-10-13 22:27:09 +00:00
( setup_ldap_source ) &
2015-06-24 18:01:16 +00:00
2017-06-02 08:32:24 +00:00
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon -i Gitea
2015-04-26 19:45:32 +00:00