Skip to content

SQL tool improvements #2859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ inplace-install-l:
ln -sf $(CURDIR)/judge/runpipe $(judgehost_bindir)
ln -sf $(CURDIR)/judge/create_cgroups $(judgehost_bindir)
ln -sf $(CURDIR)/sql/dj_setup_database $(domserver_bindir)
ln -sf $(CURDIR)/webapp/bin/console $(domserver_bindir)/dj_console
# Create tmpdir and make tmpdir writable for webserver,
# because judgehost-create-dirs sets wrong permissions:
$(MKDIR_P) $(domserver_tmpdir)
Expand Down
8 changes: 5 additions & 3 deletions misc-tools/force-passwords.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import subprocess

webappdir = '@domserver_webappdir@'
bindir = '@domserver_bindir@'
etcdir = '@domserver_etcdir@'

subprocess.run([bindir + '/dj_setup_database', 'update-password'])

with open(f'{etcdir}/restapi.secret', 'r') as f:
while True:
line = f.readline()
Expand All @@ -14,9 +16,9 @@ with open(f'{etcdir}/restapi.secret', 'r') as f:
if len(tokens) == 4 and tokens[0] == 'default':
user = tokens[2]
password = tokens[3]
subprocess.run([webappdir + '/bin/console', 'domjudge:reset-user-password', user, password])
subprocess.run([bindir + '/dj_console', 'domjudge:reset-user-password', user, password])
break

with open(f'{etcdir}/initial_admin_password.secret', 'r') as f:
password = f.readline().strip()
subprocess.run([webappdir + '/bin/console', 'domjudge:reset-user-password', 'admin', password])
subprocess.run([bindir + '/dj_console', 'domjudge:reset-user-password', 'admin', password])
57 changes: 25 additions & 32 deletions sql/dj_setup_database.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Commands:
status check database installation status
genpass generate DB,API,Symfony,admin password files
create-db-users create (empty) database and users
update-password update DB user database to that in 'etc/dbpasswords.secret'
install create database, example contest and users if not existing
bare-install create database, setup defaults if not existing
uninstall remove database users and database, INCLUDING ALL DATA!
Expand Down Expand Up @@ -233,28 +234,22 @@ remove_db_users()
verbose "DOMjudge database and user(s) removed."
}

install_examples()
{
DBUSER=$domjudge_DBUSER PASSWD=$domjudge_PASSWD symfony_console domjudge:load-example-data
"$EXAMPLEPROBDIR"/generate-contest-yaml
( cd "$EXAMPLEPROBDIR" && yes y | "$BINDIR"/import-contest )
}

uninstall_helper()
update_password()
{
read_dbpasswords
remove_db_users
(
echo "ALTER USER '$domjudge_DBUSER'@'localhost' IDENTIFIED BY '$domjudge_PASSWD';"
echo "FLUSH PRIVILEGES;"
) | mysql
verbose "ALTER USER '$domjudge_DBUSER'@'localhost' IDENTIFIED BY '$domjudge_PASSWD';"
verbose "Database user password updated from credentials file."
}

create_db_users_helper()
install_examples()
{
read_dbpasswords
create_db_users
verbose "Created empty database and users."
}

create_database_dump () {
mysqldump $(mysql_options) --opt --skip-lock-tables "$DBNAME" | pv | gzip > "$DATABASEDUMPDIR/${1}.sql.gz"
DBUSER=$domjudge_DBUSER PASSWD=$domjudge_PASSWD symfony_console domjudge:load-example-data
"$EXAMPLEPROBDIR"/generate-contest-yaml
( cd "$EXAMPLEPROBDIR" && yes y | "$BINDIR"/import-contest )
}

### Script starts here ###
Expand Down Expand Up @@ -313,7 +308,8 @@ genpass)
;;

uninstall)
uninstall_helper
read_dbpasswords
remove_db_users
;;

install-examples)
Expand All @@ -324,23 +320,24 @@ install-examples)
install-loadtest)
read_dbpasswords
create_db_users
export DB_FIRST_INSTALL=1
symfony_console doctrine:migrations:migrate -n
unset DB_FIRST_INSTALL
DBUSER=$domjudge_DBUSER PASSWD=$domjudge_PASSWD symfony_console domjudge:load-default-data
DBUSER=$domjudge_DBUSER PASSWD=$domjudge_PASSWD symfony_console domjudge:load-gatling-data
;;

create-db-users)
create_db_users_helper
read_dbpasswords
create_db_users
;;

update-password)
update_password
;;

bare-install|install)
read_dbpasswords
create_db_users
export DB_FIRST_INSTALL=1
symfony_console doctrine:migrations:migrate -n
unset DB_FIRST_INSTALL
DBUSER=$domjudge_DBUSER PASSWD=$domjudge_PASSWD symfony_console domjudge:load-default-data
if [ "$1" = "install" ]; then
install_examples
Expand All @@ -351,11 +348,6 @@ bare-install|install)
;;

upgrade)
# check for legacy dbpasswords.secret content
if grep -Eq ^team: $PASSWDFILE >/dev/null 2>&1 ; then
echo "Warning: please remove all non-jury users from $PASSWDFILE"
echo "You may also remove those users from MySQL."
fi
read_dbpasswords

# Check if we need to upgrade the Doctrine migrations table
Expand All @@ -382,7 +374,8 @@ dump)
exit 1
fi

if [ -f "${DATABASEDUMPDIR}/${DUMPNAME}.sql.gz" ]; then
DUMPFILE="${DATABASEDUMPDIR}/${DUMPNAME}.sql.gz"
if [ -f "$DUMPFILE" ]; then
while true; do
printf "Overwrite existing database dump (y/N)? "
read -r yn
Expand All @@ -392,7 +385,7 @@ dump)
esac
done
fi
create_database_dump "$DUMPNAME"
mysqldump $(mysql_options) --opt --skip-lock-tables "$DBNAME" | pv | gzip > "$DUMPFILE"
;;

load)
Expand Down Expand Up @@ -434,8 +427,8 @@ load)
fi

read_dbpasswords
uninstall_helper
create_db_users_helper
remove_db_users
create_db_users
pv "${FILE}" | gunzip | mysql "$DBNAME"
;;

Expand Down
2 changes: 2 additions & 0 deletions webapp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ install-domserver:
for d in bin config migrations public resources src templates tests vendor; do \
$(call install_tree,$(DESTDIR)$(domserver_webappdir),$$d) ; \
done
# Add Symlink to Symfony console that is in the standard path
ln -s $(domserver_webappdir)/bin/console $(DESTDIR)$(domserver_bindir)/dj_console
# Change webapp/public/doc symlink
ln -sf $(domjudge_docdir) $(DESTDIR)$(domserver_webappdir)/public/doc
$(INSTALL_DATA) -t $(DESTDIR)$(domserver_webappdir) phpunit.xml.dist .env
Expand Down
Loading