52 lines
1022 B
Bash
Executable File
52 lines
1022 B
Bash
Executable File
#!/bin/bash
|
|
|
|
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 create-user --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
|
|
}
|
|
|
|
setup_letsencrypt_certs() {
|
|
set -eu
|
|
|
|
if [ ! -d "/home/dokku/gitea/letsencrypt" ]; then
|
|
echo "=====> Generating let's encrypt certificates"
|
|
dokku letsencrypt gitea
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
set -eu
|
|
|
|
setup_db
|
|
setup_root_user
|
|
setup_letsencrypt_certs
|
|
}
|
|
|
|
main
|