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:19:39 +00:00
|
|
|
user_count=$(mysql -u"${DB_USER}" -p"${DB_PASSWD}" -h mysql --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: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/"
|
|
|
|
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 "$@"
|