This repository has been archived on 2020-10-27. You can view files and clone it, but cannot push or open issues or pull requests.
git.autonomic.zone/sbin/entrypoint.sh

121 lines
4.0 KiB
Bash
Raw Normal View History

2020-03-15 11:46:13 +00:00
#!/bin/bash
2020-03-15 11:41:24 +00:00
2020-03-15 11:46:13 +00:00
set -eu -o pipefail
2020-03-29 08:22:30 +00:00
# Install root administration user account on first installation
2020-03-15 11:46:13 +00:00
setup_root_user() {
set -eu
if [ ! -f "/data/gitea/conf/app.ini" ]; then
2020-03-22 16:19:39 +00:00
echo "-----> Missing app.ini, not setting up root user"
2020-03-15 11:46:13 +00:00
return
fi
2020-03-29 08:26:15 +00:00
user_count=$(mysql \
-u"${DB_USER}" \
-p"${DB_PASSWD}" \
-h "${DOKKU_MARIADB_GITEA_PORT_3306_TCP_ADDR}" \
--database="${DB_NAME}" \
-N -B -e "SELECT count(*) FROM user;" \
)
2020-03-15 11:46:13 +00:00
if [[ "${user_count}" == "0" ]]; then
2020-03-22 15:42:29 +00:00
echo "-----> Setting up root user for initial deployment"
2020-03-29 08:26:15 +00:00
create_user=$(gitea \
admin \
create-user \
--username "$ADMIN_USER" \
--password "$ADMIN_PASS" \
--email "$ADMIN_MAIL" \
--admin \
)
if "$create_user"; then
2020-03-22 15:42:29 +00:00
echo "-----> root user added"
2020-03-15 11:46:13 +00:00
else
2020-03-22 15:42:29 +00:00
echo "-----> Failed to add root user"
2020-03-22 16:20:11 +00:00
return
2020-03-15 11:46:13 +00:00
fi
fi
}
2020-03-29 08:22:30 +00:00
# Pass Ansible based environment variables into the Gitea app.ini configuration
2020-03-22 15:42:29 +00:00
setup_app_ini() {
set -eu
if [ ! -f "/data/gitea/conf/app.ini" ]; then
2020-04-15 09:20:22 +00:00
echo "-----> Missing app.ini, not setting up configuration"
2020-03-22 15:42:29 +00:00
return
fi
declare app_ini="/data/gitea/conf/app.ini"
2020-03-22 16:13:36 +00:00
echo "-----> Using crudini to setup configuration"
2020-03-22 15:42:29 +00:00
2020-03-29 08:26:24 +00:00
crudini --set "$app_ini" "" APP_NAME "${APP_NAME}"
crudini --set "$app_ini" "" RUN_MODE "${RUN_MODE}"
2020-03-22 16:53:12 +00:00
2020-03-28 15:36:13 +00:00
crudini --set "$app_ini" ui DEFAULT_THEME "${GITEA_THEME}"
2020-03-23 13:30:20 +00:00
crudini --set "$app_ini" ui.meta AUTHOR "${AUTHOR}"
crudini --set "$app_ini" ui.meta DESCRIPTION "${DESCRIPTION}"
2020-03-22 16:19:39 +00:00
crudini --del "$app_ini" database PATH
2020-03-22 15:42:29 +00:00
crudini --set "$app_ini" database DB_TYPE mysql
crudini --set "$app_ini" database HOST "${DB_HOST}"
crudini --set "$app_ini" database NAME "${DB_NAME}"
crudini --set "$app_ini" database USER "${DB_USER}"
crudini --set "$app_ini" database PASSWD "${DB_PASSWD}"
crudini --set "$app_ini" database SSL_MODE "disable"
2020-03-22 16:19:39 +00:00
2020-03-22 15:42:29 +00:00
crudini --set "$app_ini" server PROTOCOL "http"
crudini --set "$app_ini" server DOMAIN "${DOMAIN}"
crudini --set "$app_ini" server ROOT_URL "https://%(DOMAIN)s/"
2020-03-22 16:53:12 +00:00
crudini --set "$app_ini" server HTTP_ADDR ""
2020-03-25 10:41:44 +00:00
crudini --set "$app_ini" server HTTP_PORT "${HTTP_PORT}"
2020-03-23 14:19:29 +00:00
crudini --set "$app_ini" server SSH_DOMAIN "${SSH_DOMAIN}"
2020-03-23 15:28:11 +00:00
crudini --set "$app_ini" server SSH_PORT "${SSH_PORT}"
crudini --set "$app_ini" server SSH_LISTEN_PORT "${SSH_LISTEN_PORT}"
2020-03-22 16:53:12 +00:00
crudini --set "$app_ini" service DISABLE_REGISTRATION "${DISABLE_REGISTRATION}"
2020-03-23 14:01:06 +00:00
crudini --set "$app_ini" service ALLOW_ONLY_EXTERNAL_REGISTRATION "${ALLOW_ONLY_EXTERNAL_REGISTRATION}"
2020-05-04 09:50:07 +00:00
crudini --set "$app_ini" service ENABLE_NOTIFY_MAIL "${ENABLE_NOTIFY_MAIL}"
2020-03-22 16:53:12 +00:00
crudini --set "$app_ini" security INSTALL_LOCK "${INSTALL_LOCK}"
crudini --set "$app_ini" security SECRET_KEY "${SECRET_KEY}"
2020-03-22 15:42:29 +00:00
2020-03-22 16:53:12 +00:00
crudini --set "$app_ini" oauth2 JWT_SECRET "${JWT_SECRET}"
2020-03-23 12:09:41 +00:00
crudini --set "$app_ini" openid ENABLE_OPENID_SIGNIN "${ENABLE_OPENID_SIGNIN}"
crudini --set "$app_ini" openid ENABLE_OPENID_SIGNUP "${ENABLE_OPENID_SIGNUP}"
2020-03-23 13:30:20 +00:00
crudini --set "$app_ini" openid WHITELIST_URIS "${WHITELIST_URIS}"
2020-03-23 12:09:41 +00:00
2020-03-23 13:30:20 +00:00
crudini --set "$app_ini" indexer STARTUP_TIMEOUT "${STARTUP_TIMEOUT}"
2020-03-27 17:40:10 +00:00
crudini --set "$app_ini" mailer ENABLED "${MAILER_ENABLED}"
crudini --set "$app_ini" mailer FROM "${SMTP_FROM}"
crudini --set "$app_ini" mailer HOST "${SMTP_HOST}"
2020-03-27 17:42:41 +00:00
crudini --set "$app_ini" mailer USER "${SMTP_USER}"
crudini --set "$app_ini" mailer PASSWD "${SMTP_PASSWD}"
2020-03-27 18:35:50 +00:00
crudini --set "$app_ini" mailer MAILER_TYPE "${SMTP_MAILER_TYPE}"
2020-05-04 09:40:03 +00:00
crudini --set "$app_ini" mailer IS_TLS_ENABLED "${SMTP_TLS_ENABLED}"
crudini --set "$app_ini" markup.restructuredtext ENABLED "true"
crudini --set "$app_ini" markup.restructuredtext FILE_EXTENSIONS ".rst"
crudini --set "$app_ini" markup.restructuredtext RENDER_COMMAND rst2html
crudini --set "$app_ini" markup.restructuredtext IS_INPUT_FILE "false"
2020-03-22 15:42:29 +00:00
}
2020-03-29 08:22:30 +00:00
# Main entrypoint
2020-03-15 11:46:13 +00:00
main() {
set -eu
setup_root_user
2020-03-22 15:42:29 +00:00
setup_app_ini
2020-03-15 11:46:13 +00:00
}
main
2020-03-15 11:41:24 +00:00
/usr/bin/entrypoint "$@"