From 487b59c994f7b692670b31ce40a7c62fad41d77f Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 15 Mar 2020 12:46:13 +0100 Subject: [PATCH] Put commands into entrypoint --- sbin/dokku-entrypoint.sh | 45 +++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/sbin/dokku-entrypoint.sh b/sbin/dokku-entrypoint.sh index b902670..d995f84 100755 --- a/sbin/dokku-entrypoint.sh +++ b/sbin/dokku-entrypoint.sh @@ -1,8 +1,43 @@ -#!/bin/sh +#!/bin/bash -if [ -f "/data/gitea/conf/app.ini" ]; then - echo "=====> Running database migration" - gitea migrate -fi +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 + return + fi + + user_count=$(sqlite3 /data/gitea/gitea.db "select count(*) from user;") + + if [[ "${user_count}" == "0" ]]; then + echo "=====> Setting up root user for initial deployment" + if gitea admin createuser username "$ADMIN_USER" password "$ADMIN_PASS" email "$ADMIN_MAIL" admin; then + echo "=====> root user added" + else + echo "=====> Failed to add root user" + exit 1 + fi + fi +} + +main() { + set -eu + + setup_db + setup_root_user +} + +main /usr/bin/entrypoint "$@"