45 lines
951 B
Bash
Executable File
45 lines
951 B
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eu -o pipefail
|
|
|
|
setup_root_user() {
|
|
set -eu
|
|
|
|
# TODO(decentral1se): fix to use sqlite3 database for now
|
|
user_count=$(mysql -u"${DB_USER}" -p"${DB_PASS}" -h mysql --database="${DB_NAME}" -N -B -e "SELECT count(*) FROM user;")
|
|
|
|
if [[ "${user_count}" == "0" ]]; then
|
|
echo "==> Setting up root user for first run"
|
|
|
|
if gitea create-admin --name "$ADMIN_USER" --password "$ADMIN_PASS" --email "$ADMIN_MAIL"; then
|
|
echo "==> root user added"
|
|
else
|
|
echo "==> Failed to add root user"
|
|
exit 1
|
|
fi
|
|
fi
|
|
}
|
|
|
|
do_healthcheck() {
|
|
set -eu
|
|
|
|
echo "==> Running Gitea healthcheck"
|
|
|
|
while ! curl --fail "https://${DOMAIN}/healthcheck"; do
|
|
echo "==> Waiting for Gitea to come up"
|
|
sleep 1
|
|
done
|
|
|
|
echo "==> Gitea is up"
|
|
}
|
|
|
|
main() {
|
|
set -eu
|
|
|
|
do_healthcheck
|
|
setup_root_user
|
|
}
|
|
|
|
# TODO(decentral1se): test manually for now...
|
|
# main
|