diff --git a/Makefile b/Makefile index 8584274dec..fcfd998979 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/misc-tools/force-passwords.in b/misc-tools/force-passwords.in index af7bf80092..505d1cd337 100755 --- a/misc-tools/force-passwords.in +++ b/misc-tools/force-passwords.in @@ -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() @@ -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]) diff --git a/sql/dj_setup_database.in b/sql/dj_setup_database.in index 0bbfe80e20..8095fb706c 100755 --- a/sql/dj_setup_database.in +++ b/sql/dj_setup_database.in @@ -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! @@ -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 ### @@ -313,7 +308,8 @@ genpass) ;; uninstall) - uninstall_helper + read_dbpasswords + remove_db_users ;; install-examples) @@ -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 @@ -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 @@ -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 @@ -392,7 +385,7 @@ dump) esac done fi - create_database_dump "$DUMPNAME" + mysqldump $(mysql_options) --opt --skip-lock-tables "$DBNAME" | pv | gzip > "$DUMPFILE" ;; load) @@ -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" ;; diff --git a/webapp/Makefile b/webapp/Makefile index f4000332c9..5eac62ea13 100644 --- a/webapp/Makefile +++ b/webapp/Makefile @@ -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