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

70 lines
1.6 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
return
fi
user_count=$(sqlite3 /data/gitea/gitea.db "select count(*) from user;")
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-15 11:46:13 +00:00
exit 1
fi
fi
}
2020-03-22 15:42:29 +00:00
setup_app_ini() {
set -eu
if [ ! -f "/data/gitea/conf/app.ini" ]; then
return
fi
declare app_ini="/data/gitea/conf/app.ini"
echo "-----> Setting up root user for initial deployment"
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" sserver HTTP_ADDR ""
crudini --set "$app_ini" sserver HTTP_PORT "3000"
}
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 "$@"