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
2020-03-23 16:28:11 +01:00

96 lines
3.0 KiB
Bash
Executable File

#!/bin/bash
set -eu -o pipefail
setup_db() {
set -eu
if [ -f "/data/gitea/conf/app.ini" ]; then
echo "-----> Running database migration"
gitea migrate
fi
}
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"
if gitea admin create-user --username "$ADMIN_USER" --password "$ADMIN_PASS" --email "$ADMIN_MAIL" --admin; then
echo "-----> root user added"
else
echo "-----> Failed to add root user"
return
fi
fi
}
setup_app_ini() {
set -eu
if [ ! -f "/data/gitea/conf/app.ini" ]; then
echo "-----> Missing app.ini, not setting up root user"
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.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 "3000"
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}"
}
main() {
set -eu
setup_db
setup_root_user
setup_app_ini
}
main
/usr/bin/entrypoint "$@"