#!/bin/bash set -eu -o pipefail # Install root administration user account on first installation setup_root_user() { set -eu if [ ! -f "/data/gitea/conf/app.ini" ]; then echo "-----> Missing app.ini, not setting up root user" return fi 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;" \ ) if [[ "${user_count}" == "0" ]]; then echo "-----> Setting up root user for initial deployment" create_user=$(gitea \ admin \ create-user \ --username "$ADMIN_USER" \ --password "$ADMIN_PASS" \ --email "$ADMIN_MAIL" \ --admin \ ) if "$create_user"; then echo "-----> root user added" else echo "-----> Failed to add root user" return fi fi } # Pass Ansible based environment variables into the Gitea app.ini configuration setup_app_ini() { set -eu if [ ! -f "/data/gitea/conf/app.ini" ]; then echo "-----> Missing app.ini, not setting up configuration" return fi declare app_ini="/data/gitea/conf/app.ini" echo "-----> Using crudini to setup configuration" crudini --set "$app_ini" "" APP_NAME "${APP_NAME}" crudini --set "$app_ini" "" RUN_MODE "${RUN_MODE}" crudini --set "$app_ini" ui DEFAULT_THEME "${GITEA_THEME}" crudini --set "$app_ini" ui.meta AUTHOR "${AUTHOR}" crudini --set "$app_ini" ui.meta DESCRIPTION "${DESCRIPTION}" crudini --del "$app_ini" database PATH 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" crudini --set "$app_ini" server PROTOCOL "http" crudini --set "$app_ini" server DOMAIN "${DOMAIN}" crudini --set "$app_ini" server ROOT_URL "https://%(DOMAIN)s/" crudini --set "$app_ini" server HTTP_ADDR "" crudini --set "$app_ini" server HTTP_PORT "${HTTP_PORT}" crudini --set "$app_ini" server SSH_DOMAIN "${SSH_DOMAIN}" crudini --set "$app_ini" server SSH_PORT "${SSH_PORT}" crudini --set "$app_ini" server SSH_LISTEN_PORT "${SSH_LISTEN_PORT}" crudini --set "$app_ini" service DISABLE_REGISTRATION "${DISABLE_REGISTRATION}" crudini --set "$app_ini" service ALLOW_ONLY_EXTERNAL_REGISTRATION "${ALLOW_ONLY_EXTERNAL_REGISTRATION}" crudini --set "$app_ini" security INSTALL_LOCK "${INSTALL_LOCK}" crudini --set "$app_ini" security SECRET_KEY "${SECRET_KEY}" crudini --set "$app_ini" oauth2 JWT_SECRET "${JWT_SECRET}" crudini --set "$app_ini" openid ENABLE_OPENID_SIGNIN "${ENABLE_OPENID_SIGNIN}" crudini --set "$app_ini" openid ENABLE_OPENID_SIGNUP "${ENABLE_OPENID_SIGNUP}" crudini --set "$app_ini" openid WHITELIST_URIS "${WHITELIST_URIS}" crudini --set "$app_ini" indexer STARTUP_TIMEOUT "${STARTUP_TIMEOUT}" crudini --set "$app_ini" mailer ENABLED "${MAILER_ENABLED}" crudini --set "$app_ini" mailer FROM "${SMTP_FROM}" crudini --set "$app_ini" mailer HOST "${SMTP_HOST}" crudini --set "$app_ini" mailer USER "${SMTP_USER}" crudini --set "$app_ini" mailer PASSWD "${SMTP_PASSWD}" crudini --set "$app_ini" mailer MAILER_TYPE "${SMTP_MAILER_TYPE}" 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" } # Main entrypoint main() { set -eu setup_root_user setup_app_ini } main /usr/bin/entrypoint "$@"