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/postdeploy.sh

38 lines
722 B
Bash
Raw Normal View History

2020-03-12 14:01:36 +00:00
#!/bin/bash
set -eu -o pipefail
2020-03-12 15:35:13 +00:00
setup_db() {
set -eu
2020-03-12 17:14:42 +00:00
echo "=====> Running database migration"
2020-03-12 17:03:10 +00:00
gitea migrate
2020-03-12 15:35:13 +00:00
}
2020-03-12 14:01:36 +00:00
setup_root_user() {
set -eu
2020-03-12 15:40:17 +00:00
user_count=$(sqlite3 /data/gitea/gitea.db "select count(*) from user;")
2020-03-12 14:01:36 +00:00
if [[ "${user_count}" == "0" ]]; then
2020-03-12 17:14:42 +00:00
echo "=====> Setting up root user for first run"
2020-03-12 15:33:02 +00:00
if gitea admin create-user --username "$ADMIN_USER" --password "$ADMIN_PASS" --email "$ADMIN_MAIL" --admin; then
2020-03-12 17:14:42 +00:00
echo "=====> root user added"
2020-03-12 14:01:36 +00:00
else
2020-03-12 17:14:42 +00:00
echo "=====> Failed to add root user"
2020-03-12 14:01:36 +00:00
exit 1
fi
fi
}
main() {
set -eu
2020-03-12 17:03:10 +00:00
if [ -f "/data/gitea/conf/app.ini" ]; then
setup_db
setup_root_user
fi
2020-03-12 14:01:36 +00:00
}
2020-03-12 16:32:36 +00:00
main