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

96 lines
3.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
setup_db() {
set -eu
if [ -f "/data/gitea/conf/app.ini" ]; then
2020-03-22 15:42:29 +00:00
echo "-----> Running database migration"
2020-03-15 11:46:13 +00:00
gitea migrate
fi
}
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-22 16:36:19 +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-15 12:11:35 +00:00
if gitea admin create-user --username "$ADMIN_USER" --password "$ADMIN_PASS" --email "$ADMIN_MAIL" --admin; 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-22 15:42:29 +00:00
setup_app_ini() {
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-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-22 16:56:34 +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-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 ""
crudini --set "$app_ini" server HTTP_PORT "3000"
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-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-22 15:42:29 +00:00
}
2020-03-15 11:46:13 +00:00
main() {
set -eu
setup_db
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 "$@"